From fded7e4edd2ec3535e1335790656efebe8d7f2ca Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Thu, 7 Oct 2021 18:36:30 +0200 Subject: [PATCH] CMakePM: Add headers only on compiler groups without PCH sources The change that treats header files as projects added all sources for a certain language for every compiler group. This meant that for the target that has precompiled headers, the source files would be added multiple times. This change reverts to adding only the source files from a compiler group and the header files for a language type, but only for non PCH compiler group. Fixes: QTCREATORBUG-26383 Change-Id: Ib328e0a0331e0f373d5a5981489bc17c58b8eed6 Reviewed-by: David Schulz Reviewed-by: Christian Kandeler --- .../fileapidataextractor.cpp | 58 ++++++++++++------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp index c4f4810f34f..7200a060002 100644 --- a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp +++ b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp @@ -28,9 +28,10 @@ #include "fileapiparser.h" #include "projecttreehelper.h" -#include +#include #include +#include #include #include #include @@ -336,16 +337,6 @@ RawProjectParts generateRawProjectParts(const PreprocessedData &input, int counter = 0; for (const TargetDetails &t : input.targetDetails) { QDir sourceDir(sourceDirectory.toString()); - - // Do not tread generated files and CMake precompiled headers as project files - const auto sourceFiles = Utils::filtered(t.sources, [buildDirectory](const SourceInfo &si) { - return !si.isGenerated && !isPchFile(buildDirectory, FilePath::fromString(si.path)); - }); - CppEditor::ProjectFileCategorizer - categorizer({}, transform(sourceFiles, [&sourceDir](const SourceInfo &si) { - return sourceDir.absoluteFilePath(si.path); - })); - bool needPostfix = t.compileGroups.size() > 1; int count = 1; for (const CompileInfo &ci : t.compileGroups) { @@ -387,20 +378,45 @@ RawProjectParts generateRawProjectParts(const PreprocessedData &input, QStringList fragments = splitFragments(ci.fragments); + // Get all sources from the compiler group, except generated sources + QStringList sources; + for (auto idx: ci.sources) { + SourceInfo si = t.sources.at(idx); + if (si.isGenerated) + continue; + sources.push_back(sourceDir.absoluteFilePath(si.path)); + } + + // If we are not in a pch compiler group, add all the headers that are not generated + const bool hasPchSource = anyOf(sources, [buildDirectory](const QString &path) { + return isPchFile(buildDirectory, FilePath::fromString(path)); + }); + if (!hasPchSource) { + QString headerMimeType; + if (ci.language == "C") + headerMimeType = CppEditor::Constants::C_HEADER_MIMETYPE; + else if (ci.language == "CXX") + headerMimeType = CppEditor::Constants::CPP_HEADER_MIMETYPE; + + for (const SourceInfo &si : t.sources) { + if (si.isGenerated) + continue; + const auto mimeTypes = Utils::mimeTypesForFileName(si.path); + for (auto mime : mimeTypes) + if (mime.name() == headerMimeType) + sources.push_back(sourceDir.absoluteFilePath(si.path)); + } + } + + // Set project files except pch files + rpp.setFiles(Utils::filtered(sources, [buildDirectory](const QString &path) { + return !isPchFile(buildDirectory, FilePath::fromString(path)); + })); + FilePath precompiled_header = FilePath::fromString(findOrDefault(t.sources, [&ending](const SourceInfo &si) { return si.path.endsWith(ending); }).path); - - CppEditor::ProjectFiles sources; - if (ci.language == "C") - sources = categorizer.cSources(); - else if (ci.language == "CXX") - sources = categorizer.cxxSources(); - - rpp.setFiles(transform(sources, [](const CppEditor::ProjectFile &pf) { - return pf.path; - })); if (!precompiled_header.isEmpty()) { if (precompiled_header.toFileInfo().isRelative()) { const FilePath parentDir = FilePath::fromString(sourceDir.absolutePath());