File 0002-CMakePM-Only-set-CTest-launchers-for-test-targets.patch of Package qt-creator

From 8b3f147baa25df8276b221b2cd431cb04f8fe3bb Mon Sep 17 00:00:00 2001
From: Ralf Habacker <ralf.habacker@freenet.de>
Date: Tue, 23 Sep 2025 14:46:55 +0200
Subject: [PATCH 2/2] CMakePM: Only set CTest launchers for test targets

CMake sets the TEST_LAUNCHER property of targets from the global
CMAKE_TEST_LAUNCHER variable. This is applied for non-test targets.

This commit clears such launchers from the non-test targets.

Fixes: QTCREATORBUG-32550
Change-Id: I997b377a600e2c41227162562d0d990d160194a5
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
---
 .../cmakeprojectmanager/cmakebuildsystem.cpp  | 33 +++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp
index 644fb2b571f..8e735c08912 100644
--- a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp
@@ -2283,6 +2283,31 @@ static FilePaths librarySearchPaths(const CMakeBuildSystem *bs, const QString &b
     return cmakeBuildTarget.libraryDirectories;
 }
 
+static bool isTestTarget(const QString &targetName, const FilePath &buildDir)
+{
+    // The CTest file is always named CTestTestfile.cmake and lives in the build dir
+    const FilePath testFile = buildDir.pathAppended("CTestTestfile.cmake");
+    if (!testFile.exists())
+        return false;
+
+    // Parse the file
+    std::optional<cmListFile> cmakeListFile = getUncachedCMakeListFile(testFile);
+    if (!cmakeListFile)
+        return false;
+
+    // Find an add_test() call whose first argument equals the target name
+    for (const cmListFileFunction &func : cmakeListFile->Functions) {
+        if (func.LowerCaseName() != "add_test")
+            continue;
+        if (func.Arguments().size() < 1)
+            continue;
+        const auto &arg = func.Arguments().at(0);
+        if (QString::fromStdString(arg.Value) == targetName)
+            return true;
+    }
+    return false;
+}
+
 const QList<BuildTargetInfo> CMakeBuildSystem::appTargets() const
 {
     const CMakeConfig &cm = configurationFromCMake();
@@ -2316,6 +2341,14 @@ const QList<BuildTargetInfo> CMakeBuildSystem::appTargets() const
             bti.usesTerminal = !ct.linksToQtGui;
             bti.isQtcRunnable = ct.qtcRunnable;
 
+            // Remove the test launchers if the target is not a test
+            if (bti.launchers.size() > 0
+                && !isTestTarget(ct.title, bti.targetFilePath.parentDir())) {
+                bti.launchers = Utils::filtered(bti.launchers, [](const Launcher &l) {
+                    return !l.id.startsWith("test");
+                });
+            }
+
             // Workaround for QTCREATORBUG-19354:
             bti.runEnvModifier = [this, buildKey](Environment &env, bool enabled) {
                 if (enabled)
-- 
2.51.0

openSUSE Build Service is sponsored by