CMake: Exclude non-project CMake files from search

All the CMake files the belong to packages found with `find_package` are
part of the project tree, but we shouldn't include them when searching
through "files in the project".

Set listInProjects to false for these files.

Fixes: QTCREATORBUG-30372
Change-Id: If39d477f14dc3207f4e2dd66b2f3969811dbd863
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Eike Ziller
2024-02-15 10:33:27 +01:00
parent 5d41ab126f
commit 832fde9e0e
2 changed files with 12 additions and 7 deletions

View File

@@ -35,7 +35,8 @@ void addCMakeVFolder(FolderNode *base,
int priority, int priority,
const QString &displayName, const QString &displayName,
std::vector<std::unique_ptr<FileNode>> &&files, std::vector<std::unique_ptr<FileNode>> &&files,
bool sourcesOrHeaders) bool sourcesOrHeaders,
bool listInProject)
{ {
if (files.size() == 0) if (files.size() == 0)
return; return;
@@ -45,6 +46,10 @@ void addCMakeVFolder(FolderNode *base,
folder = newFolder.get(); folder = newFolder.get();
base->addNode(std::move(newFolder)); base->addNode(std::move(newFolder));
} }
if (!listInProject) {
for (auto it = files.begin(); it != files.end(); ++it)
(*it)->setListInProject(false);
}
folder->addNestedNodes(std::move(files)); folder->addNestedNodes(std::move(files));
folder->forEachFolderNode([] (FolderNode *fn) { fn->compress(); }); folder->forEachFolderNode([] (FolderNode *fn) { fn->compress(); });
} }
@@ -68,10 +73,7 @@ void addCMakeInputs(FolderNode *root,
std::unique_ptr<ProjectNode> cmakeVFolder = std::make_unique<CMakeInputsNode>(root->filePath()); std::unique_ptr<ProjectNode> cmakeVFolder = std::make_unique<CMakeInputsNode>(root->filePath());
QSet<Utils::FilePath> knownFiles; QSet<Utils::FilePath> knownFiles;
root->forEachGenericNode([&knownFiles](const Node *n) { root->forEachGenericNode([&knownFiles](const Node *n) { knownFiles.insert(n->filePath()); });
if (n->listInProject())
knownFiles.insert(n->filePath());
});
addCMakeVFolder(cmakeVFolder.get(), addCMakeVFolder(cmakeVFolder.get(),
sourceDir, sourceDir,
@@ -87,7 +89,9 @@ void addCMakeInputs(FolderNode *root,
Utils::FilePath(), Utils::FilePath(),
10, 10,
Tr::tr("<Other Locations>"), Tr::tr("<Other Locations>"),
removeKnownNodes(knownFiles, std::move(rootInputs))); removeKnownNodes(knownFiles, std::move(rootInputs)),
/*sourcesOrHeaders=*/false,
/*listInProject=*/false);
root->addNode(std::move(cmakeVFolder)); root->addNode(std::move(cmakeVFolder));
} }

View File

@@ -21,7 +21,8 @@ void addCMakeVFolder(ProjectExplorer::FolderNode *base,
int priority, int priority,
const QString &displayName, const QString &displayName,
std::vector<std::unique_ptr<ProjectExplorer::FileNode>> &&files, std::vector<std::unique_ptr<ProjectExplorer::FileNode>> &&files,
bool sourcesOrHeaders = false); bool sourcesOrHeaders = false,
bool listInProject = true);
std::vector<std::unique_ptr<ProjectExplorer::FileNode>> &&removeKnownNodes( std::vector<std::unique_ptr<ProjectExplorer::FileNode>> &&removeKnownNodes(
const QSet<Utils::FilePath> &knownFiles, const QSet<Utils::FilePath> &knownFiles,