From c70c7ac29cecfa0d1928b2eae2de3e0e6e8d37f8 Mon Sep 17 00:00:00 2001
From: dt <qtc-commiter@nokia.com>
Date: Fri, 12 Dec 2008 17:22:02 +0100
Subject: [PATCH] Fixes:    Create a cbp file if we didn't find one, create All
 target

Task:     -
RevBy:    -
AutoTest: -
Details:  For now create only one build configuration "AllTargets",
build only the "all" target. Create runconfigurations for all targets
with option type=4
---
 .../cmakeprojectmanager/cmakeproject.cpp      | 38 +++++++++++++------
 .../cmakeprojectmanager/cmakeproject.h        |  2 +-
 src/plugins/cmakeprojectmanager/makestep.cpp  |  2 +-
 3 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp
index 423fa2dcb3f..6e1e8fd1f41 100644
--- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp
@@ -50,6 +50,17 @@
 using namespace CMakeProjectManager;
 using namespace CMakeProjectManager::Internal;
 
+
+// QtCreator CMake Generator wishlist:
+// Which make targets we need to build to get all executables
+// What is the make we need to call
+// What is the actual compiler executable
+// DEFINES
+
+// Open Questions
+// Who sets up the environment for cl.exe ? INCLUDEPATH and so on
+
+
 CMakeProject::CMakeProject(CMakeManager *manager, const QString &fileName)
     : m_manager(manager), m_fileName(fileName), m_rootNode(new CMakeProjectNode(m_fileName))
 {
@@ -57,8 +68,10 @@ CMakeProject::CMakeProject(CMakeManager *manager, const QString &fileName)
     m_file = new CMakeFile(this, fileName);
     QDir dir = QFileInfo(m_fileName).absoluteDir();
     QString cbpFile = findCbpFile(dir);
-    if (cbpFile.isEmpty())
-        cbpFile = createCbpFile(dir);
+    if (cbpFile.isEmpty()) {
+        createCbpFile(dir);
+        cbpFile = findCbpFile(dir);
+    }
 
     //TODO move this parsing to a seperate method, which is also called if the CMakeList.txt is updated
     CMakeCbpParser cbpparser;
@@ -111,7 +124,7 @@ QString CMakeProject::findCbpFile(const QDir &directory)
     return QString::null;
 }
 
-QString CMakeProject::createCbpFile(const QDir &directory)
+void CMakeProject::createCbpFile(const QDir &directory)
 {
     // We create a cbp file, only if we didn't find a cbp file in the base directory
     // Yet that can still override cbp files in subdirectories
@@ -124,8 +137,7 @@ QString CMakeProject::createCbpFile(const QDir &directory)
     QProcess cmake;
     cmake.setWorkingDirectory(directory.absolutePath());
     cmake.start("cmake", QStringList() << "-GCodeBlocks - Unix Makefiles");
-
-    return QString::null;
+    cmake.waitForFinished();
 }
 
 void CMakeProject::buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list)
@@ -261,17 +273,21 @@ void CMakeProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader
         insertBuildStep(0, cmakeStep);
         insertBuildStep(1, makeStep);
 
+        addBuildConfiguration("AllTargets");
+        setActiveBuildConfiguration("AllTargets");
+        makeStep->setValue("AllTargets", "buildTargets", QStringList() << "all");
+
         // Create build configurations of m_targets
         qDebug()<<"Create build configurations of m_targets";
+        bool setActive = false;
         foreach(const CMakeTarget &ct, m_targets) {
-            addBuildConfiguration(ct.title);
-            makeStep->setValue(ct.title, "makeCommand", ct.makeCommand);
-            makeStep->setValue(ct.title, "makeCleanCommand", ct.makeCleanCommand);
-
             QSharedPointer<ProjectExplorer::RunConfiguration> rc(new CMakeRunConfiguration(this, ct.executable, ct.workingDirectory));
-            // TODO set build configuration to build before it can be run
             addRunConfiguration(rc);
-            setActiveRunConfiguration(rc); // TODO what exactly shall be the active run configuration?
+            // The first one gets the honour of beeing the active one
+            if (!setActive) {
+                setActiveRunConfiguration(rc);
+                setActive = true;
+            }
         }
         setActiveBuildConfiguration("all");
 
diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h
index 2a0314fda1a..48f5057d102 100644
--- a/src/plugins/cmakeprojectmanager/cmakeproject.h
+++ b/src/plugins/cmakeprojectmanager/cmakeproject.h
@@ -102,7 +102,7 @@ public:
 
 private:
     QString findCbpFile(const QDir &);
-    QString createCbpFile(const QDir &);
+    void createCbpFile(const QDir &);
 
     void buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list);
     ProjectExplorer::FolderNode *findOrCreateFolder(CMakeProjectNode *rootNode, QString directory);
diff --git a/src/plugins/cmakeprojectmanager/makestep.cpp b/src/plugins/cmakeprojectmanager/makestep.cpp
index 3cdc0726e8c..71d1a5d93a3 100644
--- a/src/plugins/cmakeprojectmanager/makestep.cpp
+++ b/src/plugins/cmakeprojectmanager/makestep.cpp
@@ -54,7 +54,7 @@ bool MakeStep::init(const QString &buildConfiguration)
     setEnabled(buildConfiguration, true);
     setWorkingDirectory(buildConfiguration, m_pro->buildDirectory(buildConfiguration));
     setCommand(buildConfiguration, "make"); // TODO give full path here?
-    setArguments(buildConfiguration, QStringList()); // TODO
+    setArguments(buildConfiguration, value(buildConfiguration, "buildTargets").toStringList()); // TODO
     setEnvironment(buildConfiguration, m_pro->environment(buildConfiguration));
     return AbstractProcessStep::init(buildConfiguration);
 }
-- 
GitLab