ProjectExplorer: Move makeInstallCommand()

... from Project to BuildSystem.

More direct and less use of Target::activeBuildConfiguration().

Change-Id: I148381d23be0f9ab0750ed1440e1b2b3e25aded0
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2022-06-10 16:41:27 +02:00
parent 9a411245d3
commit f974488128
15 changed files with 70 additions and 82 deletions

View File

@@ -36,26 +36,31 @@
#include "cmakeprojectplugin.h"
#include "cmakespecificsettings.h"
#include "projecttreehelper.h"
#include "utils/algorithm.h"
#include <android/androidconstants.h>
#include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <cppeditor/cppeditorconstants.h>
#include <cppeditor/cppprojectupdater.h>
#include <cppeditor/generatedcodemodelsupport.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <projectexplorer/taskhub.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <qtsupport/qtcppkitinfo.h>
#include <qtsupport/qtkitinformation.h>
#include <app/app_version.h>
#include <utils/algorithm.h>
#include <utils/checkablemessagebox.h>
#include <utils/fileutils.h>
#include <utils/macroexpander.h>
@@ -1314,5 +1319,31 @@ void CMakeBuildSystem::updateInitialCMakeExpandableVars()
emit configurationChanged(config);
}
MakeInstallCommand CMakeBuildSystem::makeInstallCommand(const FilePath &installRoot) const
{
MakeInstallCommand cmd;
if (CMakeTool *tool = CMakeKitAspect::cmakeTool(target()->kit()))
cmd.command.setExecutable(tool->cmakeExecutable());
QString installTarget = "install";
if (usesAllCapsTargets())
installTarget = "INSTALL";
FilePath buildDirectory = ".";
if (auto bc = buildConfiguration())
buildDirectory = bc->buildDirectory();
cmd.command.addArg("--build");
cmd.command.addArg(buildDirectory.onDevice(cmd.command.executable()).path());
cmd.command.addArg("--target");
cmd.command.addArg(installTarget);
if (isMultiConfigReader())
cmd.command.addArgs({"--config", cmakeBuildType()});
cmd.environment.set("DESTDIR", installRoot.nativePath());
return cmd;
}
} // namespace Internal
} // namespace CMakeProjectManager

View File

@@ -98,6 +98,9 @@ public:
Utils::CommandLine commandLineForTests(const QList<QString> &tests,
const QStringList &options) const final;
ProjectExplorer::MakeInstallCommand makeInstallCommand(
const Utils::FilePath &installRoot) const final;
static bool filteredOutTarget(const CMakeBuildTarget &target);
bool isMultiConfig() const;

View File

@@ -116,40 +116,4 @@ ProjectExplorer::DeploymentKnowledge CMakeProject::deploymentKnowledge() const
: DeploymentKnowledge::Bad;
}
MakeInstallCommand CMakeProject::makeInstallCommand(const Target *target,
const FilePath &installRoot)
{
MakeInstallCommand cmd;
if (const BuildConfiguration * const bc = target->activeBuildConfiguration()) {
if (const auto cmakeStep = bc->buildSteps()->firstOfType<CMakeBuildStep>()) {
if (CMakeTool *tool = CMakeKitAspect::cmakeTool(target->kit()))
cmd.command.setExecutable(tool->cmakeExecutable());
}
}
QString installTarget = "install";
QStringList config;
auto bs = qobject_cast<CMakeBuildSystem*>(target->buildSystem());
QTC_ASSERT(bs, return {});
if (bs->usesAllCapsTargets())
installTarget = "INSTALL";
if (bs->isMultiConfigReader())
config << "--config" << bs->cmakeBuildType();
FilePath buildDirectory = ".";
if (auto bc = bs->buildConfiguration())
buildDirectory = bc->buildDirectory();
cmd.command.addArg("--build");
cmd.command.addArg(buildDirectory.onDevice(cmd.command.executable()).path());
cmd.command.addArg("--target");
cmd.command.addArg(installTarget);
cmd.command.addArgs(config);
cmd.environment.set("DESTDIR", installRoot.nativePath());
return cmd;
}
} // namespace CMakeProjectManager

View File

@@ -54,8 +54,6 @@ protected:
private:
ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const override;
ProjectExplorer::MakeInstallCommand makeInstallCommand(const ProjectExplorer::Target *target,
const Utils::FilePath &installRoot) final;
mutable Internal::CMakeProjectImporter *m_projectImporter = nullptr;