diff --git a/src/plugins/cmakeprojectmanager/cmakecbpparser.cpp b/src/plugins/cmakeprojectmanager/cmakecbpparser.cpp index c75133b2180..16d3336cd0d 100644 --- a/src/plugins/cmakeprojectmanager/cmakecbpparser.cpp +++ b/src/plugins/cmakeprojectmanager/cmakecbpparser.cpp @@ -29,6 +29,8 @@ ****************************************************************************/ #include "cmakecbpparser.h" +#include "cmakekitinformation.h" +#include "cmaketool.h" #include #include @@ -147,8 +149,9 @@ void CMakeCbpParser::sortFiles() qCDebug(log) << target.title << target.sourceDirectory << target.includeFiles << target.defines << target.files << "\n"; } -bool CMakeCbpParser::parseCbpFile(const QString &fileName, const QString &sourceDirectory) +bool CMakeCbpParser::parseCbpFile(Kit *kit, const QString &fileName, const QString &sourceDirectory) { + m_kit = kit; m_buildDirectory = QFileInfo(fileName).absolutePath(); m_sourceDirectory = sourceDirectory; @@ -245,6 +248,9 @@ void CMakeCbpParser::parseBuildTargetOption() { if (attributes().hasAttribute(QLatin1String("output"))) { m_buildTarget.executable = attributes().value(QLatin1String("output")).toString(); + CMakeTool *tool = CMakeKitInformation::cmakeTool(m_kit); + if (tool) + m_buildTarget.executable = tool->mapAllPaths(m_kit, m_buildTarget.executable); } else if (attributes().hasAttribute(QLatin1String("type"))) { const QStringRef value = attributes().value(QLatin1String("type")); if (value == QLatin1String("2") || value == QLatin1String("3")) @@ -304,8 +310,13 @@ void CMakeCbpParser::parseMakeCommands() void CMakeCbpParser::parseBuildTargetBuild() { - if (attributes().hasAttribute(QLatin1String("command"))) + if (attributes().hasAttribute(QLatin1String("command"))) { m_buildTarget.makeCommand = attributes().value(QLatin1String("command")).toString(); + + CMakeTool *tool = CMakeKitInformation::cmakeTool(m_kit); + if (tool) + m_buildTarget.makeCommand = tool->mapAllPaths(m_kit, m_buildTarget.makeCommand); + } while (!atEnd()) { readNext(); if (isEndElement()) @@ -317,8 +328,13 @@ void CMakeCbpParser::parseBuildTargetBuild() void CMakeCbpParser::parseBuildTargetClean() { - if (attributes().hasAttribute(QLatin1String("command"))) + if (attributes().hasAttribute(QLatin1String("command"))) { m_buildTarget.makeCleanCommand = attributes().value(QLatin1String("command")).toString(); + + CMakeTool *tool = CMakeKitInformation::cmakeTool(m_kit); + if (tool) + m_buildTarget.makeCleanCommand = tool->mapAllPaths(m_kit, m_buildTarget.makeCleanCommand); + } while (!atEnd()) { readNext(); if (isEndElement()) @@ -346,7 +362,12 @@ void CMakeCbpParser::parseAdd() // CMake only supports and const QXmlStreamAttributes addAttributes = attributes(); - const QString includeDirectory = addAttributes.value(QLatin1String("directory")).toString(); + QString includeDirectory = addAttributes.value(QLatin1String("directory")).toString(); + + CMakeTool *tool = CMakeKitInformation::cmakeTool(m_kit); + if (tool) + includeDirectory = tool->mapAllPaths(m_kit, includeDirectory); + // allow adding multiple times because order happens if (!includeDirectory.isEmpty()) m_buildTarget.includeFiles.append(includeDirectory); @@ -380,6 +401,13 @@ void CMakeCbpParser::parseUnit() //qDebug()<mapAllPaths(m_kit, fileName.toString()); + fileName = FileName::fromUserInput(mappedFile); + } + m_parsingCmakeUnit = false; while (!atEnd()) { readNext(); diff --git a/src/plugins/cmakeprojectmanager/cmakecbpparser.h b/src/plugins/cmakeprojectmanager/cmakecbpparser.h index 62480c2c7be..f18ff846ffd 100644 --- a/src/plugins/cmakeprojectmanager/cmakecbpparser.h +++ b/src/plugins/cmakeprojectmanager/cmakecbpparser.h @@ -36,7 +36,10 @@ #include -namespace ProjectExplorer { class FileNode; } +namespace ProjectExplorer { +class FileNode; +class Kit; +} namespace CMakeProjectManager { namespace Internal { @@ -44,7 +47,7 @@ namespace Internal { class CMakeCbpParser : public QXmlStreamReader { public: - bool parseCbpFile(const QString &fileName, const QString &sourceDirectory); + bool parseCbpFile(ProjectExplorer::Kit *kit, const QString &fileName, const QString &sourceDirectory); QList fileList(); QList cmakeFileList(); QList buildTargets(); @@ -69,6 +72,7 @@ private: void parseUnknownElement(); void sortFiles(); + ProjectExplorer::Kit *m_kit; QList m_fileList; QList m_cmakeFileList; QSet m_processedUnits; diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index eac208d2249..15e128bbbb1 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -246,12 +246,14 @@ bool CMakeProject::parseCMakeLists() return false; } + Kit *k = activeTarget()->kit(); + // setFolderName m_rootNode->setDisplayName(QFileInfo(cbpFile).completeBaseName()); CMakeCbpParser cbpparser; // Parsing //qDebug()<<"Parsing file "<kit(); ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(k); if (!tc) { emit buildTargetsChanged(); diff --git a/src/plugins/cmakeprojectmanager/cmaketool.cpp b/src/plugins/cmakeprojectmanager/cmaketool.cpp index ebc14a29aa8..180baf97209 100644 --- a/src/plugins/cmakeprojectmanager/cmaketool.cpp +++ b/src/plugins/cmakeprojectmanager/cmaketool.cpp @@ -284,6 +284,17 @@ void CMakeTool::setDisplayName(const QString &displayName) CMakeToolManager::notifyAboutUpdate(this); } +void CMakeTool::setPathMapper(const CMakeTool::PathMapper &pathMapper) +{ + m_pathMapper = pathMapper; +} + +QString CMakeTool::mapAllPaths(ProjectExplorer::Kit *kit, const QString &in) const +{ + if (m_pathMapper) + return m_pathMapper(kit, in); + return in; +} void CMakeTool::parseFunctionDetailsOutput(const QByteArray &output) { diff --git a/src/plugins/cmakeprojectmanager/cmaketool.h b/src/plugins/cmakeprojectmanager/cmaketool.h index 9c98c0949e7..9fcbf4ab1cd 100644 --- a/src/plugins/cmakeprojectmanager/cmaketool.h +++ b/src/plugins/cmakeprojectmanager/cmaketool.h @@ -43,6 +43,8 @@ QT_FORWARD_DECLARE_CLASS(QProcess) +namespace ProjectExplorer { class Kit; } + namespace CMakeProjectManager { class CMAKE_EXPORT CMakeTool : public QObject @@ -54,6 +56,8 @@ public: AutoDetection }; + typedef std::function PathMapper; + explicit CMakeTool(Detection d, const Core::Id &id = Core::Id()); explicit CMakeTool(const QVariantMap &map, bool fromSdk); ~CMakeTool(); @@ -75,6 +79,9 @@ public: QString displayName() const; void setDisplayName(const QString &displayName); + void setPathMapper(const PathMapper &includePathMapper); + QString mapAllPaths(ProjectExplorer::Kit *kit, const QString &in) const; + private slots: void finished(int exitCode); @@ -103,6 +110,7 @@ private: Core::Id m_id; QString m_displayName; + PathMapper m_pathMapper; }; } // namespace CMakeProjectManager diff --git a/src/plugins/cmakeprojectmanager/cmaketoolmanager.cpp b/src/plugins/cmakeprojectmanager/cmaketoolmanager.cpp index 913d076ed1d..f157fccc5e9 100644 --- a/src/plugins/cmakeprojectmanager/cmaketoolmanager.cpp +++ b/src/plugins/cmakeprojectmanager/cmaketoolmanager.cpp @@ -394,6 +394,7 @@ void CMakeToolManager::restoreCMakeTools() // restore the legacy cmake settings only once and keep them around readAndDeleteLegacyCMakeSettings(); + emit m_instance->cmakeToolsLoaded(); } void CMakeToolManager::registerAutodetectionHelper(CMakeToolManager::AutodetectionHelper helper) diff --git a/src/plugins/cmakeprojectmanager/cmaketoolmanager.h b/src/plugins/cmakeprojectmanager/cmaketoolmanager.h index 23b75a88eb6..6edf21618a0 100644 --- a/src/plugins/cmakeprojectmanager/cmaketoolmanager.h +++ b/src/plugins/cmakeprojectmanager/cmaketoolmanager.h @@ -75,6 +75,7 @@ signals: void cmakeRemoved (const Core::Id &id); void cmakeUpdated (const Core::Id &id); void cmakeToolsChanged (); + void cmakeToolsLoaded (); void defaultCMakeChanged (); private: