ctest: honor all -D definitions in command-line dashboard client mode

Commit 63b6e7d785 (ctest: allow dashboard clients to specify presets via
variables, 2026-05-26) added support for the CTEST_PRESET family of
variables that provide users with an additional method of defining what
preset to use (if any) for dashboard client steps.

However, these variables were not being honored properly when defined
on the command-line with ctest -D. This was caused by the fact that these
variables do not have a corresponding CTest configuration setting.
Instead, they are read directly using cmMakefile::GetDefinition().

To fix this, we now inject all variables defined with ctest -D into the
cmMakefile used by CTest in ProcessSteps(). This more closely matches the
existing behavior of cmCTestScriptHandler (ctest -S mode).

In addition to fixing the newly added CTEST_PRESET variables, this also
allow users to properly define CTEST_BUILD_CONFIGURATION and
CTEST_CONFIGURATION_TYPE from the command-line.
This commit is contained in:
Zack Galbreath committed 2026-05-29 11:40:47 -04:00
1 parent cd807309bf
commit ba768963e5
3 files changed
+38

No files matched your search

+11
View File
@@ -735,6 +735,17 @@ int cmCTest::ProcessSteps()
cmMakefile& mf = *script.GetMakefile();
this->ReadCustomConfigurationFileTree(this->Impl->BinaryDir, &mf);
this->SetCMakeVariables(mf);
// Inject variables passed via -D so that ctest_* commands can read them
// using mf.GetDefinition(). This matches what cmCTestScriptHandler does
// before running a -S script. SetCMakeVariables() (above) only defines
// variables that correspond to a CTest Configuration key. Other variables
// such as CTEST_PRESET are read directly from the makefile and would
// otherwise be invisible here.
for (auto const& def : this->GetDefinitions()) {
mf.AddDefinition(def.first, def.second);
}
// CTEST_TIME_LIMIT may come from CTestCustom.cmake (already in the makefile)
// or from the config map (just populated by SetCMakeVariables above).
this->SetTimeLimit(mf.GetDefinition("CTEST_TIME_LIMIT"));
@@ -45,6 +45,32 @@ endforeach()
run_ctest(TestPresetGenericVar)
unset(CASE_TEST_PREFIX_CODE)
# Verify that CTEST_TEST_PRESET passed via -D on the command line reaches
# ctest_test() when ctest is run with -M/-T.
set(case_source_dir "${RunCMake_BINARY_DIR}/TestPresetCLIVar")
set(case_binary_dir "${RunCMake_BINARY_DIR}/TestPresetCLIVar-build")
configure_file(
"${RunCMake_SOURCE_DIR}/CMakePresets.json.in"
"${case_source_dir}/CMakePresets.json"
@ONLY)
file(REMOVE_RECURSE "${case_binary_dir}")
file(MAKE_DIRECTORY "${case_binary_dir}")
file(WRITE "${case_binary_dir}/DartConfiguration.tcl"
"BuildDirectory: ${case_binary_dir}\nSourceDirectory: ${case_source_dir}\n")
file(WRITE "${case_binary_dir}/CTestTestfile.cmake"
"add_test(test1 \"${CMAKE_COMMAND}\" -E true)\n"
"add_test(test2 \"${CMAKE_COMMAND}\" -E true)\n"
"add_test(test3 \"${CMAKE_COMMAND}\" -E true)\n")
set(RunCMake_TEST_BINARY_DIR "${case_binary_dir}")
set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_command(TestPresetCLIVar
${CMAKE_CTEST_COMMAND}
-C Debug
-M Experimental
-D "CTEST_TEST_PRESET=my-include-preset"
-T Test
-V)
set(custom_presets_file
"${RunCMake_BINARY_DIR}/TestPresetFileInclude/custom-presets.json")
configure_file(
@@ -0,0 +1 @@
1/1 Test #[0-9]+: test1 \.+ Passed +[0-9\.]+ sec