dependencies unit check - CMake & CTest : make test doesn't build tests

3 Answers

There is actually a way to use make test. You need to define the build of the test executable as one of the tests and then add dependencies between the tests. That is:

         "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target test_code)
ADD_TEST(ctest_run_test_code test_code)
                     PROPERTIES DEPENDS ctest_build_test_code)
resources remove timeout

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.

All above answers are perfect. But actually CMake use CTest as its testing tools, so the standard method (I think it is) to do the mission is:

enable_testing ()
add_test (TestName TestCommand)
add_test (TestName2 AnotherTestCommand)

Then run cmake and make to build the targets. After that, you can either run make test, or just run


you will get the result. This is tested under CMake 2.8 .

Check details at: