From 6fd9a3c807619b699d0927e85544d53a8cfd955e Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Thu, 8 Aug 2024 11:22:10 +0200 Subject: [PATCH] CMakePM: Refactor display of CMakeLists.txt All CMakeLists.txt from the Project view are marked as generated, except the root one. This means that in normal case they will be hidden. Every CMake Target (except Utility) will get a CMakeLists.txt: entry with the definition line of the target. The CMake Folders will get an entry with the CMakeLists.txt which can be accessed via context menu and "Open...". The CMake Folder that only had a CMakeLists.txt will be removed when the filter "Hide Empty Directories" is checked. This for example makes a reduced plugin Qt Creator only display the enabled plugins, and not all plugins! With this change the "Simplify Tree" view will no longer have many CMakeLists.txt entries, which makes the view more useful. Fixes: QTCREATORBUG-31362 Change-Id: I708171e4b114100fae6fb592044a19fc36239261 Reviewed-by: Marcus Tillmanns --- .../cmakeprojectmanager/cmakeprojectnodes.cpp | 2 ++ .../fileapidataextractor.cpp | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp index 54f28f7b2ad..bb58db95e36 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp @@ -44,6 +44,8 @@ CMakeListsNode::CMakeListsNode(const FilePath &cmakeListPath) : { setIcon(DirectoryIcon(Constants::Icons::FILE_OVERLAY)); setListInProject(false); + setLocationInfo( + {{Constants::CMAKE_LISTS_TXT, cmakeListPath.pathAppended(Constants::CMAKE_LISTS_TXT)}}); } bool CMakeListsNode::showInSimpleTree() const diff --git a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp index d65dbac18a2..640ae571759 100644 --- a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp +++ b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp @@ -112,10 +112,12 @@ static CMakeFileResult extractCMakeFilesData(const QFuture &cancelFuture, } auto node = std::make_unique(info.path, FileType::Project); - node->setIsGenerated(info.isGenerated - && !info.isCMakeListsDotTxt); // CMakeLists.txt are never - // generated, independent - // what cmake thinks:-) + node->setIsGenerated(info.isGenerated); + + // We will have the CMakeLists.txt file in the Target nodes as a child node. + // Except the root CMakeLists.txt file. + if (info.isCMakeListsDotTxt && info.path.parentDir() != sourceDirectory) + node->setIsGenerated(true); if (info.isCMakeListsDotTxt) { result.cmakeListNodes.emplace_back(std::move(node)); @@ -938,6 +940,14 @@ static void setupLocationInfoForTargets(const QFuture &cancelFuture, result += dedupMulti(t.installDefinitions); folderNode->setLocationInfo(result); + + if (!t.backtrace.isEmpty() && t.targetType != TargetType::UtilityType) { + auto cmakeDefinition = std::make_unique( + t.backtrace.last().path, Node::fileTypeForFileName(t.backtrace.last().path)); + cmakeDefinition->setLine(t.backtrace.last().line); + cmakeDefinition->setPriority(Node::DefaultProjectFilePriority); + folderNode->addNode(std::move(cmakeDefinition)); + } } } }