diff options
author | Cristian Adam <cristian.adam@qt.io> | 2021-09-22 20:35:26 +0200 |
---|---|---|
committer | Cristian Adam <cristian.adam@qt.io> | 2021-09-23 13:52:05 +0000 |
commit | 4cad094066370fd177e3cb7fde64fd80e05eee84 (patch) | |
tree | b1cdfa817e2d51cb7f1ae5b2eef0abf91d3de994 /src/plugins/cmakeprojectmanager/fileapidataextractor.cpp | |
parent | ddccb87a879b5b015c17d8733b1b1f429f573d3e (diff) | |
download | qt-creator-4cad094066370fd177e3cb7fde64fd80e05eee84.tar.gz |
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 <eike.ziller@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/cmakeprojectmanager/fileapidataextractor.cpp')
-rw-r--r-- | src/plugins/cmakeprojectmanager/fileapidataextractor.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
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 <cppeditor/cppprojectfilecategorizer.h> + #include <utils/algorithm.h> #include <utils/qtcassert.h> #include <utils/qtcprocess.h> @@ -329,6 +331,11 @@ RawProjectParts generateRawProjectParts(const PreprocessedData &input, for (const TargetDetails &t : input.targetDetails) { QDir sourceDir(sourceDirectory.toString()); + CppEditor::ProjectFileCategorizer + categorizer({}, transform<QList>(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<QList>(ci.sources, [&t, &sourceDir](const int si) { - return sourceDir.absoluteFilePath(t.sources[static_cast<size_t>(si)].path); + CppEditor::ProjectFiles sources; + if (ci.language == "C") + sources = categorizer.cSources(); + else if (ci.language == "CXX") + sources = categorizer.cxxSources(); + + rpp.setFiles(transform<QList>(sources, [](const CppEditor::ProjectFile &pf) { + return pf.path; })); if (!precompiled_header.isEmpty()) { if (precompiled_header.toFileInfo().isRelative()) { |