Run ctest from different directory than build dire

2019-04-27 03:40发布

I would like to be able in a similar manner as I can run cmake like

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

to run ctest like

ctest --build <bld_directory>

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

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

It would great if somebody could shed some light on if this is possible or not ? Many thanks, Jiri

标签: cmake ctest
1条回答
Animai°情兽
2楼-- · 2019-04-27 03:53

I couldn't find the way to do it through ctest options, but it is doable using the rule make test which is linked to 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 option that you want with -C /path/to/build_directory/, and you can add any ctest options with ARGS='your ctest options here'

For example, from any directory in 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>"

查看更多
登录 后发表回答