diff options
author | Ralf Habacker <ralf.habacker@freenet.de> | 2023-11-11 16:33:39 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-12-13 15:20:43 (GMT) |
commit | 1ec0372ed4b450e242fdb8f6a7d2862baa61b501 (patch) | |
tree | 2ae040a6f48ea682b62f72b56b593b72f3f286c5 /Source | |
parent | 478a5f4e044d253971e71a41ad6fc6b8aa4e1c07 (diff) | |
download | CMake-1ec0372ed4b450e242fdb8f6a7d2862baa61b501.zip CMake-1ec0372ed4b450e242fdb8f6a7d2862baa61b501.tar.gz CMake-1ec0372ed4b450e242fdb8f6a7d2862baa61b501.tar.bz2 |
add_test: Optionally use a launcher for tests running in-project targets
Add a `CMAKE_TEST_LAUNCHER` variable and corresponding `TEST_LAUNCHER`
target property.
Issue: #23672
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmTarget.cxx | 1 | ||||
-rw-r--r-- | Source/cmTestGenerator.cxx | 12 | ||||
-rw-r--r-- | Source/cmake.cxx | 10 |
3 files changed, 23 insertions, 0 deletions
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 169d808..832bf57 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -594,6 +594,7 @@ TargetProperty const StaticTargetProperties[] = { { "CROSSCOMPILING_EMULATOR"_s, IC::ExecutableTarget }, { "EXPORT_COMPILE_COMMANDS"_s, IC::CanCompileSources }, { "FOLDER"_s }, + { "TEST_LAUNCHER"_s, IC::ExecutableTarget }, // Xcode properties { "XCODE_GENERATE_SCHEME"_s, IC::NeedsXcode }, diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx index ca1226a..2831d0d 100644 --- a/Source/cmTestGenerator.cxx +++ b/Source/cmTestGenerator.cxx @@ -168,6 +168,18 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os, // Use the target file on disk. exe = target->GetFullPath(config); + // Prepend with the test launcher if specified. + cmValue launcher = target->GetProperty("TEST_LAUNCHER"); + if (cmNonempty(launcher)) { + cmList launcherWithArgs{ *launcher }; + std::string launcherExe(launcherWithArgs[0]); + cmSystemTools::ConvertToUnixSlashes(launcherExe); + os << cmOutputConverter::EscapeForCMake(launcherExe) << " "; + for (std::string const& arg : cmMakeRange(launcherWithArgs).advance(1)) { + os << cmOutputConverter::EscapeForCMake(arg) << " "; + } + } + // Prepend with the emulator when cross compiling if required. cmValue emulator = target->GetProperty("CROSSCOMPILING_EMULATOR"); if (cmNonempty(emulator)) { diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 002a020..bcba7f8 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2517,6 +2517,16 @@ int cmake::ActualConfigure() "Name of generator toolset.", cmStateEnums::INTERNAL); } + if (!this->State->GetInitializedCacheValue("CMAKE_TEST_LAUNCHER")) { + cm::optional<std::string> testLauncher = + cmSystemTools::GetEnvVar("CMAKE_TEST_LAUNCHER"); + if (testLauncher && !testLauncher->empty()) { + std::string message = "Test launcher to run tests executable."; + this->AddCacheEntry("CMAKE_TEST_LAUNCHER", *testLauncher, message, + cmStateEnums::STRING); + } + } + if (!this->State->GetInitializedCacheValue( "CMAKE_CROSSCOMPILING_EMULATOR")) { cm::optional<std::string> emulator = |