I have a regression test suite consisting of multiple custom targets created with add_custom_target()
.
Moreover there is a "convenience" target regressions
to run all regressions. It simply contains all single regression targets as dependency.
This is reflected in the following MCVE:
cmake_minimum_required(VERSION 3.17)
project (Regressions)
add_custom_target(reg_1 COMMAND ${CMAKE_COMMAND} -E echo 'First regression')
add_custom_target(reg_2 COMMAND ${CMAKE_COMMAND} -E echo 'Second regression')
# ...
add_custom_target(regressions DEPENDS reg_1 reg_2)
Now I can run cmake --build . --target regressions
from the build directory and reg_1
and reg_2
are run as part of regressions
.
My problem is that if one of the regressions fail, the remaining are not executed. But of course I want to always run all regressions and only have a summary of the failed ones. How can I achieve this behavior, i.e. always execute all subtargets, no matter whether some of them fail?
I assume that the natural way to do this is to use add_test()
(after all regressions runs are tests), but I failed because the custom targets are no executables and AFAIK you cannot use custom CMake targets with add_test()
.
Please feel free to recommend an alternative to my current approach. If I could handle everything using ctest
that would be preferred anyway.