CMakePM: Fix crash when adding files to target having zero arguments

Qt Creator restores a backup of a project's structure when a CMake
configuration fails.

If a user removes all arguments from a function defining a target,
configure CMake and have the backup restored can lead to a state where
the backup target exists in the project structure.

Then when trying to add files to this target Qt Creator crashes.

Fixes: QTCREATORBUG-32745
Change-Id: I9db9b54ae883f6c5b40da623a9984e9c33195d30
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Cristian Adam
2025-04-07 11:01:21 +02:00
parent 9e2f47e2f7
commit 19a13932a4

View File

@@ -697,6 +697,11 @@ bool CMakeBuildSystem::addSrcFiles(Node *context, const FilePaths &filePaths, Fi
<< "could not be found at" << targetDefinitionLine; << "could not be found at" << targetDefinitionLine;
return false; return false;
} }
if (function->Arguments().size() == 0) {
qCCritical(cmakeBuildSystemLog) << "Function that defined the target" << targetName
<< "has zero arguments.";
return false;
}
const bool haveGlobbing = isGlobbingFunction(*cmakeListFile, *function); const bool haveGlobbing = isGlobbingFunction(*cmakeListFile, *function);
n->setVisibleAfterAddFileAction(!haveGlobbing); n->setVisibleAfterAddFileAction(!haveGlobbing);