0

I have a CMakeLists.txt in my test folder and it looks like this:

include(CTest)
enable_testing()

if (CMAKE_VERSION VERSION_LESS 3.2)
    set(UPDATE_DISCONNECTED_IF_AVAILABLE "")
else()
    set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
endif()

include("../DownloadProject.cmake")
download_project(PROJ               catch
                 GIT_REPOSITORY     https://github.com/philsquared/Catch
                 GIT_TAG            v1.5.8
                 ${UPDATE_DISCONNECTED_IF_AVAILABLE}
)
include_directories(${catch_SOURCE_DIR}/single_include/)

include_directories(../src)
set(TEST_SOURCE_FILES <several cpp files>)
add_executable(unit_tests ${TEST_SOURCE_FILES})
target_link_libraries(unit_tests client)
add_test(NAME testclient COMMAND unit_tests)
add_custom_command(TARGET unit_tests POST_BUILD COMMAND /opt/local/bin/ctest --output-on-failure --schedule-random)

Every time I run my tests and they fail, make deletes the binary. If I comment the include(CTest), add_test and add_custom_command the binary is not deleted on failure.

How can I prevent this from happening?

ruipacheco
  • 15,025
  • 19
  • 82
  • 138
  • `How can I prevent this from happening?` - do not run tests as *a part of the building executable* (`add_custom_command` in *TARGET* mode). Definitely, there was similar question on SO recently. – Tsyvarev Nov 10 '16 at 19:30
  • Why is the executable deleted on failure? – ruipacheco Nov 11 '16 at 08:10

0 Answers0