|
| 1 | +# Add an executable and its related test. |
| 2 | +# |
| 3 | +# The executable is always linked to 'kokkostools' and 'test_common'. |
| 4 | +# |
| 5 | +# The test environment always contains 'KOKKOS_TOOLS_LIBS' that is set as the path |
| 6 | +# to the target file of 'CONNECTOR_LIB'. |
| 7 | +# |
| 8 | +# Arguments: |
| 9 | +# TARGET_NAME : name of the test |
| 10 | +# SOURCE_FILE : source file, defaults to <TARGET_NAME>.cpp |
| 11 | +# CONNECTOR_LIB : connector library target name under test |
| 12 | +function(kp_add_executable_and_test) |
| 13 | + |
| 14 | + cmake_parse_arguments(kaeat_args "" "TARGET_NAME;SOURCE_FILE;CONNECTOR_LIB" "" ${ARGN}) |
| 15 | + |
| 16 | + if(NOT DEFINED kaeat_args_TARGET_NAME OR NOT DEFINED kaeat_args_SOURCE_FILE OR NOT DEFINED kaeat_args_CONNECTOR_LIB) |
| 17 | + message(FATAL_ERROR "Wrong usage.") |
| 18 | + endif() |
| 19 | + |
| 20 | + add_executable(${kaeat_args_TARGET_NAME}) |
| 21 | + |
| 22 | + target_sources( |
| 23 | + ${kaeat_args_TARGET_NAME} |
| 24 | + PRIVATE |
| 25 | + ${kaeat_args_SOURCE_FILE} |
| 26 | + ) |
| 27 | + target_link_libraries( |
| 28 | + ${kaeat_args_TARGET_NAME} |
| 29 | + PRIVATE |
| 30 | + kokkostools test_common |
| 31 | + ) |
| 32 | + |
| 33 | + add_test( |
| 34 | + NAME ${kaeat_args_TARGET_NAME} |
| 35 | + COMMAND $<TARGET_FILE:${kaeat_args_TARGET_NAME}> |
| 36 | + ) |
| 37 | + set_property( |
| 38 | + TEST ${kaeat_args_TARGET_NAME} |
| 39 | + APPEND |
| 40 | + PROPERTY |
| 41 | + ENVIRONMENT "KOKKOS_TOOLS_LIBS=$<TARGET_FILE:${kaeat_args_CONNECTOR_LIB}>" |
| 42 | + ) |
| 43 | + |
| 44 | +endfunction(kp_add_executable_and_test) |
| 45 | + |
| 46 | +# Create a test library that contains the required Kokkos and Google Test |
| 47 | +# initialization sequence. |
| 48 | +add_library(test_common OBJECT) |
| 49 | +target_sources( |
| 50 | + test_common |
| 51 | + PRIVATE |
| 52 | + UnitTestMain.cpp |
| 53 | +) |
| 54 | +target_link_libraries(test_common PUBLIC GTest::gtest GTest::gmock Kokkos::kokkos) |
| 55 | + |
1 | 56 | add_subdirectory(space-time-stack) |
0 commit comments