feature: allow passing command-line parameters to ctest executed from running cmake tests target
When running cmake tests target (such as RUN_TESTS
in Visual Studio), it is not possible to pass additional command-line parameters to ctest. Because of this, we cannot specify ctest command-line parameters when generating the solution with cmake.
For example, if we need the option --output-on-failure
to always be passed when running the cmake tests target, right now it is only possible if CTEST_OUTPUT_ON_FAILURE
environment variable is defined when running cmake to generate the solution. This is not ideal because it requires additional setup or command-line options when running cmake, whereas we need the generated solution to have proper default when not passing any additional options to cmake.
Besides, if new command-line options are added to ctest, more environment variables would need to be exposed in cmake to allow setting those values, which is not ideal.
Instead, if we could directly specify ctest command-line parameters to be set as a traditional cmake list variable, we can set those in the cmake file so that when the solution is generated, it will have proper ctest command-line option set by default, for the current project.
Example, if we needed tests to always be verbose:
enable_testing()
list(APPEND CMAKE_CTEST_ARGUMENTS "--verbose")
Note that this only adds ctest command-line options when running the cmake tests target, and not when manually running ctest from the command-line.