diff --git a/src/plugins/cmakeprojectmanager/builddirmanager.cpp b/src/plugins/cmakeprojectmanager/builddirmanager.cpp index 27ac6a4504e..d3468a95409 100644 --- a/src/plugins/cmakeprojectmanager/builddirmanager.cpp +++ b/src/plugins/cmakeprojectmanager/builddirmanager.cpp @@ -64,7 +64,7 @@ BuildDirManager::~BuildDirManager() = default; Utils::FileName BuildDirManager::workDirectory(const BuildDirParameters ¶meters) const { const Utils::FileName bdir = parameters.buildDirectory; - const CMakeTool *cmake = parameters.cmakeTool; + const CMakeTool *cmake = parameters.cmakeTool(); if (bdir.exists()) { m_buildDirToTempDir.erase(bdir); return bdir; @@ -141,7 +141,7 @@ bool BuildDirManager::hasConfigChanged() const CMakeConfig currentConfig = takeCMakeConfiguration(); - const CMakeTool *tool = m_parameters.cmakeTool; + const CMakeTool *tool = m_parameters.cmakeTool(); QTC_ASSERT(tool, return false); // No cmake... we should not have ended up here in the first place const QString extraKitGenerator = m_parameters.extraGenerator; const QString mainKitGenerator = m_parameters.generator; @@ -196,7 +196,7 @@ void BuildDirManager::setParametersAndRequestParse(const BuildDirParameters &par int newReaderReparseOptions, int existingReaderReparseOptions) { - if (!parameters.cmakeTool) { + if (!parameters.cmakeTool()) { TaskHub::addTask(Task::Error, tr("The kit needs to define a CMake tool to parse this project."), ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM); @@ -240,7 +240,7 @@ void BuildDirManager::becameDirty() if (!m_parameters.buildConfiguration || !m_parameters.buildConfiguration->isActive()) return; - const CMakeTool *tool = m_parameters.cmakeTool; + const CMakeTool *tool = m_parameters.cmakeTool(); if (!tool->isAutoRun()) return; diff --git a/src/plugins/cmakeprojectmanager/builddirparameters.cpp b/src/plugins/cmakeprojectmanager/builddirparameters.cpp index 4af170b4907..481695f7e9a 100644 --- a/src/plugins/cmakeprojectmanager/builddirparameters.cpp +++ b/src/plugins/cmakeprojectmanager/builddirparameters.cpp @@ -27,6 +27,7 @@ #include "cmakebuildconfiguration.h" #include "cmakekitinformation.h" +#include "cmaketoolmanager.h" #include #include @@ -53,7 +54,7 @@ BuildDirParameters::BuildDirParameters(CMakeBuildConfiguration *bc) environment = bc->environment(); - cmakeTool = CMakeKitInformation::cmakeTool(k); + cmakeToolId = CMakeKitInformation::cmakeToolId(k); auto tc = ToolChainKitInformation::toolChain(k, Constants::CXX_LANGUAGE_ID); if (tc) @@ -74,7 +75,12 @@ BuildDirParameters::BuildDirParameters(CMakeBuildConfiguration *bc) generatorArguments = CMakeGeneratorKitInformation::generatorArguments(k); } -bool BuildDirParameters::isValid() const { return buildConfiguration && cmakeTool; } +bool BuildDirParameters::isValid() const { return buildConfiguration && cmakeTool(); } + +CMakeTool *BuildDirParameters::cmakeTool() const +{ + return CMakeToolManager::findById(cmakeToolId); +} BuildDirParameters::BuildDirParameters(const BuildDirParameters &) = default; diff --git a/src/plugins/cmakeprojectmanager/builddirparameters.h b/src/plugins/cmakeprojectmanager/builddirparameters.h index 1c26b45ffea..92f5f16eeea 100644 --- a/src/plugins/cmakeprojectmanager/builddirparameters.h +++ b/src/plugins/cmakeprojectmanager/builddirparameters.h @@ -46,6 +46,7 @@ public: BuildDirParameters(const BuildDirParameters &other); bool isValid() const; + CMakeTool *cmakeTool() const; CMakeBuildConfiguration *buildConfiguration = nullptr; QString projectName; @@ -54,7 +55,7 @@ public: Utils::FileName buildDirectory; Utils::FileName workDirectory; // either buildDirectory or a QTemporaryDirectory! Utils::Environment environment; - CMakeTool *cmakeTool = nullptr; + Core::Id cmakeToolId; QByteArray cxxToolChainId; QByteArray cToolChainId; diff --git a/src/plugins/cmakeprojectmanager/builddirreader.cpp b/src/plugins/cmakeprojectmanager/builddirreader.cpp index 1d15eb7f7f4..3cf74ad6f42 100644 --- a/src/plugins/cmakeprojectmanager/builddirreader.cpp +++ b/src/plugins/cmakeprojectmanager/builddirreader.cpp @@ -41,8 +41,9 @@ namespace Internal { BuildDirReader *BuildDirReader::createReader(const BuildDirParameters &p) { - QTC_ASSERT(p.isValid() && p.cmakeTool, return nullptr); - if (p.cmakeTool->hasServerMode()) + CMakeTool *cmake = p.cmakeTool(); + QTC_ASSERT(p.isValid() && cmake, return nullptr); + if (cmake->hasServerMode()) return new ServerModeReader; return new TeaLeafReader; } diff --git a/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp b/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp index 7a8d22ac284..fef5a45f589 100644 --- a/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp +++ b/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp @@ -83,13 +83,16 @@ Core::Id CMakeKitInformation::id() return TOOL_ID; } -CMakeTool *CMakeKitInformation::cmakeTool(const Kit *k) +Core::Id CMakeKitInformation::cmakeToolId(const Kit *k) { if (!k) - return nullptr; + return {}; + return Core::Id::fromSetting(k->value(TOOL_ID)); +} - const QVariant id = k->value(TOOL_ID); - return CMakeToolManager::findById(Core::Id::fromSetting(id)); +CMakeTool *CMakeKitInformation::cmakeTool(const Kit *k) +{ + return CMakeToolManager::findById(cmakeToolId(k)); } void CMakeKitInformation::setCMakeTool(Kit *k, const Core::Id id) diff --git a/src/plugins/cmakeprojectmanager/cmakekitinformation.h b/src/plugins/cmakeprojectmanager/cmakekitinformation.h index 87f9de0b67e..3da3f7d7b22 100644 --- a/src/plugins/cmakeprojectmanager/cmakekitinformation.h +++ b/src/plugins/cmakeprojectmanager/cmakekitinformation.h @@ -43,6 +43,7 @@ public: static Core::Id id(); + static Core::Id cmakeToolId(const ProjectExplorer::Kit *k); static CMakeTool *cmakeTool(const ProjectExplorer::Kit *k); static void setCMakeTool(ProjectExplorer::Kit *k, const Core::Id id); diff --git a/src/plugins/cmakeprojectmanager/servermodereader.cpp b/src/plugins/cmakeprojectmanager/servermodereader.cpp index 097840072f2..459168c1883 100644 --- a/src/plugins/cmakeprojectmanager/servermodereader.cpp +++ b/src/plugins/cmakeprojectmanager/servermodereader.cpp @@ -98,13 +98,14 @@ ServerModeReader::~ServerModeReader() void ServerModeReader::setParameters(const BuildDirParameters &p) { - QTC_ASSERT(p.cmakeTool, return); + CMakeTool *cmake = p.cmakeTool(); + QTC_ASSERT(cmake, return); BuildDirReader::setParameters(p); if (!m_cmakeServer) { m_cmakeServer.reset(new ServerMode(p.environment, p.sourceDirectory, p.workDirectory, - p.cmakeTool->cmakeExecutable(), + cmake->cmakeExecutable(), p.generator, p.extraGenerator, p.platform, p.toolset, true, 1)); connect(m_cmakeServer.get(), &ServerMode::errorOccured, @@ -139,15 +140,17 @@ void ServerModeReader::setParameters(const BuildDirParameters &p) bool ServerModeReader::isCompatible(const BuildDirParameters &p) { - if (!p.cmakeTool) + CMakeTool *newCmake = p.cmakeTool(); + CMakeTool *oldCmake = m_parameters.cmakeTool(); + if (!newCmake || !oldCmake) return false; // Server mode connection got lost, reset... - if (!m_parameters.cmakeTool->cmakeExecutable().isEmpty() && !m_cmakeServer) + if (!oldCmake && oldCmake->cmakeExecutable().isEmpty() && !m_cmakeServer) return false; - return p.cmakeTool->hasServerMode() - && p.cmakeTool->cmakeExecutable() == m_parameters.cmakeTool->cmakeExecutable() + return newCmake->hasServerMode() + && newCmake->cmakeExecutable() == oldCmake->cmakeExecutable() && p.environment == m_parameters.environment && p.generator == m_parameters.generator && p.extraGenerator == m_parameters.extraGenerator diff --git a/src/plugins/cmakeprojectmanager/tealeafreader.cpp b/src/plugins/cmakeprojectmanager/tealeafreader.cpp index acf19e0e79d..e5ea1951144 100644 --- a/src/plugins/cmakeprojectmanager/tealeafreader.cpp +++ b/src/plugins/cmakeprojectmanager/tealeafreader.cpp @@ -131,8 +131,8 @@ TeaLeafReader::TeaLeafReader() connect(EditorManager::instance(), &EditorManager::aboutToSave, this, [this](const IDocument *document) { if (m_cmakeFiles.contains(document->filePath()) - || !m_parameters.cmakeTool - || !m_parameters.cmakeTool->isAutoRun()) + || !m_parameters.cmakeTool() + || !m_parameters.cmakeTool()->isAutoRun()) emit dirty(); }); @@ -154,9 +154,9 @@ TeaLeafReader::~TeaLeafReader() bool TeaLeafReader::isCompatible(const BuildDirParameters &p) { - if (!p.cmakeTool) + if (!p.cmakeTool()) return false; - return !p.cmakeTool->hasServerMode(); + return !p.cmakeTool()->hasServerMode(); } void TeaLeafReader::resetData() @@ -409,7 +409,8 @@ void TeaLeafReader::cleanUpProcess() void TeaLeafReader::extractData() { - QTC_ASSERT(m_parameters.isValid() && m_parameters.cmakeTool, return); + CMakeTool *cmake = m_parameters.cmakeTool(); + QTC_ASSERT(m_parameters.isValid() && cmake, return); const FileName srcDir = m_parameters.sourceDirectory; const FileName bldDir = m_parameters.workDirectory; @@ -436,7 +437,7 @@ void TeaLeafReader::extractData() // setFolderName CMakeCbpParser cbpparser; // Parsing - if (!cbpparser.parseCbpFile(m_parameters.cmakeTool->pathMapper(), cbpFile, srcDir)) + if (!cbpparser.parseCbpFile(cmake->pathMapper(), cbpFile, srcDir)) return; m_projectName = cbpparser.projectName(); @@ -461,7 +462,8 @@ void TeaLeafReader::extractData() void TeaLeafReader::startCMake(const QStringList &configurationArguments) { - QTC_ASSERT(m_parameters.isValid() && m_parameters.cmakeTool, return); + CMakeTool *cmake = m_parameters.cmakeTool(); + QTC_ASSERT(m_parameters.isValid() && cmake, return); const FileName workDirectory = m_parameters.workDirectory; QTC_ASSERT(!m_cmakeProcess, return); @@ -506,7 +508,7 @@ void TeaLeafReader::startCMake(const QStringList &configurationArguments) TaskHub::clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM); MessageManager::write(tr("Running \"%1 %2\" in %3.") - .arg(m_parameters.cmakeTool->cmakeExecutable().toUserOutput()) + .arg(cmake->cmakeExecutable().toUserOutput()) .arg(args) .arg(workDirectory.toUserOutput())); @@ -516,7 +518,7 @@ void TeaLeafReader::startCMake(const QStringList &configurationArguments) tr("Configuring \"%1\"").arg(m_parameters.projectName), "CMake.Configure"); - m_cmakeProcess->setCommand(m_parameters.cmakeTool->cmakeExecutable().toString(), args); + m_cmakeProcess->setCommand(cmake->cmakeExecutable().toString(), args); emit configurationStarted(); m_cmakeProcess->start(); }