Tarantula
Tarantula

Reputation: 19862

cmake optional testing

I have the follow situation:

add_executable(TestOne TestOne.cpp)
target_link_libraries(TestOne my_library)

add_test(TestOne TestOne)
set_tests_properties (TestOne
  PROPERTIES PASS_REGULAR_EXPRESSION "Passed")

This block of cmake code from the CMakeLists.txt is inside the /test directory of my shared library (my_library) project. The problem is that when I run "make", it compiles this test, but I want to make that compilation optional, in order to compile only when I do "make test" and not when I do "make", I want to make my tests optional.

Upvotes: 4

Views: 2132

Answers (1)

Martin
Martin

Reputation: 1381

There's a CMake variable BUILD_TESTING, which you can use.

Do the following:

 IF (BUILD_TESTING)
    add_executable(TestOne TestOne.cpp)
    target_link_libraries(TestOne my_library)

    add_test(TestOne TestOne)
    set_tests_properties (TestOne
                          PROPERTIES PASS_REGULAR_EXPRESSION "Passed")
 ENDIF(BUILD_TESTING)

You can change the variable by running cmake-gui, ccmake or cmake -DBUILD_TESTING=ON. As far as I know there is no possibility to do what you want without rerunning CMake.

Upvotes: 5

Related Questions