Run ctest from a different directory than the build directory used by cmake?

I would like to be able in a similar way, how can I run cmake as

cmake -H<src-directory> -B<bld-directory> cmake --build <bld_directory>

to run ctest as

ctest --build <bld_directory>

Obviously running ctest from a will will work, but it would be nice if I could just tell ctest where to look for its configuration file and where the test executables are located.

From the documentation, this is not very clear (or I may not have looked in the right place) if this is possible at all or not.

Would it be great if someone could shed light, if this is possible or not? Thanks a lot, Jiri

+6
source share
1 answer

I could not find a way to do this using the ctest parameters, but this is doable using the make test rule, which is associated with ctest.

In the Makefile generated by cmake in your build folder, you can find the rule:

 #Special rule for the target test test: @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running tests..." /usr/bin/ctest --force-new-ctest-process $(ARGS) .PHONY : test 

make provides the parameter you want to use with -C /path/to/build_directory/ , and you can add any ctest parameters with ARGS='your ctest options here'

For example, from any directory on your system you can write:

make test -C /path/to/build_folder ARGS='-R SpecificTestIWantToRun -VV'

or

cmake --build <bld_directory> --target test -- ARGS="<ctest_args>"

+2
source

All Articles