How to run ctest after building my project with cmake

This form of add_custom_command will only execute if another CMake target has a dependency on “tests.txt”. I assume that no other target has “tests.txt” as an input file, hence the custom command never runs.

I think you could use the second form of add_custom_command to achieve your goal; something like:

add_custom_command(TARGET MainTest
                   POST_BUILD
                   COMMAND ctest -C $<CONFIGURATION> --output-on-failure)

Leave a Comment

tech