From dbb5a70f93bb19c7907abcdc3b26248b2959c208 Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Wed, 31 Mar 2021 17:58:09 +0200 Subject: [PATCH] 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 --- src/plugins/cmakeprojectmanager/cmakebuildstep.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp b/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp index 90b7bd7db06..e0c81b999e2 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp @@ -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));