File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ add_subdirectory (src)
4545option (${PROJECT_NAME} _TEST "Enable testing for ${PROJECT_NAME} ." ${PROJECT_IS_TOP_LEVEL} )
4646
4747if (${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 )
5051endif ()
Original file line number Diff line number Diff line change @@ -24,14 +24,23 @@ endif ()
2424# Add the check target that builds and runs tests.
2525add_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+
2736macro (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} )
You can’t perform that action at this time.
0 commit comments