Add tests only if they are built and can therefore be run

This commit is contained in:
TheAssassin
2019-09-06 03:13:05 +02:00
parent 2cc962a344
commit d26947985d
2 changed files with 16 additions and 2 deletions

View File

@@ -1,5 +1,19 @@
set(TEST_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data)
# common CMake macro for linuxdeploy, adding tests only if they are supposed to be built
# otherwise if you try to run CTest the tests aren't build and CTest can't find them
if(NOT COMMAND ld_add_test)
function(ld_add_test TARGET_NAME)
get_target_property(${TARGET_NAME}_EFA ${TARGET_NAME} EXCLUDE_FROM_ALL)
if(NOT ${${TARGET_NAME}_EXCLUDE_FROM_ALL})
message(STATUS "[${PROJECT_NAME}] Adding test ${TARGET_NAME}")
add_test(${TARGET_NAME} ${TARGET_NAME})
else()
message(STATUS "[${PROJECT_NAME}] Test ${TARGET_NAME} is excluded from ALL, not adding as test")
endif()
endfunction()
endif()
# first build dependencies for tests
add_subdirectory(simple_library)
add_subdirectory(simple_executable)

View File

@@ -12,7 +12,7 @@ target_compile_definitions(test_appdir PRIVATE
)
# register in CTest
add_test(test_appdir test_appdir)
ld_add_test(test_appdir)
# make sure library and executable are built before test_appdir
add_dependencies(test_appdir simple_library simple_executable)
@@ -33,7 +33,7 @@ target_compile_definitions(test_linuxdeploy PRIVATE
)
# register in CTest
add_test(test_linuxdeploy test_linuxdeploy)
ld_add_test(test_linuxdeploy)
# make sure library and executable are built before test_appdir
add_dependencies(test_linuxdeploy simple_library simple_executable)