Additional cmake testing

I have the following 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 CMakeLists.txt is inside the / test directory of my shared library project (my_library). The problem is that when I run “make”, it compiles this test, but I want to make this compilation optional, to compile only when I do the “make test”, and not when I do the “make”, I want make my tests optional.

+3
source share
1 answer

There is a variable BUICD_TESTING from CMake here that you can use.

Follow these steps:

 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)

, cmake-gui, ccmake cmake -DBUILD_TESTING = ON. , , , CMake.

+4

All Articles