From 4cad094066370fd177e3cb7fde64fd80e05eee84 Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Wed, 22 Sep 2021 20:35:26 +0200 Subject: CMakePM: Treat header files as project files CMake doesn't associate header files in a compiler group in the file-api export. But it does list them as source files if added to the source files of a target. By using the CppEditor::ProjectFileCategorizer we can sort the header files to the right compiler group. This way one could have the clang-tidy and clazy run on a header file. Or the TODO plugin find TODOs in header files. Or the Autotest plugin finding Google Tests in header files. Fixes: QTCREATORBUG-23783 Fixes: QTCREATORBUG-23843 Fixes: QTCREATORBUG-26201 Fixes: QTCREATORBUG-26238 Change-Id: I8acace48e89fd9b3da8bce1c479dec7891e1bbd4 Reviewed-by: Eike Ziller Reviewed-by: Christian Kandeler --- .../cmakeprojectmanager/fileapidataextractor.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/plugins/cmakeprojectmanager/fileapidataextractor.cpp') diff --git a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp index 95e438de6b..13c99c5bfb 100644 --- a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp +++ b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp @@ -28,6 +28,8 @@ #include "fileapiparser.h" #include "projecttreehelper.h" +#include + #include #include #include @@ -329,6 +331,11 @@ RawProjectParts generateRawProjectParts(const PreprocessedData &input, for (const TargetDetails &t : input.targetDetails) { QDir sourceDir(sourceDirectory.toString()); + CppEditor::ProjectFileCategorizer + categorizer({}, transform(t.sources, [&sourceDir](const SourceInfo &si) { + return sourceDir.absoluteFilePath(si.path); + })); + bool needPostfix = t.compileGroups.size() > 1; int count = 1; for (const CompileInfo &ci : t.compileGroups) { @@ -375,8 +382,14 @@ RawProjectParts generateRawProjectParts(const PreprocessedData &input, return si.path.endsWith(ending); }).path); - rpp.setFiles(transform(ci.sources, [&t, &sourceDir](const int si) { - return sourceDir.absoluteFilePath(t.sources[static_cast(si)].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()) { -- cgit v1.2.1