Skip to content

Commit 39c7a8d

Browse files
authored
Merge pull request #111 from eseiler/infra/cmake
[INFRA] cmake
2 parents efb4ab5 + d38b2a8 commit 39c7a8d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ add_subdirectory (src)
4545
option (${PROJECT_NAME}_TEST "Enable testing for ${PROJECT_NAME}." ${PROJECT_IS_TOP_LEVEL})
4646

4747
if (${PROJECT_NAME}_TEST)
48+
enable_testing () # Makes ctest work in root build directory.
4849
# Add the tests. This will include `test/CMakeLists.txt`.
4950
add_subdirectory (test EXCLUDE_FROM_ALL)
5051
endif ()

cmake/test/config.cmake

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,23 @@ endif ()
2424
# Add the check target that builds and runs tests.
2525
add_custom_target (check COMMAND ${CMAKE_CTEST_COMMAND} ${CMAKE_CTEST_ARGUMENTS})
2626
27+
get_directory_property (${PROJECT_NAME}_targets DIRECTORY "${${PROJECT_NAME}_SOURCE_DIR}/src" BUILDSYSTEM_TARGETS)
28+
foreach (target IN LISTS ${PROJECT_NAME}_targets)
29+
get_target_property (type ${target} TYPE)
30+
if (type STREQUAL "EXECUTABLE")
31+
list (APPEND ${PROJECT_NAME}_EXECUTABLE_LIST ${target})
32+
endif ()
33+
endforeach ()
34+
unset (${PROJECT_NAME}_targets)
35+
2736
macro (add_app_test test_filename)
28-
file (RELATIVE_PATH source_file "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_LIST_DIR}/${test_filename}")
37+
file (RELATIVE_PATH source_file "${${PROJECT_NAME}_SOURCE_DIR}" "${CMAKE_CURRENT_LIST_DIR}/${test_filename}")
2938
get_filename_component (target "${source_file}" NAME_WE)
3039
3140
add_executable (${target} ${test_filename})
3241
target_link_libraries (${target} ${PROJECT_NAME}::test)
3342
34-
add_dependencies (${target} ${PROJECT_NAME})
43+
add_dependencies (${target} ${${PROJECT_NAME}_EXECUTABLE_LIST})
3544
add_dependencies (check ${target})
3645
3746
add_test (NAME ${target} COMMAND ${target})

0 commit comments

Comments
 (0)