[dependencies] CMake & CTest : make test doesn't build tests


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:

ADD_TEST(ctest_build_test_code
         "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target test_code)
ADD_TEST(ctest_run_test_code test_code)
SET_TESTS_PROPERTIES(ctest_run_test_code
                     PROPERTIES DEPENDS ctest_build_test_code)
Question

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

ctest

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

Check details at: http://cmake.org/Wiki/CMake/Testing_With_CTest#Simple_Testing







Links