CMakePM: Fix Subproject build for targets using FOLDER property

If a target is being moved around using the FOLDER property as:

  set_target_properties(mytarget PROPERTIES FOLDER "folder")

then the parent project node is no longer the CMakeListsNode, but the
"folder" Node, which doesn't represent the subdirectory where the target
has been defined.

Change-Id: Ida76be7f90ad3e2e58d480c8de4be2e0f7b352b4
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Cristian Adam
2024-08-30 18:45:47 +02:00
parent ee43d68ffd
commit 4790b09bee

View File

@@ -75,7 +75,7 @@ private:
void enableBuildSubprojectContextMenu(Node *node); void enableBuildSubprojectContextMenu(Node *node);
void enableBuildSubprojectMenu(); void enableBuildSubprojectMenu();
void runSubprojectOperation(const QString &clean, const QString &build); void runSubprojectOperation(const QString &clean, const QString &build);
CMakeListsNode* currentListsNodeForEditor(); const CMakeListsNode* currentListsNodeForEditor();
QAction *m_runCMakeAction; QAction *m_runCMakeAction;
QAction *m_clearCMakeCacheAction; QAction *m_clearCMakeCacheAction;
@@ -551,7 +551,7 @@ void CMakeManager::runSubprojectOperation(const QString &clean, const QString &b
} }
} }
CMakeListsNode *CMakeManager::currentListsNodeForEditor() const CMakeListsNode *CMakeManager::currentListsNodeForEditor()
{ {
Core::IDocument *currentDocument = Core::EditorManager::currentDocument(); Core::IDocument *currentDocument = Core::EditorManager::currentDocument();
if (!currentDocument) if (!currentDocument)
@@ -566,7 +566,26 @@ CMakeListsNode *CMakeManager::currentListsNodeForEditor()
if (!targetNode) if (!targetNode)
return nullptr; return nullptr;
return dynamic_cast<CMakeListsNode*>(targetNode->parentProjectNode()); auto bs = qobject_cast<CMakeBuildSystem *>(ProjectTree::currentBuildSystem());
if (!bs)
return nullptr;
auto cmakeBuildTarget
= Utils::findOrDefault(bs->buildTargets(), [&targetNode](const CMakeBuildTarget &cbt) {
return targetNode->buildKey() == cbt.title;
});
if (cmakeBuildTarget.backtrace.isEmpty())
return nullptr;
const FilePath targetDefinitionDir = cmakeBuildTarget.backtrace.last().path.parentDir();
auto projectNode = bs->project()->rootProjectNode()->findProjectNode(
[&targetDefinitionDir](const ProjectNode *node) {
if (auto cmakeListsNode = dynamic_cast<const CMakeListsNode *>(node))
return cmakeListsNode->path() == targetDefinitionDir;
return false;
});
return dynamic_cast<CMakeListsNode *>(projectNode);
} }
void CMakeManager::buildFile(Node *node) void CMakeManager::buildFile(Node *node)