Skip to content

CTestTargets: Honor CMAKE_CTEST_ARGUMENTS in CTEST_TEST_TARGET_ALIAS

Extend the change from !4168 (merged) to cover the test target alias created by CTEST_TEST_TARGET_ALIAS too.

This would allow:

# Add project-specific options to the autogenerated test or RUN_TESTS target
set( CMAKE_CTEST_ARGUMENTS -T Test --no-compress-output )

# Alias the generator-specific test (Makefile) and RUN_TESTS (Visual Studio)
# targets into a common, cross-platform, runtests target.
set( CTEST_TEST_TARGET_ALIAS runtests )

include( CTest )

to use the arguments as part of make runtests.

Although CTEST_TEST_TARGET_ALIAS is undocumented, I believe this is more in line with the intended functionality of the CTEST_CTEST_ARGUMENTS variable, whose documentation states

Set this to a semicolon-separated list of command-line arguments to pass to ctest(1) when running tests through the test (or RUN_TESTS) target of the generated build system.

Without this, to get the CTest test target alias to use the global CTest arguments, I have to do

# Add project-specific options to the autogenerated test or RUN_TESTS target
set( CMAKE_CTEST_ARGUMENTS -T Test --no-compress-output )

# Alias the generator-specific test (Makefile) and RUN_TESTS (Visual Studio)
# targets into a common, cross-platform, runtests target.
# Also, add CMAKE_CTEST_ARGUMENTS, since CTestTargets.cmake doesn't.
# This must be set before the first call to include(CTest)
set( CMAKE_CTEST_COMMAND ${CMAKE_CTEST_COMMAND} ${CMAKE_CTEST_ARGUMENTS} )
set( CTEST_TEST_TARGET_ALIAS runtests )

include( CTest )

Fixes: #22239 (closed)
Topic-rename: ctest-target-alias-args

Edited by Brad King

Merge request reports