The format for ctest
arguments are specified in the CTest documentation as such:
ctest --build-and-test <path-to-source> <path-to-build>
--build-generator <generator>
[<options>...]
[--build-options <opts>...]
[--test-command <command> [<args>...]]
So, on Visual Studio for example, you could run test Test1
from your build folder (using ..
for the source directory, and .
for the binary directory):
ctest --build-and-test .. . --build-generator "Visual Studio 16 2019" --test-command Test1 --gtest_output=xml
As of CMake 3.17, you can now specify arguments to pass to CTest (and arguments for individual tests) in the CMake file where you define the test itself. The CMAKE_CTEST_ARGUMENTS
variable takes a semicolon-delimited list of arguments to pass to CTest. So, sticking with the above example, you could do something like this:
set(CMAKE_CTEST_ARGUMENTS "--build-and-test;${CMAKE_SOURCE_DIR};${CMAKE_BINARY_DIR};--build-generator;${CMAKE_GENERATOR};--test-command;Test1;--gtest_output=xml")