Skip to content

Commit

Permalink
Merge pull request #6 from MortenSchou/5-discover_tests-only-discover…
Browse files Browse the repository at this point in the history
…s-single-target

discover_tests now accepts multiple targets
  • Loading branch information
MortenSchou authored Feb 14, 2024
2 parents 76f3d82 + 6408e0a commit 710d38d
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions cmake/mtest.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# discover_tests(<target>) adds a post-build command to the given <target> that calls CMake in script mode to generate the CTest script.
# discover_tests(<target>...) adds a post-build command to each <target> that calls CMake in script mode to generate the CTest script.

function(discover_tests TARGET)
set(ctest_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_tests.cmake")
add_custom_command(
TARGET ${TARGET} POST_BUILD
BYPRODUCTS "${ctest_tests_file}"
COMMAND "${CMAKE_COMMAND}"
-D "TEST_TARGET=${TARGET}"
-D "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>"
-D "CTEST_FILE=${ctest_tests_file}"
-P "${_MTEST_DISCOVER_TEST_SCRIPT}"
VERBATIM
)
set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES "${ctest_tests_file}")
function(discover_tests)
foreach (TARGET IN LISTS ARGN)
set(ctest_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_tests.cmake")
add_custom_command(
TARGET ${TARGET} POST_BUILD
BYPRODUCTS "${ctest_tests_file}"
COMMAND "${CMAKE_COMMAND}"
-D "TEST_TARGET=${TARGET}"
-D "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>"
-D "CTEST_FILE=${ctest_tests_file}"
-P "${_MTEST_DISCOVER_TEST_SCRIPT}"
VERBATIM
)
set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES "${ctest_tests_file}")
endforeach()
endfunction()

# Specify location of the mtest_add_tests.cmake script relative to current location (not relative to where discover_tests() is called).
Expand Down

0 comments on commit 710d38d

Please sign in to comment.