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 … Read more

CMake & CTest : make test doesn’t build tests

It is arguably a bug in CMake (previously tracked here) that this doesn’t work out of the box. A workaround is to do the following: add_test(TestName ExeName) add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS ExeName) Then you can run make check and it will compile and run the test. If you have several tests, then you would have … Read more

tech