|
| 1 | +cmake_minimum_required(VERSION 3.26...4.0) |
| 2 | +include_guard() |
| 3 | + |
| 4 | +function(scalapack_add_test test) |
| 5 | + #[===[.md |
| 6 | + # scalapack_add_test |
| 7 | +
|
| 8 | + Internal helper for adding functional tests of entire CMake projects |
| 9 | +
|
| 10 | + ## Synopsis |
| 11 | + ```cmake |
| 12 | + scalapack_add_test(<name> |
| 13 | + [TEST_NAME <test_name>] |
| 14 | + [CMAKE_ARGS <arg1> ...] |
| 15 | + [LABELS <label1> ...] |
| 16 | + ) |
| 17 | + ``` |
| 18 | +
|
| 19 | + ## Options |
| 20 | +
|
| 21 | + `<name>` |
| 22 | + : Test project to be configured |
| 23 | +
|
| 24 | + This is a subfolder relative to `${CMAKE_CURRENT_SOURCE_DIR}` containing the |
| 25 | + test project with `CMakeLists.txt` |
| 26 | +
|
| 27 | + `TEST_NAME` [Default: `<name>`] |
| 28 | + : Unique name of the ctest test name being created |
| 29 | +
|
| 30 | + `CMAKE_ARGS` |
| 31 | + : Additional CMake args passed to the configure step |
| 32 | + ]===] |
| 33 | + |
| 34 | + set(ARGS_Options) |
| 35 | + set(ARGS_OneValue |
| 36 | + TEST_NAME |
| 37 | + ) |
| 38 | + set(ARGS_MultiValue |
| 39 | + CMAKE_ARGS |
| 40 | + LABELS |
| 41 | + ) |
| 42 | + cmake_parse_arguments(PARSE_ARGV 1 ARGS "${ARGS_Options}" "${ARGS_OneValue}" "${ARGS_MultiValue}") |
| 43 | + # Check required/optional arguments |
| 44 | + if(NOT DEFINED ARGS_TEST_NAME) |
| 45 | + set(ARGS_TEST_NAME ${test}) |
| 46 | + endif() |
| 47 | + |
| 48 | + if(SCALAPACK_SOURCE_DIR) |
| 49 | + # If scalapack is built as part of the same project, use the build artifacts |
| 50 | + list(APPEND ARGS_CMAKE_ARGS |
| 51 | + -Dscalapack_ROOT=${SCALAPACK_BINARY_DIR} |
| 52 | + ) |
| 53 | + else() |
| 54 | + # Otherwise use `scalapack_DIR` which is created after the `find_package` |
| 55 | + list(APPEND ARGS_CMAKE_ARGS |
| 56 | + -Dscalapack_ROOT=${scalapack_DIR} |
| 57 | + ) |
| 58 | + endif() |
| 59 | + # Propagate the compilers used |
| 60 | + list(APPEND ARGS_CMAKE_ARGS |
| 61 | + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} |
| 62 | + -DCMAKE_Fortran_COMPILER=${CMAKE_Fortran_COMPILER} |
| 63 | + ) |
| 64 | + |
| 65 | + add_test(NAME ${ARGS_TEST_NAME} |
| 66 | + COMMAND ${CMAKE_CTEST_COMMAND} --build-and-test ${CMAKE_CURRENT_SOURCE_DIR}/${test} |
| 67 | + ${CMAKE_CURRENT_BINARY_DIR}/${test} |
| 68 | + # Use the same build environment as the current runner |
| 69 | + --build-generator "${CMAKE_GENERATOR}" |
| 70 | + --build-options |
| 71 | + ${ARGS_CMAKE_ARGS} |
| 72 | + --test-command ${CMAKE_CTEST_COMMAND} |
| 73 | + --test-dir ${CMAKE_CURRENT_BINARY_DIR}/${test} |
| 74 | + --no-tests=ignore |
| 75 | + --output-on-failure |
| 76 | + ) |
| 77 | +endfunction() |
0 commit comments