diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 0f9abde479d..8523b392e87 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -48,7 +48,6 @@ add_subdirectory(autotoolsprojectmanager) add_subdirectory(bazaar) add_subdirectory(beautifier) add_subdirectory(clearcase) -add_subdirectory(cmakeprojectmanager) add_subdirectory(cvs) add_subdirectory(designer) add_subdirectory(docker) @@ -80,6 +79,7 @@ if (WITH_QMLDESIGNER) endif() add_subdirectory(python) add_subdirectory(clangformat) +add_subdirectory(cmakeprojectmanager) # Level 7: add_subdirectory(android) diff --git a/src/plugins/cmakeprojectmanager/CMakeLists.txt b/src/plugins/cmakeprojectmanager/CMakeLists.txt index 492d6284146..2c58b4f08b3 100644 --- a/src/plugins/cmakeprojectmanager/CMakeLists.txt +++ b/src/plugins/cmakeprojectmanager/CMakeLists.txt @@ -1,7 +1,7 @@ add_qtc_plugin(CMakeProjectManager PLUGIN_CLASS CMakeProjectPlugin DEPENDS QmlJS - PLUGIN_DEPENDS Core CppEditor ProjectExplorer TextEditor QtSupport + PLUGIN_DEPENDS Core CppEditor Debugger ProjectExplorer TextEditor QtSupport SYSTEM_INCLUDES 3dparty/cmake SOURCES builddirparameters.cpp builddirparameters.h diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp index 6df1e7452d7..5189c7934fd 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp @@ -12,6 +12,9 @@ #include "presetsmacros.h" #include +#include +#include +#include #include #include @@ -30,7 +33,9 @@ #include #include +#include +using namespace Debugger; using namespace ProjectExplorer; using namespace QtSupport; using namespace Utils; @@ -60,6 +65,7 @@ struct DirectoryData FilePath sysroot; QtProjectImporter::QtVersionData qt; QVector toolchains; + QVariant debugger; }; static FilePaths scanDirectory(const FilePath &path, const QString &prefix) @@ -205,6 +211,48 @@ FilePaths CMakeProjectImporter::presetCandidates() return candidates; } +static QVariant findOrRegisterDebugger( + Environment &env, const std::optional &vendor, const QString &presetName) +{ + const QString debuggerKey("debugger"); + if (!vendor || !vendor.value().contains(debuggerKey)) + return {}; + + const QVariant debuggerVariant = vendor.value().value(debuggerKey); + FilePath debuggerPath = FilePath::fromUserInput(debuggerVariant.toString()); + if (!debuggerPath.isEmpty()) { + if (debuggerPath.isRelativePath()) + debuggerPath = env.searchInPath(debuggerPath.fileName()); + + const QString mainName = Tr::tr("CMake Preset (%1) %2 Debugger"); + DebuggerItem debugger; + debugger.setCommand(debuggerPath); + debugger.setUnexpandedDisplayName( + mainName.arg(presetName).arg(debuggerPath.completeBaseName())); + debugger.setAutoDetected(false); + QString errorMessage; + debugger.reinitializeFromFile(&errorMessage, &env); + if (!errorMessage.isEmpty()) + qCWarning(cmInputLog()) << "Error reinitializing debugger" << debuggerPath.toString() + << "Error:" << errorMessage; + + return DebuggerItemManager::registerDebugger(debugger); + } else { + auto debuggerMap = debuggerVariant.toMap(); + if (debuggerMap.isEmpty()) + return {}; + + // Manually create an Id, otrhewise the Kit will not have a debugger set + if (!debuggerMap.contains("Id")) + debuggerMap.insert("Id", QUuid::createUuid().toString()); + + auto store = storeFromMap(debuggerMap); + DebuggerItem debugger(store); + + return DebuggerItemManager::registerDebugger(debugger); + } +} + Target *CMakeProjectImporter::preferredTarget(const QList &possibleTargets) { for (Kit *kit : m_project->oldPresetKits()) { @@ -835,6 +883,8 @@ QList CMakeProjectImporter::examineDirectory(const FilePath &importPath, data->hasQmlDebugging = CMakeBuildConfiguration::hasQmlDebugging(config); + data->debugger = findOrRegisterDebugger(env, configurePreset.vendor, configurePreset.name); + QByteArrayList buildConfigurationTypes = {cache.valueOf("CMAKE_BUILD_TYPE")}; if (buildConfigurationTypes.front().isEmpty()) { buildConfigurationTypes.clear(); @@ -1055,6 +1105,9 @@ Kit *CMakeProjectImporter::createKit(void *directoryData) const if (!data->cmakePreset.isEmpty()) ensureBuildDirectory(*data, k); + if (data->debugger.isValid()) + DebuggerKitAspect::setDebugger(k, data->debugger); + qCInfo(cmInputLog) << "Temporary Kit created."; }); } diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs index 1cbaac7b6d6..98849a71f57 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs @@ -8,6 +8,7 @@ QtcPlugin { Depends { name: "Core" } Depends { name: "CppEditor" } + Depends { name: "Debugger" } Depends { name: "QmlJS" } Depends { name: "ProjectExplorer" } Depends { name: "TextEditor" } diff --git a/src/plugins/cmakeprojectmanager/presetsparser.cpp b/src/plugins/cmakeprojectmanager/presetsparser.cpp index c83eb6e5d3f..6c15f217f09 100644 --- a/src/plugins/cmakeprojectmanager/presetsparser.cpp +++ b/src/plugins/cmakeprojectmanager/presetsparser.cpp @@ -148,6 +148,30 @@ std::optional parseCondition(const QJsonValue &jsonVa return condition; } +bool parseVendor(const QJsonValue &jsonValue, std::optional &vendorSettings) +{ + // The whole section is optional + if (jsonValue.isUndefined()) + return true; + if (!jsonValue.isObject()) + return false; + + const QJsonObject object = jsonValue.toObject(); + const QJsonValue qtIo = object.value("qt.io/QtCreator/1.0"); + if (qtIo.isUndefined()) + return true; + if (!qtIo.isObject()) + return false; + + const QJsonObject qtIoObject = qtIo.toObject(); + vendorSettings = QVariantMap(); + for (const QString &settingKey : qtIoObject.keys()) { + const QJsonValue settingValue = qtIoObject.value(settingKey); + vendorSettings->insert(settingKey, settingValue.toVariant()); + } + return true; +} + bool parseConfigurePresets(const QJsonValue &jsonValue, QList &configurePresets, const Utils::FilePath &fileDir) @@ -188,6 +212,9 @@ bool parseConfigurePresets(const QJsonValue &jsonValue, if (object.contains("condition")) preset.condition = parseCondition(object.value("condition")); + if (object.contains("vendor")) + parseVendor(object.value("vendor"), preset.vendor); + if (object.contains("displayName")) preset.displayName = object.value("displayName").toString(); if (object.contains("description")) @@ -378,6 +405,9 @@ bool parseBuildPresets(const QJsonValue &jsonValue, if (object.contains("condition")) preset.condition = parseCondition(object.value("condition")); + if (object.contains("vendor")) + parseVendor(object.value("vendor"), preset.vendor); + if (object.contains("displayName")) preset.displayName = object.value("displayName").toString(); if (object.contains("description")) @@ -435,30 +465,6 @@ bool parseBuildPresets(const QJsonValue &jsonValue, return true; } -bool parseVendor(const QJsonValue &jsonValue, std::optional &vendorSettings) -{ - // The whole section is optional - if (jsonValue.isUndefined()) - return true; - if (!jsonValue.isObject()) - return false; - - const QJsonObject object = jsonValue.toObject(); - const QJsonValue qtIo = object.value("qt.io/QtCreator/1.0"); - if (qtIo.isUndefined()) - return true; - if (!qtIo.isObject()) - return false; - - const QJsonObject qtIoObject = qtIo.toObject(); - vendorSettings = QVariantMap(); - for (const QString &settingKey : qtIoObject.keys()) { - const QJsonValue settingValue = qtIoObject.value(settingKey); - vendorSettings->insert(settingKey, settingValue.toVariant()); - } - return true; -} - const PresetsData &PresetsParser::presetsData() const { return m_presetsData; @@ -535,10 +541,9 @@ bool PresetsParser::parse(const Utils::FilePath &jsonFile, QString &errorMessage return true; } -static QHash merge(const QHash &first, - const QHash &second) +static QVariantMap merge(const QVariantMap &first, const QVariantMap &second) { - QHash result = first; + QVariantMap result = first; for (auto it = second.constKeyValueBegin(); it != second.constKeyValueEnd(); ++it) { result[it->first] = it->second; } diff --git a/src/plugins/cmakeprojectmanager/presetsparser.h b/src/plugins/cmakeprojectmanager/presetsparser.h index b4852656881..cfbf5654895 100644 --- a/src/plugins/cmakeprojectmanager/presetsparser.h +++ b/src/plugins/cmakeprojectmanager/presetsparser.h @@ -94,7 +94,7 @@ public: std::optional hidden = false; std::optional inherits; std::optional condition; - std::optional> vendor; + std::optional vendor; std::optional displayName; std::optional description; std::optional generator; @@ -120,7 +120,7 @@ public: std::optional hidden = false; std::optional inherits; std::optional condition; - std::optional> vendor; + std::optional vendor; std::optional displayName; std::optional description; std::optional environment;