CMakePM: Remove non existing targets from cmake --target list

Testing with a hello project like this:

1. Go to settings select "hello" target, deselect "all"
2. Go to CMakeLists.txt and rename the hello target to hello2
3. Run CMake <-- important, this will rescan the file-api target structure
4. Build

Step 3 will notice that hello target is missing and remove it, since
no targets are there "all" will be inserted and step 4 will work.

Fixes: QTCREATORBUG-25477
Change-Id: I6a4461341550931006558e5fdecb5a4323afaf35
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Cristian Adam
2021-03-31 17:58:09 +02:00
parent 5d5ff57495
commit dbb5a70f93

View File

@@ -536,6 +536,14 @@ void CMakeBuildStep::recreateBuildTargetsModel()
addItem(QString(), true);
// Remove the targets that do not exist in the build system
// This can result when selected targets get renamed
if (!targetList.empty()) {
Utils::erase(m_buildTargets, [targetList](const QString &bt) { return !targetList.contains(bt); });
if (m_buildTargets.empty())
m_buildTargets.push_back(m_allTarget);
}
for (const QString &buildTarget : qAsConst(targetList))
addItem(buildTarget, specialTargets(usesAllCapsTargets).contains(buildTarget));