diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index 2845b74ed00fc6b51569b242b61ca267a8415a12..e0129942eb1bdf10113a0a3e4c1a90a8fb71d01b 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -293,6 +293,10 @@ bool CMakeProject::parseCMakeLists() allIncludePaths.append(projectDirectory()); allIncludePaths.append(cbpparser.includeFiles()); + QByteArray allDefines; + allDefines.append(activeBC->toolChain()->predefinedMacros(QStringList())); + allDefines.append(cbpparser.defines()); + QStringList allFrameworkPaths; QList<ProjectExplorer::HeaderPath> allHeaderPaths; if (activeBC->toolChain()) @@ -310,7 +314,7 @@ bool CMakeProject::parseCMakeLists() CPlusPlus::CppModelManagerInterface::ProjectInfo pinfo = modelmanager->projectInfo(this); if (pinfo.includePaths() != allIncludePaths || pinfo.sourceFiles() != m_files - || pinfo.defines() != (activeBC->toolChain() ? activeBC->toolChain()->predefinedMacros(QStringList()) : QByteArray()) + || pinfo.defines() != allDefines || pinfo.frameworkPaths() != allFrameworkPaths) { pinfo.clearProjectParts(); CPlusPlus::CppModelManagerInterface::ProjectPart::Ptr part( @@ -318,7 +322,7 @@ bool CMakeProject::parseCMakeLists() part->includePaths = allIncludePaths; // TODO we only want C++ files, not all other stuff that might be in the project part->sourceFiles = m_files; - part->defines = (activeBC->toolChain() ? activeBC->toolChain()->predefinedMacros(QStringList()) : QByteArray()); // TODO this is to simplistic + part->defines = allDefines; part->frameworkPaths = allFrameworkPaths; part->language = CPlusPlus::CppModelManagerInterface::CXX; pinfo.appendProjectPart(part); @@ -1085,7 +1089,31 @@ void CMakeCbpParser::parseCompiler() void CMakeCbpParser::parseAdd() { - m_includeFiles.append(attributes().value("directory").toString()); + // CMake only supports <Add option=\> and <Add directory=\> + const QXmlStreamAttributes addAttributes = attributes(); + + const QString includeDirectory = addAttributes.value("directory").toString(); + // allow adding multiple times because order happens + if (!includeDirectory.isEmpty()) { + m_includeFiles.append(includeDirectory); + } + + QString compilerOption = addAttributes.value("option").toString(); + // defining multiple times a macro to the same value makes no sense + if (!compilerOption.isEmpty() && !m_compilerOptions.contains(compilerOption)) { + m_compilerOptions.append(compilerOption); + int macroNameIndex = compilerOption.indexOf("-D") + 2; + if (macroNameIndex != 1) { + int assignIndex = compilerOption.indexOf('=', macroNameIndex); + if (assignIndex != -1) { + compilerOption[assignIndex] = ' '; + } + m_defines.append("#define "); + m_defines.append(compilerOption.mid(macroNameIndex).toAscii()); + m_defines.append('\n'); + } + } + while (!atEnd()) { readNext(); if (isEndElement()) { @@ -1183,6 +1211,11 @@ QStringList CMakeCbpParser::includeFiles() return m_includeFiles; } +QByteArray CMakeCbpParser::defines() const +{ + return m_defines; +} + QList<CMakeBuildTarget> CMakeCbpParser::buildTargets() { return m_buildTargets; diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h index 52183e905b0420bc15d31771e2cc32ec3fef4b93..6166a348b24502e22c262460bb0ed0a59e47bdd5 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.h +++ b/src/plugins/cmakeprojectmanager/cmakeproject.h @@ -162,9 +162,11 @@ public: QList<ProjectExplorer::FileNode *> cmakeFileList(); QStringList includeFiles(); QList<CMakeBuildTarget> buildTargets(); + QByteArray defines() const; QString projectName() const; QString compilerName() const; bool hasCMakeFiles(); + private: void parseCodeBlocks_project_file(); void parseProject(); @@ -186,6 +188,8 @@ private: QSet<QString> m_processedUnits; bool m_parsingCmakeUnit; QStringList m_includeFiles; + QStringList m_compilerOptions; + QByteArray m_defines; CMakeBuildTarget m_buildTarget; bool m_buildTargetType;