|
1 | 1 | # ——— Helper function to add & register tests —————————————————————————
|
2 | 2 | function(ppc_add_test test_name test_src USE_FLAG)
|
3 |
| - if(${USE_FLAG}) |
4 |
| - add_executable(${test_name} "${PROJECT_SOURCE_DIR}/${test_src}") |
5 |
| - enable_testing() |
6 |
| - add_test(NAME ${test_name} COMMAND ${test_name}) |
7 |
| - install(TARGETS ${test_name} RUNTIME DESTINATION bin) |
8 |
| - endif() |
| 3 | + if(${USE_FLAG}) |
| 4 | + add_executable(${test_name} "${PROJECT_SOURCE_DIR}/${test_src}") |
| 5 | + enable_testing() |
| 6 | + add_test(NAME ${test_name} COMMAND ${test_name}) |
| 7 | + install(TARGETS ${test_name} RUNTIME DESTINATION bin) |
| 8 | + endif() |
9 | 9 | endfunction()
|
10 | 10 |
|
11 | 11 | # Function to configure tests
|
12 | 12 | function(add_tests test_flag exec_target subdir)
|
13 |
| - if(${test_flag}) |
14 |
| - # Gather all source files under tests/<subdir> |
15 |
| - file(GLOB_RECURSE src_files |
16 |
| - "${TEST_DIR}/${subdir}/*.cpp" |
17 |
| - "${TEST_DIR}/${subdir}/*.cxx" |
18 |
| - "${TEST_DIR}/${subdir}/*.cc" |
19 |
| - ) |
20 |
| - target_sources(${exec_target} PRIVATE ${src_files}) |
21 |
| - list(APPEND TEST_EXECUTABLES ${exec_target}) |
22 |
| - set(TEST_EXECUTABLES "${TEST_EXECUTABLES}" PARENT_SCOPE) |
23 |
| - endif() |
| 13 | + if(${test_flag}) |
| 14 | + # Gather all source files under tests/<subdir> |
| 15 | + file(GLOB_RECURSE src_files "${TEST_DIR}/${subdir}/*.cpp" |
| 16 | + "${TEST_DIR}/${subdir}/*.cxx" "${TEST_DIR}/${subdir}/*.cc") |
| 17 | + target_sources(${exec_target} PRIVATE ${src_files}) |
| 18 | + list(APPEND TEST_EXECUTABLES ${exec_target}) |
| 19 | + set(TEST_EXECUTABLES |
| 20 | + "${TEST_EXECUTABLES}" |
| 21 | + PARENT_SCOPE) |
| 22 | + endif() |
24 | 23 | endfunction()
|
25 | 24 |
|
26 | 25 | # ============================================================================
|
27 |
| -# Function: setup_implementation |
28 |
| -# - NAME: implementation sub‐directory name (e.g. “mpi”) |
29 |
| -# - PROJ_NAME: project base name |
30 |
| -# - BASE_DIR: root source directory |
31 |
| -# - TESTS: list of test executables to link against |
| 26 | +# Function: setup_implementation - NAME: implementation sub‐directory name |
| 27 | +# (e.g. “mpi”) - PROJ_NAME: project base name - BASE_DIR: root source |
| 28 | +# directory - TESTS: list of test executables to link against |
32 | 29 | # ============================================================================
|
33 | 30 | function(setup_implementation)
|
34 |
| - # parse named args: NAME, PROJ_NAME, BASE_DIR; multi‐value: TESTS |
35 |
| - cmake_parse_arguments( |
36 |
| - SETUP |
37 |
| - "" # no plain options |
38 |
| - "NAME;PROJ_NAME;BASE_DIR" |
39 |
| - "TESTS" |
40 |
| - ${ARGN} |
41 |
| - ) |
| 31 | + # parse named args: NAME, PROJ_NAME, BASE_DIR; multi‐value: TESTS |
| 32 | + cmake_parse_arguments(SETUP "" # no plain options |
| 33 | + "NAME;PROJ_NAME;BASE_DIR" "TESTS" ${ARGN}) |
42 | 34 |
|
43 |
| - # skip if impl dir doesn't exist |
44 |
| - set(IMP_DIR "${SETUP_BASE_DIR}/${SETUP_NAME}") |
45 |
| - if(NOT EXISTS "${IMP_DIR}") |
46 |
| - return() |
47 |
| - endif() |
48 |
| - message(STATUS " -- ${SETUP_NAME}") |
| 35 | + # skip if impl dir doesn't exist |
| 36 | + set(IMP_DIR "${SETUP_BASE_DIR}/${SETUP_NAME}") |
| 37 | + if(NOT EXISTS "${IMP_DIR}") |
| 38 | + return() |
| 39 | + endif() |
| 40 | + message(STATUS " -- ${SETUP_NAME}") |
49 | 41 |
|
50 |
| - # collect sources |
51 |
| - file(GLOB_RECURSE CPP_SOURCES "${IMP_DIR}/src/*.cpp") |
52 |
| - file(GLOB_RECURSE ALL_SOURCES |
53 |
| - "${IMP_DIR}/include/*.h" |
54 |
| - "${IMP_DIR}/include/*.hpp" |
55 |
| - "${IMP_DIR}/src/*.cpp" |
56 |
| - ) |
| 42 | + # collect sources |
| 43 | + file(GLOB_RECURSE CPP_SOURCES "${IMP_DIR}/src/*.cpp") |
| 44 | + file(GLOB_RECURSE ALL_SOURCES "${IMP_DIR}/include/*.h" |
| 45 | + "${IMP_DIR}/include/*.hpp" "${IMP_DIR}/src/*.cpp") |
57 | 46 |
|
58 |
| - # create library (STATIC if .cpp exist, otherwise INTERFACE) |
59 |
| - set(LIB_NAME "${SETUP_PROJ_NAME}_${SETUP_NAME}") |
60 |
| - if(CPP_SOURCES) |
61 |
| - add_library(${LIB_NAME} STATIC ${ALL_SOURCES}) |
62 |
| - else() |
63 |
| - add_library(${LIB_NAME} INTERFACE ${ALL_SOURCES}) |
64 |
| - endif() |
| 47 | + # create library (STATIC if .cpp exist, otherwise INTERFACE) |
| 48 | + set(LIB_NAME "${SETUP_PROJ_NAME}_${SETUP_NAME}") |
| 49 | + if(CPP_SOURCES) |
| 50 | + add_library(${LIB_NAME} STATIC ${ALL_SOURCES}) |
| 51 | + else() |
| 52 | + add_library(${LIB_NAME} INTERFACE ${ALL_SOURCES}) |
| 53 | + endif() |
65 | 54 |
|
66 |
| - # link core module |
67 |
| - target_link_libraries(${LIB_NAME} PUBLIC core_module_lib) |
| 55 | + # link core module |
| 56 | + target_link_libraries(${LIB_NAME} PUBLIC core_module_lib) |
68 | 57 |
|
69 |
| - # and link into each enabled test executable |
70 |
| - foreach(test_exec ${SETUP_TESTS}) |
71 |
| - target_link_libraries(${test_exec} PUBLIC ${LIB_NAME}) |
72 |
| - endforeach() |
| 58 | + # and link into each enabled test executable |
| 59 | + foreach(test_exec ${SETUP_TESTS}) |
| 60 | + target_link_libraries(${test_exec} PUBLIC ${LIB_NAME}) |
| 61 | + endforeach() |
73 | 62 | endfunction()
|
74 | 63 |
|
75 | 64 | # Function to configure each subproject
|
76 | 65 | function(ppc_configure_subproject SUBDIR)
|
77 |
| - # Module-specific compile-time definitions |
78 |
| - add_compile_definitions( |
79 |
| - PPC_SETTINGS_${SUBDIR}="${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}/settings.json" |
80 |
| - PPC_ID_${SUBDIR}="${SUBDIR}" |
81 |
| - ) |
| 66 | + # Module-specific compile-time definitions |
| 67 | + add_compile_definitions( |
| 68 | + PPC_SETTINGS_${SUBDIR}="${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}/settings.json" |
| 69 | + PPC_ID_${SUBDIR}="${SUBDIR}") |
82 | 70 |
|
83 |
| - # Switch project context to the subproject |
84 |
| - project(${SUBDIR}) |
| 71 | + # Switch project context to the subproject |
| 72 | + project(${SUBDIR}) |
85 | 73 |
|
86 |
| - # Directory with tests and list of test executables (populated by setup_implementation) |
87 |
| - set(TEST_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}/tests") |
88 |
| - set(TEST_EXECUTABLES "") |
| 74 | + # Directory with tests and list of test executables (populated by |
| 75 | + # setup_implementation) |
| 76 | + set(TEST_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}/tests") |
| 77 | + set(TEST_EXECUTABLES "") |
89 | 78 |
|
90 |
| - # Register functional and performance test runners |
91 |
| - add_tests(USE_FUNC_TESTS ${FUNC_TEST_EXEC} functional) |
92 |
| - add_tests(USE_PERF_TESTS ${PERF_TEST_EXEC} performance) |
| 79 | + # Register functional and performance test runners |
| 80 | + add_tests(USE_FUNC_TESTS ${FUNC_TEST_EXEC} functional) |
| 81 | + add_tests(USE_PERF_TESTS ${PERF_TEST_EXEC} performance) |
93 | 82 |
|
94 |
| - message(STATUS "${SUBDIR}") |
| 83 | + message(STATUS "${SUBDIR}") |
95 | 84 |
|
96 |
| - # List of implementations to configure |
97 |
| - foreach(IMPL IN LISTS IMPLEMENTATIONS) |
98 |
| - setup_implementation( |
99 |
| - NAME ${IMPL} |
100 |
| - PROJ_NAME ${SUBDIR} |
101 |
| - TESTS "${TEST_EXECUTABLES}" |
102 |
| - BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}" |
103 |
| - ) |
104 |
| - endforeach() |
| 85 | + # List of implementations to configure |
| 86 | + foreach(IMPL IN LISTS IMPLEMENTATIONS) |
| 87 | + setup_implementation( |
| 88 | + NAME |
| 89 | + ${IMPL} |
| 90 | + PROJ_NAME |
| 91 | + ${SUBDIR} |
| 92 | + TESTS |
| 93 | + "${TEST_EXECUTABLES}" |
| 94 | + BASE_DIR |
| 95 | + "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}") |
| 96 | + endforeach() |
105 | 97 | endfunction()
|
0 commit comments