forked from qt-creator/qt-creator
CMakePM: Build the correct executable before running
When issuing on a CMake target the context menu action "Run" the build system would build the wrong target: * either "all" * or "Current executable" which might have been a different target This change set makes sure that when a project target is selected in the Project view, the build target will be restricted to this target. This way the correct executable will be built before running. Fixes: QTCREATORBUG-31386 Change-Id: Ibe6e50c4588ffca53ec2ac9555265023188f6e4e Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -1658,16 +1658,18 @@ void CMakeBuildConfiguration::buildTarget(const QString &buildTarget)
|
||||
return bs->id() == Constants::CMAKE_BUILD_STEP_ID;
|
||||
}));
|
||||
|
||||
QStringList originalBuildTargets;
|
||||
if (cmBs) {
|
||||
originalBuildTargets = cmBs->buildTargets();
|
||||
if (m_unrestrictedBuildTargets.isEmpty())
|
||||
m_unrestrictedBuildTargets = cmBs->buildTargets();
|
||||
cmBs->setBuildTargets({buildTarget});
|
||||
}
|
||||
|
||||
BuildManager::buildList(buildSteps());
|
||||
|
||||
if (cmBs)
|
||||
cmBs->setBuildTargets(originalBuildTargets);
|
||||
if (cmBs) {
|
||||
cmBs->setBuildTargets(m_unrestrictedBuildTargets);
|
||||
m_unrestrictedBuildTargets.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void CMakeBuildConfiguration::reBuildTarget(const QString &cleanTarget, const QString &buildTarget)
|
||||
@@ -1681,9 +1683,9 @@ void CMakeBuildConfiguration::reBuildTarget(const QString &cleanTarget, const QS
|
||||
return bs->id() == Constants::CMAKE_BUILD_STEP_ID;
|
||||
}));
|
||||
|
||||
QStringList originalBuildTargets;
|
||||
if (cmBs) {
|
||||
originalBuildTargets = cmBs->buildTargets();
|
||||
if (m_unrestrictedBuildTargets.isEmpty())
|
||||
m_unrestrictedBuildTargets = cmBs->buildTargets();
|
||||
cmBs->setBuildTargets({buildTarget});
|
||||
}
|
||||
QString originalCleanTarget;
|
||||
@@ -1694,8 +1696,10 @@ void CMakeBuildConfiguration::reBuildTarget(const QString &cleanTarget, const QS
|
||||
|
||||
BuildManager::buildLists({cleanSteps(), buildSteps()});
|
||||
|
||||
if (cmBs)
|
||||
cmBs->setBuildTargets(originalBuildTargets);
|
||||
if (cmBs) {
|
||||
cmBs->setBuildTargets(m_unrestrictedBuildTargets);
|
||||
m_unrestrictedBuildTargets.clear();
|
||||
}
|
||||
if (cmCs)
|
||||
cmCs->setBuildTargets({originalCleanTarget});
|
||||
}
|
||||
@@ -2113,6 +2117,11 @@ void CMakeBuildConfiguration::addToEnvironment(Utils::Environment &env) const
|
||||
}
|
||||
|
||||
void CMakeBuildConfiguration::restrictNextBuild(const ProjectExplorer::RunConfiguration *rc)
|
||||
{
|
||||
setRestrictedBuildTarget(rc ? rc->buildKey() : QString());
|
||||
}
|
||||
|
||||
void CMakeBuildConfiguration::setRestrictedBuildTarget(const QString &buildTarget)
|
||||
{
|
||||
auto buildStep = qobject_cast<CMakeBuildStep *>(
|
||||
findOrDefault(buildSteps()->steps(), [](const BuildStep *bs) {
|
||||
@@ -2121,14 +2130,17 @@ void CMakeBuildConfiguration::restrictNextBuild(const ProjectExplorer::RunConfig
|
||||
if (!buildStep)
|
||||
return;
|
||||
|
||||
if (rc) {
|
||||
m_unrestrictedBuildTargets = buildStep->buildTargets();
|
||||
buildStep->setBuildTargets({rc->buildKey()});
|
||||
if (!buildTarget.isEmpty()) {
|
||||
if (m_unrestrictedBuildTargets.isEmpty())
|
||||
m_unrestrictedBuildTargets = buildStep->buildTargets();
|
||||
buildStep->setBuildTargets({buildTarget});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_unrestrictedBuildTargets.isEmpty())
|
||||
if (!m_unrestrictedBuildTargets.isEmpty()) {
|
||||
buildStep->setBuildTargets(m_unrestrictedBuildTargets);
|
||||
m_unrestrictedBuildTargets.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Environment CMakeBuildConfiguration::configureEnvironment() const
|
||||
|
@@ -72,6 +72,7 @@ public:
|
||||
void addToEnvironment(Utils::Environment &env) const override;
|
||||
|
||||
void restrictNextBuild(const ProjectExplorer::RunConfiguration *rc) override;
|
||||
void setRestrictedBuildTarget(const QString &buildTarget);
|
||||
|
||||
Utils::Environment configureEnvironment() const;
|
||||
Internal::CMakeBuildSystem *cmakeBuildSystem() const;
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include "cmakeprojectmanager.h"
|
||||
|
||||
#include "cmakebuildsystem.h"
|
||||
#include "cmakebuildconfiguration.h"
|
||||
#include "cmakekitaspect.h"
|
||||
#include "cmakeprocess.h"
|
||||
#include "cmakeproject.h"
|
||||
@@ -62,7 +63,8 @@ public:
|
||||
static void openCMakeUrl(const QUrl &url);
|
||||
|
||||
private:
|
||||
void updateCmakeActions(Node *node);
|
||||
void updateCMakeActions(Node *node);
|
||||
void updateCMakeBuildTarget(Node *node);
|
||||
void clearCMakeCache(BuildSystem *buildSystem);
|
||||
void runCMake(BuildSystem *buildSystem);
|
||||
void runCMakeWithProfiling(BuildSystem *buildSystem);
|
||||
@@ -290,22 +292,24 @@ CMakeManager::CMakeManager()
|
||||
CMakeTool::Version version = tool ? tool->version() : CMakeTool::Version();
|
||||
m_canDebugCMake = (version.major == 3 && version.minor >= 27) || version.major > 3;
|
||||
}
|
||||
updateCmakeActions(ProjectTree::currentNode());
|
||||
updateCMakeActions(ProjectTree::currentNode());
|
||||
});
|
||||
connect(BuildManager::instance(), &BuildManager::buildStateChanged, this, [this] {
|
||||
updateCmakeActions(ProjectTree::currentNode());
|
||||
updateCMakeActions(ProjectTree::currentNode());
|
||||
});
|
||||
connect(EditorManager::instance(), &EditorManager::currentEditorChanged, this, [this]() {
|
||||
updateBuildFileAction();
|
||||
enableBuildSubprojectMenu();
|
||||
});
|
||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
|
||||
this, &CMakeManager::updateCmakeActions);
|
||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged, this, [this](Node *node) {
|
||||
updateCMakeActions(node);
|
||||
updateCMakeBuildTarget(node);
|
||||
});
|
||||
|
||||
updateCmakeActions(ProjectTree::currentNode());
|
||||
updateCMakeActions(ProjectTree::currentNode());
|
||||
}
|
||||
|
||||
void CMakeManager::updateCmakeActions(Node *node)
|
||||
void CMakeManager::updateCMakeActions(Node *node)
|
||||
{
|
||||
auto project = qobject_cast<CMakeProject *>(ProjectManager::startupProject());
|
||||
const bool visible = project && !BuildManager::isBuilding(project);
|
||||
@@ -332,6 +336,21 @@ void CMakeManager::updateCmakeActions(Node *node)
|
||||
enableBuildSubprojectContextMenu(node);
|
||||
}
|
||||
|
||||
void CMakeManager::updateCMakeBuildTarget(Node *node)
|
||||
{
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
auto bs = qobject_cast<CMakeBuildSystem *>(ProjectTree::currentBuildSystem());
|
||||
if (!bs)
|
||||
return;
|
||||
|
||||
auto targetNode = dynamic_cast<const CMakeTargetNode *>(node);
|
||||
|
||||
bs->cmakeBuildConfiguration()->setRestrictedBuildTarget(
|
||||
targetNode ? targetNode->buildKey() : QString());
|
||||
}
|
||||
|
||||
void CMakeManager::clearCMakeCache(BuildSystem *buildSystem)
|
||||
{
|
||||
auto cmakeBuildSystem = dynamic_cast<CMakeBuildSystem *>(buildSystem);
|
||||
|
Reference in New Issue
Block a user