I'm trying CTest in CMake in order to automatically run some of my tests using make test
target. The problem is CMake does not "understand" that the test I'm willing to run has to be built since it is part of the project.
So I'm looking for a way to explicitly specify this dependency.
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 to use DEPENDS exe1 exe2 exe3 ...
in the above line.