1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-23 18:08:31 +08:00

Add CMAKE_CTEST_ARGUMENTS variable to pass command-line arguments to ctest

Fixes: #20172
This commit is contained in:
Robert Goulet
2019-12-28 00:20:05 -05:00
committed by Brad King
parent 93526fd913
commit 4153d8445b
7 changed files with 39 additions and 0 deletions

View File

@@ -369,6 +369,7 @@ Variables that Control the Build
/variable/CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY /variable/CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY
/variable/CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG /variable/CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG
/variable/CMAKE_CONFIG_POSTFIX /variable/CMAKE_CONFIG_POSTFIX
/variable/CMAKE_CTEST_ARGUMENTS
/variable/CMAKE_CUDA_SEPARABLE_COMPILATION /variable/CMAKE_CUDA_SEPARABLE_COMPILATION
/variable/CMAKE_CUDA_RESOLVE_DEVICE_SYMBOLS /variable/CMAKE_CUDA_RESOLVE_DEVICE_SYMBOLS
/variable/CMAKE_DEBUG_POSTFIX /variable/CMAKE_DEBUG_POSTFIX

View File

@@ -0,0 +1,6 @@
cmake-ctest-arguments
---------------------
* A :variable:`CMAKE_CTEST_ARGUMENTS` variable was added to specify a list
of command-line arguments passed to CTest when running through the
``test`` (or ``RUN_TESTS``) target of the generated build system.

View File

@@ -0,0 +1,6 @@
CMAKE_CTEST_ARGUMENTS
---------------------
Set this to a :ref:`semicolon-separated list <CMake Language Lists>` of
command-line arguments to pass to :manual:`ctest(1)` when running tests
through the ``test`` (or ``RUN_TESTS``) target of the generated build system.

View File

@@ -2458,6 +2458,13 @@ void cmGlobalGenerator::AddGlobalTarget_Test(
cmCustomCommandLine singleLine; cmCustomCommandLine singleLine;
singleLine.push_back(cmSystemTools::GetCTestCommand()); singleLine.push_back(cmSystemTools::GetCTestCommand());
singleLine.push_back("--force-new-ctest-process"); singleLine.push_back("--force-new-ctest-process");
if (auto testArgs = mf->GetDefinition("CMAKE_CTEST_ARGUMENTS")) {
std::vector<std::string> args;
cmExpandList(testArgs, args);
for (auto const& arg : args) {
singleLine.push_back(arg);
}
}
if (cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.') { if (cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.') {
singleLine.push_back("-C"); singleLine.push_back("-C");
singleLine.push_back(cmakeCfgIntDir); singleLine.push_back(cmakeCfgIntDir);

View File

@@ -0,0 +1,4 @@
set(log "${RunCMake_TEST_BINARY_DIR}/output-log.txt")
if(NOT EXISTS "${log}")
set(RunCMake_TEST_FAILED "The expected output log file is missing:\n ${log}")
endif()

View File

@@ -0,0 +1,2 @@
include(CTest)
add_test(NAME CMakeCTestArguments COMMAND ${CMAKE_COMMAND} -E echo CMakeCTestArguments)

View File

@@ -5,3 +5,16 @@ run_cmake(BeforeProject)
unset(RunCMake_TEST_OPTIONS) unset(RunCMake_TEST_OPTIONS)
run_cmake(NotOn) run_cmake(NotOn)
function(run_CMakeCTestArguments)
run_cmake_with_options(CMakeCTestArguments "-DCMAKE_CTEST_ARGUMENTS=--quiet\\;--output-log\\;output-log.txt")
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CMakeCTestArguments-build)
if(RunCMake_GENERATOR MATCHES "Make|Ninja")
set(test "test")
else()
set(test "RUN_TESTS")
endif()
run_cmake_command(CMakeCTestArguments-test ${CMAKE_COMMAND} --build . --config Debug --target "${test}")
endfunction()
run_CMakeCTestArguments()