From ac34413a35a15eec744de1e5970e07555b66a410 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 24 Apr 2015 11:23:50 -0700 Subject: [PATCH] cmake: don't always build tests Only build the tests when running them. The downside of the way this is implemented is that build errors for the tests actually show up as test errors and are only seen in the test log - but this seemed worth not having every build include the tests. Signed-off-by: Dirk Hohndel --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 39d09a5b1..e4c5cc4a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -361,15 +361,17 @@ endif() # QTest based tests macro(TEST NAME FILE) - add_executable(${NAME} tests/${FILE} ${SUBSURFACE_RESOURCES}) + add_executable(${NAME} EXCLUDE_FROM_ALL tests/${FILE} ${SUBSURFACE_RESOURCES}) target_link_libraries(${NAME} subsurface_corelib ${QT_TEST_LIBRARIES} ${SUBSURFACE_LINK_LIBRARIES}) - add_test(NAME ${NAME} COMMAND ${NAME}) + add_test(NAME ${NAME}_build COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${NAME}) + add_test(NAME ${NAME}_run COMMAND ${NAME}) + set_tests_properties(${NAME}_run PROPERTIES DEPENDS ${NAME}_build) endmacro() -enable_testing() add_definitions(-DSUBSURFACE_SOURCE="${CMAKE_SOURCE_DIR}") add_definitions(-g) if(NOT NO_TESTS) + enable_testing() TEST(TestUnitConversion testunitconversion.cpp) TEST(TestProfile testprofile.cpp) TEST(TestGpsCoords testgpscoords.cpp)