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

和自甴很熟 提交于 2019-12-05 17:16: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


回答1:


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>"



来源:https://stackoverflow.com/questions/38644741/run-ctest-from-different-directory-than-build-directory-used-by-cmake

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!