vendredi 26 avril 2019

How to add command after all target is built

My goal is to run all tests with CTest as soon as all test binaries are built. Curretly I have the following CMakeList.txt:

add_library(my_lib SHARED mllib.c)

add_executable(test_suite1 test_suite1.c)
target_link_libraries(test_suite1 my_lib)

add_executable(test_suite2 test_suite2.c)
target_link_libraries(test_suite2 my_lib)

 #... many other suites

enable_testing()
add_test(NAME test_suite1 COMMAND test_suite1)
add_test(NAME test_suite2 COMMAND test_suite2)

Now I want to run the command ctest as soon as all test suite binaries are built. There is a form of add_custom_command:

add_custom_command(
     TARGET test_suite
     POST_BUILD 
     COMMAND ctest
)

The problem is that add_custom_command accepts only 1 target and that would require adding another custom command for each test added which duplicating and weird.

Maybe it is possible to create a fake target depending on all the target? Or some other way...?

Aucun commentaire:

Enregistrer un commentaire