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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-04-24 11:23:50 -07:00
parent 38ba7177c7
commit ac34413a35

View file

@ -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)