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.

(cherry picked from commit 152d2245d9)
Task-number: QTCREATORBUG-21425
Change-Id: I387d9d9fb4ae7b54fa08ee9b23efb9ab1f179b9c
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Tobias Hunger
2018-11-16 14:10:35 +01:00
committed by Nikolai Kosjar
parent b364282228
commit 20badbe019

View File

@@ -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(); });