I want my tests to be launched each time my project is successfully built. And if some tests are broken I want my build to be broken too. By default I need to run tests manu
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)