diff --git a/src/plugins/cmakeprojectmanager/servermodereader.cpp b/src/plugins/cmakeprojectmanager/servermodereader.cpp index 0fa25b52a1d..aa48e1873b0 100644 --- a/src/plugins/cmakeprojectmanager/servermodereader.cpp +++ b/src/plugins/cmakeprojectmanager/servermodereader.cpp @@ -683,18 +683,23 @@ void ServerModeReader::addFileGroups(ProjectNode *targetRoot, toList.append(newFileNodes); // Add scanned header files: + const FileNameList headerPaths = headers.keys(); for (const IncludePath *i : f->includePaths) { - const QList &headerFiles = headers.value(i->path); - const QList unseenHeaders = Utils::filtered(headerFiles, [&alreadyListed](const FileNode *fn) { - const int count = alreadyListed.count(); - alreadyListed.insert(fn->filePath()); - return count != alreadyListed.count(); - }); - toList.append(Utils::transform(unseenHeaders, [](const FileNode *fn) -> FileNode * { - auto copy = new FileNode(fn->filePath(), fn->fileType(), fn->isGenerated()); - copy->setEnabled(false); - return copy; - })); + for (const FileName &hp : headerPaths) { + if (hp != i->path && !hp.isChildOf(i->path)) + continue; + const QList &headerFiles = headers.value(hp); + const QList unseenHeaders = Utils::filtered(headerFiles, [&alreadyListed](const FileNode *fn) { + const int count = alreadyListed.count(); + alreadyListed.insert(fn->filePath()); + return count != alreadyListed.count(); + }); + toList.append(Utils::transform(unseenHeaders, [](const FileNode *fn) { + auto copy = new FileNode(fn->filePath(), fn->fileType(), fn->isGenerated()); + copy->setEnabled(false); + return copy; + })); + } } }