Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 829
Tarantula Avatar asked Aug 31 '25 23:08

Tarantula


1 Answers

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.

like image 61
Martin Avatar answered Sep 04 '25 01:09

Martin