From 100cd10d6ececb014a0541f45b1a580bcf557e10 Mon Sep 17 00:00:00 2001 From: Claus Steuer Date: Sun, 17 Sep 2017 20:01:41 +0200 Subject: [PATCH] CMake: Set CMakeRunConfiguration executable and working directory Since 131c7a1 the executable and base working directory property of CMakeRunConfiguration objects is no longer set when the project data is updated. At least the executable is required in the AutoTest plugin. Change-Id: I31c4cb37983d3983664d178c0f8c08d491f719ad Reviewed-by: Tobias Hunger --- .../cmakeprojectmanager/cmakeproject.cpp | 30 ++++++++++++++++++- .../cmakeprojectmanager/cmakeproject.h | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index 211f564cc83..57de95ad1fa 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -152,7 +152,7 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc) } updateApplicationAndDeploymentTargets(); - t->updateDefaultRunConfigurations(); + updateTargetRunConfigurations(t); createGeneratedCodeModelSupport(); @@ -448,6 +448,34 @@ QStringList CMakeProject::filesGeneratedFrom(const QString &sourceFile) const } } +void CMakeProject::updateTargetRunConfigurations(Target *t) +{ + // *Update* existing runconfigurations (no need to update new ones!): + QHash buildTargetHash; + const QList buildTargetList = buildTargets(); + foreach (const CMakeBuildTarget &bt, buildTargetList) { + if (bt.targetType != ExecutableType || bt.executable.isEmpty()) + continue; + + buildTargetHash.insert(bt.title, &bt); + } + + foreach (RunConfiguration *rc, t->runConfigurations()) { + auto cmakeRc = qobject_cast(rc); + if (!cmakeRc) + continue; + + auto btIt = buildTargetHash.constFind(cmakeRc->title()); + if (btIt != buildTargetHash.constEnd()) { + cmakeRc->setExecutable(btIt.value()->executable.toString()); + cmakeRc->setBaseWorkingDirectory(btIt.value()->workingDirectory); + } + } + + // create new and remove obsolete RCs using the factories + t->updateDefaultRunConfigurations(); +} + void CMakeProject::updateApplicationAndDeploymentTargets() { Target *t = activeTarget(); diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h index 8083cf9dec1..1d3e047683f 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.h +++ b/src/plugins/cmakeprojectmanager/cmakeproject.h @@ -123,6 +123,7 @@ private: void createGeneratedCodeModelSupport(); QStringList filesGeneratedFrom(const QString &sourceFile) const final; + void updateTargetRunConfigurations(ProjectExplorer::Target *t); void updateApplicationAndDeploymentTargets(); ProjectExplorer::Target *m_connectedTarget = nullptr;