From 328a24edee3008a8d6bbbc7f57ac064bcd806d37 Mon Sep 17 00:00:00 2001
From: Oleksii Serdiuk <contacts@oleksii.name>
Date: Sun, 7 Jul 2013 23:49:13 +0200
Subject: [PATCH] CMake: Make CMake plugin work with RemoteLinux plugin.

Modified CMake plugin to work correctly with RemoteLinux plugin.
Because of not being able to extract files to be installed from CMake
project, only executable targets are automatically added to deployment
files. All other files have to be specified in CMakeDeployment.txt file
which should be placed into root of CMake project. The file format is:
> deployment/prefix
> relative/source/file1:relative/destination/dir1
> ...
> relative/source/filen:relative/destination/dirn

Where:
- deployment/prefix is (absolute) path prefix to which files will be
  deployed on the remote machine.
- relative/source/file is file path relative to CMake project root.
  Plain files - no directories or wildcards supported.
- relative/destination/dir is destination directory path relative to
  deployment/prefix.

Change-Id: I0831636c1b9aac3ff16bb6293104c512d2abfb5a
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
---
 .../cmakeopenprojectwizard.cpp                |  4 +-
 .../cmakeprojectmanager/cmakeproject.cpp      | 63 +++++++++++++++----
 .../cmakeprojectmanager/cmakeproject.h        |  1 +
 3 files changed, 54 insertions(+), 14 deletions(-)

diff --git a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp
index bbc937d2266..790ba14cb4c 100644
--- a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp
@@ -42,6 +42,7 @@
 #include <projectexplorer/abi.h>
 #include <projectexplorer/projectexplorerconstants.h>
 #include <texteditor/fontsettings.h>
+#include <remotelinux/remotelinux_constants.h>
 
 #include <QVBoxLayout>
 #include <QFormLayout>
@@ -179,7 +180,8 @@ QList<GeneratorInfo> GeneratorInfo::generatorInfosFor(ProjectExplorer::Kit *k, N
     if (!tc)
         return results;
     Core::Id deviceType = ProjectExplorer::DeviceTypeKitInformation::deviceTypeId(k);
-    if (deviceType !=  ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE)
+    if (deviceType !=  ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE
+            && deviceType != RemoteLinux::Constants::GenericLinuxOsType)
         return results;
     ProjectExplorer::Abi targetAbi = tc->targetAbi();
     if (n != ForceNinja) {
diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp
index a3801d3e20f..ea5cf7b9ff9 100644
--- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp
@@ -41,11 +41,13 @@
 #include <projectexplorer/headerpath.h>
 #include <projectexplorer/buildsteplist.h>
 #include <projectexplorer/buildmanager.h>
+#include <projectexplorer/buildtargetinfo.h>
 #include <projectexplorer/kitinformation.h>
 #include <projectexplorer/kitmanager.h>
 #include <projectexplorer/toolchain.h>
 #include <projectexplorer/target.h>
 #include <projectexplorer/deployconfiguration.h>
+#include <projectexplorer/deploymentdata.h>
 #include <projectexplorer/projectmacroexpander.h>
 #include <qtsupport/customexecutablerunconfiguration.h>
 #include <qtsupport/baseqtversion.h>
@@ -261,6 +263,7 @@ bool CMakeProject::parseCMakeLists()
 //            qDebug()<<"";
 //        }
 
+    updateApplicationAndDeploymentTargets();
 
     createUiCodeModelSupport();
 
@@ -562,9 +565,7 @@ bool CMakeProject::fromMap(const QVariantMap &map)
 
         t->addBuildConfiguration(bc);
 
-        DeployConfigurationFactory *fac = ExtensionSystem::PluginManager::getObject<DeployConfigurationFactory>();
-        ProjectExplorer::DeployConfiguration *dc = fac->create(t, ProjectExplorer::Constants::DEFAULT_DEPLOYCONFIGURATION_ID);
-        t->addDeployConfiguration(dc);
+        t->updateDefaultDeployConfigurations();
 
         addTarget(t);
     } else {
@@ -608,17 +609,9 @@ bool CMakeProject::fromMap(const QVariantMap &map)
 
 bool CMakeProject::setupTarget(Target *t)
 {
-    CMakeBuildConfigurationFactory *factory
-            = ExtensionSystem::PluginManager::getObject<CMakeBuildConfigurationFactory>();
-    CMakeBuildConfiguration *bc = factory->create(t, Constants::CMAKE_BC_ID, QLatin1String("all"));
-    if (!bc)
-        return false;
-
-    t->addBuildConfiguration(bc);
+    t->updateDefaultBuildConfigurations();
+    t->updateDefaultDeployConfigurations();
 
-    DeployConfigurationFactory *fac = ExtensionSystem::PluginManager::getObject<DeployConfigurationFactory>();
-    ProjectExplorer::DeployConfiguration *dc = fac->create(t, ProjectExplorer::Constants::DEFAULT_DEPLOYCONFIGURATION_ID);
-    t->addDeployConfiguration(dc);
     return true;
 }
 
@@ -720,6 +713,50 @@ void CMakeProject::updateRunConfigurations(Target *t)
     }
 }
 
+void CMakeProject::updateApplicationAndDeploymentTargets()
+{
+    Target *t = activeTarget();
+
+    QFile deploymentFile;
+    QTextStream deploymentStream;
+    QString deploymentPrefix;
+    QDir sourceDir;
+
+    sourceDir.setPath(t->project()->projectDirectory());
+    deploymentFile.setFileName(sourceDir.filePath(QLatin1String("QtCreatorDeployment.txt")));
+    if (deploymentFile.open(QFile::ReadOnly | QFile::Text)) {
+        deploymentStream.setDevice(&deploymentFile);
+        deploymentPrefix = deploymentStream.readLine();
+        if (!deploymentPrefix.endsWith(QLatin1Char('/')))
+            deploymentPrefix.append(QLatin1Char('/'));
+    }
+
+    BuildTargetInfoList appTargetList;
+    DeploymentData deploymentData;
+    QDir buildDir(t->activeBuildConfiguration()->buildDirectory().toString());
+    foreach (const CMakeBuildTarget &ct, m_buildTargets) {
+        if (ct.executable.isEmpty())
+            continue;
+
+        deploymentData.addFile(ct.executable, deploymentPrefix + buildDir.relativeFilePath(QFileInfo(ct.executable).dir().path()), DeployableFile::TypeExecutable);
+        if (!ct.library) {
+            // TODO: Put a path to corresponding .cbp file into projectFilePath?
+            appTargetList.list << BuildTargetInfo(ct.executable, ct.executable);
+        }
+    }
+
+    QString absoluteSourcePath = sourceDir.absolutePath();
+    if (!absoluteSourcePath.endsWith(QLatin1Char('/')))
+        absoluteSourcePath.append(QLatin1Char('/'));
+    while (!deploymentStream.atEnd()) {
+        QStringList file = deploymentStream.readLine().split(QLatin1Char(':'));
+        deploymentData.addFile(absoluteSourcePath + file.at(0), deploymentPrefix + file.at(1));
+    }
+
+    t->setApplicationTargets(appTargetList);
+    t->setDeploymentData(deploymentData);
+}
+
 void CMakeProject::createUiCodeModelSupport()
 {
     QHash<QString, QString> uiFileHash;
diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h
index 804eecc7564..c7946d95020 100644
--- a/src/plugins/cmakeprojectmanager/cmakeproject.h
+++ b/src/plugins/cmakeprojectmanager/cmakeproject.h
@@ -125,6 +125,7 @@ private:
     void createUiCodeModelSupport();
     QString uiHeaderFile(const QString &uiFile);
     void updateRunConfigurations(ProjectExplorer::Target *t);
+    void updateApplicationAndDeploymentTargets();
 
     CMakeManager *m_manager;
     ProjectExplorer::Target *m_activeTarget;
-- 
GitLab