From 069bb2d359acb7ea77157b8ec0e6b7982fead344 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Tue, 14 Jun 2016 17:43:11 +0200 Subject: [PATCH] CMake: Work around cmake reporting include paths in random order Work around cmake reporting include paths in random order to Qt Creator due to a bug in the CodeBlocks generator. Remove the tool chains include paths from the list reported by cmake and have the code model add those again later. That keeps at least the include paths of the compiler in order, which is important as this makes sure any fixed headers shipped with the compiler actually get picked up. Task-number: QTCREATORBUG-16432 Change-Id: I218735914bcc750ce87b02b05d111f3fe2bb5644 Reviewed-by: Tim Jenssen --- .../cmakeprojectmanager/cmakeproject.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index 1f2ddb95514..e7c78ab01df 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -66,6 +66,7 @@ #include #include +#include #include using namespace ProjectExplorer; @@ -242,15 +243,27 @@ void CMakeProject::parseCMakeOutput() activeQtVersion = CppTools::ProjectPart::Qt5; } + const Utils::FileName sysroot = ProjectExplorer::SysRootKitInformation::sysRoot(k); + ppBuilder.setQtVersion(activeQtVersion); QHash targetDataCache; foreach (const CMakeBuildTarget &cbt, buildTargets()) { - // This explicitly adds -I. to the include paths - QStringList includePaths = cbt.includeFiles; + // CMake shuffles the include paths that it reports via the CodeBlocks generator + // So remove the toolchain include paths, so that at least those end up in the correct + // place. + QStringList cxxflags = getCXXFlagsFor(cbt, targetDataCache); + QSet tcIncludes; + foreach (const HeaderPath &hp, tc->systemHeaderPaths(cxxflags, sysroot)) { + tcIncludes.insert(hp.path()); + } + QStringList includePaths; + foreach (const QString &i, cbt.includeFiles) { + if (!tcIncludes.contains(i)) + includePaths.append(i); + } includePaths += projectDirectory().toString(); ppBuilder.setIncludePaths(includePaths); - QStringList cxxflags = getCXXFlagsFor(cbt, targetDataCache); ppBuilder.setCFlags(cxxflags); ppBuilder.setCxxFlags(cxxflags); ppBuilder.setDefines(cbt.defines);