|
1 | | -# Build program. |
2 | | -add_executable(strings strings.c) |
3 | | -add_executable(gksort gksort.c) |
4 | | -add_executable(fis fis.c) |
5 | | -add_executable(gkrw rw.c) |
6 | | -add_executable(gkgraph gkgraph.c) |
7 | | -add_executable(csrcnv csrcnv.c) |
8 | | -add_executable(grKx grKx.c) |
9 | | -add_executable(m2mnbrs m2mnbrs.c) |
10 | | -add_executable(cmpnbrs cmpnbrs.c) |
11 | | -add_executable(splatt2svd splatt2svd.c) |
12 | | -add_executable(gkuniq gkuniq.c) |
13 | | - |
14 | | -foreach(prog strings gksort fis gkrw gkgraph csrcnv grKx m2mnbrs cmpnbrs splatt2svd gkuniq) |
15 | | - target_link_libraries(${prog} GKlib) |
16 | | -endforeach(prog) |
17 | | - |
18 | | -# Install a subset of them |
19 | | -install(TARGETS csrcnv RUNTIME DESTINATION bin) |
| 1 | +function(GKlib_add_test test) |
| 2 | + #[===[.md |
| 3 | + # GKlib_add_test |
| 4 | +
|
| 5 | + Internal helper for adding GKlib tests |
| 6 | +
|
| 7 | + ## Synopsis |
| 8 | + ```cmake |
| 9 | + GKlib_add_test(<name> |
| 10 | + [TEST_NAME <test_name>] |
| 11 | + [TARGET <target>] |
| 12 | + [LABELS <label1> <label2>]) |
| 13 | + ``` |
| 14 | +
|
| 15 | + ## Options |
| 16 | +
|
| 17 | + `<name>` |
| 18 | + Path to the CMake project to be executed relative to `${CMAKE_CURRENT_SOURCE_DIR}` |
| 19 | +
|
| 20 | + `TEST_NAME` [Default: `<name>`] |
| 21 | + Name for the test to be used as the ctest name |
| 22 | +
|
| 23 | + `LABELS` |
| 24 | + Additional labels to be added |
| 25 | +
|
| 26 | + ]===] |
| 27 | + |
| 28 | + set(ARGS_Options) |
| 29 | + set(ARGS_OneValue |
| 30 | + TEST_NAME |
| 31 | + ) |
| 32 | + set(ARGS_MultiValue |
| 33 | + LABELS |
| 34 | + ) |
| 35 | + cmake_parse_arguments(PARSE_ARGV 1 ARGS "${ARGS_Options}" "${ARGS_OneValue}" "${ARGS_MultiValue}") |
| 36 | + # Check required/optional arguments |
| 37 | + if (ARGC LESS 1) |
| 38 | + message(FATAL_ERROR |
| 39 | + "Fortuno: Missing test name in Octopus_add_test call") |
| 40 | + endif () |
| 41 | + if (NOT DEFINED ARGS_TEST_NAME) |
| 42 | + set(ARGS_TEST_NAME ${test}) |
| 43 | + endif () |
| 44 | + |
| 45 | + add_test(NAME ${ARGS_TEST_NAME} |
| 46 | + COMMAND ${CMAKE_CTEST_COMMAND} --build-and-test ${CMAKE_CURRENT_SOURCE_DIR}/${test} |
| 47 | + ${CMAKE_CURRENT_BINARY_DIR}/${test} |
| 48 | + --build-generator "${CMAKE_GENERATOR}" |
| 49 | + --build-options -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} |
| 50 | + # Generated Config file point to binary targets until it is installed |
| 51 | + -DFETCHCONTENT_TRY_FIND_PACKAGE_MODE=ALWAYS |
| 52 | + -DGKlib_ROOT=${PROJECT_BINARY_DIR} |
| 53 | + # TODO: Implement recursive ctest and remove --notests flag |
| 54 | + --test-command ${CMAKE_CTEST_COMMAND} --test-dir ${CMAKE_CURRENT_BINARY_DIR}/${test} --no-tests=ignore |
| 55 | + ) |
| 56 | + set_tests_properties(${ARGS_TEST_NAME} PROPERTIES |
| 57 | + LABELS "${ARGS_LABELS}" |
| 58 | + ) |
| 59 | +endfunction() |
| 60 | + |
| 61 | +foreach (test IN ITEMS |
| 62 | + cmpnbrs |
| 63 | + csrcnv |
| 64 | + fis |
| 65 | + gkgraph |
| 66 | + gksort |
| 67 | + gkuniq |
| 68 | + grKx |
| 69 | + m2mnbrs |
| 70 | + rw |
| 71 | + splatt2svd |
| 72 | + strings |
| 73 | +) |
| 74 | + GKlib_add_test(${test}) |
| 75 | +endforeach () |
0 commit comments