forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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()) {
|
||||
|
@@ -34,7 +34,7 @@
|
||||
|
||||
namespace CppEditor {
|
||||
|
||||
class ProjectFileCategorizer
|
||||
class CPPEDITOR_EXPORT ProjectFileCategorizer
|
||||
{
|
||||
public:
|
||||
using FileIsActive = ProjectExplorer::RawProjectPart::FileIsActive;
|
||||
|
Reference in New Issue
Block a user