From 152d2245d9ed10aad188208cbdea02f0cf94c482 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Fri, 16 Nov 2018 14:10:35 +0100 Subject: [PATCH] CMake: Suppress header-only targets from code model Do not report targets that contain headers only and have no include directories/defines set up to the code model. Such targets are used to tell creator about the projects header files as a work-around to creator not reporting headers in cmake projects. This work-around is of course not necessary anymore, but it is widely used and breaks the heuristics in the code model. So do not inform the code model about these parts of the project. Task-number: QTCREATORBUG-21425 Change-Id: I387d9d9fb4ae7b54fa08ee9b23efb9ab1f179b9c Reviewed-by: Nikolai Kosjar --- .../cmakeprojectmanager/servermodereader.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/plugins/cmakeprojectmanager/servermodereader.cpp b/src/plugins/cmakeprojectmanager/servermodereader.cpp index 3451e704da4..54364f75c7b 100644 --- a/src/plugins/cmakeprojectmanager/servermodereader.cpp +++ b/src/plugins/cmakeprojectmanager/servermodereader.cpp @@ -360,6 +360,19 @@ void ServerModeReader::updateCodeModel(CppTools::RawProjectParts &rpps) { int counter = 0; for (const FileGroup *fg : qAsConst(m_fileGroups)) { + // CMake users worked around Creator's inability of listing header files by creating + // custom targets with all the header files. This target breaks the code model, so + // keep quiet about it:-) + if (fg->macros.isEmpty() + && fg->includePaths.isEmpty() + && !fg->isGenerated + && Utils::allOf(fg->sources, [](const Utils::FileName &source) { + return Node::fileTypeForFileName(source) == FileType::Header; + })) { + qWarning() << "Not reporting all-header file group of target" << fg->target << "to code model."; + continue; + } + ++counter; const QStringList flags = QtcProcess::splitArgs(fg->compileFlags); const QStringList includes = transform(fg->includePaths, [](const IncludePath *ip) { return ip->path.toString(); });