|
| 1 | +add_custom_target(mull_tests) |
| 2 | + |
| 3 | +function(add_mull_test name) |
| 4 | + message( |
| 5 | + STATUS |
| 6 | + "add_mull_test(${name}) is disabled because CMAKE_CXX_COMPILER_ID is ${CMAKE_CXX_COMPILER_ID}." |
| 7 | + ) |
| 8 | +endfunction() |
| 9 | + |
| 10 | +if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 11 | + return() |
| 12 | +endif() |
| 13 | + |
| 14 | +function(find_mull) |
| 15 | + string(REGEX MATCH "[0-9]+" version ${CMAKE_CXX_COMPILER_VERSION}) |
| 16 | + find_program(MULL_RUNNER_PROGRAM "mull-runner-${version}") |
| 17 | + if(MULL_RUNNER_PROGRAM) |
| 18 | + message( |
| 19 | + STATUS "mull-runner-${version} found at ${MULL_RUNNER_PROGRAM}.") |
| 20 | + else() |
| 21 | + message( |
| 22 | + STATUS |
| 23 | + "mull-runner-${version} not found. add_mull_test() will fail unless a valid RUNNER_DIR is provided." |
| 24 | + ) |
| 25 | + endif() |
| 26 | + find_file(MULL_PLUGIN_LIBRARY "mull-ir-frontend-${version}" |
| 27 | + HINTS "/usr/lib") |
| 28 | + if(MULL_PLUGIN_LIBRARY) |
| 29 | + message( |
| 30 | + STATUS |
| 31 | + "mull-ir-frontend-${version} found at ${MULL_PLUGIN_LIBRARY}.") |
| 32 | + else() |
| 33 | + message( |
| 34 | + STATUS |
| 35 | + "mull-ir-frontend-${version} not found. add_mull_test() will fail unless a valid PLUGIN_DIR is provided." |
| 36 | + ) |
| 37 | + endif() |
| 38 | + return(PROPAGATE MULL_RUNNER_PROGRAM MULL_PLUGIN_LIBRARY) |
| 39 | +endfunction() |
| 40 | + |
| 41 | +find_mull() |
| 42 | + |
| 43 | +function(add_mull_test name) |
| 44 | + set(options EXCLUDE_CTEST) |
| 45 | + set(singleValueArgs PLUGIN_DIR RUNNER_DIR) |
| 46 | + set(multiValueArgs RUNNER_ARGS) |
| 47 | + cmake_parse_arguments(MULL "${options}" "${singleValueArgs}" |
| 48 | + "${multiValueArgs}" ${ARGN}) |
| 49 | + |
| 50 | + string(REGEX MATCH "[0-9]+" version ${CMAKE_CXX_COMPILER_VERSION}) |
| 51 | + |
| 52 | + set(MULL_RUNNER_NOT_FOUND_COMMAND |
| 53 | + COMMAND ${CMAKE_COMMAND} -E echo |
| 54 | + "Cannot run mull_${name} because mull-runner-${version} not found." |
| 55 | + COMMAND ${CMAKE_COMMAND} -E false) |
| 56 | + set(MULL_PLUGIN_NOT_FOUND_COMMAND |
| 57 | + COMMAND ${CMAKE_COMMAND} -E echo |
| 58 | + "Cannot build mull_${name} because mull-ir-frontend-${version} not found." |
| 59 | + COMMAND ${CMAKE_COMMAND} -E false) |
| 60 | + |
| 61 | + if(MULL_RUNNER_DIR) |
| 62 | + find_program(MULL_RUNNER "mull-runner-${version}" |
| 63 | + HINTS ${MULL_RUNNER_DIR}) |
| 64 | + else() |
| 65 | + set(MULL_RUNNER ${MULL_RUNNER_PROGRAM}) |
| 66 | + set(MULL_RUNNER_DIR "<RUNNER_DIR not provided>") |
| 67 | + endif() |
| 68 | + if(NOT MULL_RUNNER) |
| 69 | + message( |
| 70 | + WARNING |
| 71 | + "mull-runner-${version} not found at ${MULL_RUNNER_DIR}. mull_${name} is a failing test." |
| 72 | + ) |
| 73 | + add_custom_target(mull_${name} ${MULL_RUNNER_NOT_FOUND_COMMAND}) |
| 74 | + add_dependencies(mull_tests mull_${name}) |
| 75 | + return() |
| 76 | + endif() |
| 77 | + |
| 78 | + if(MULL_PLUGIN_DIR) |
| 79 | + find_file(MULL_PLUGIN "mull-ir-frontend-${version}" |
| 80 | + HINTS ${MULL_PLUGIN_DIR}) |
| 81 | + else() |
| 82 | + set(MULL_PLUGIN ${MULL_PLUGIN_LIBRARY}) |
| 83 | + set(MULL_PLUGIN_DIR "<PLUGIN_DIR not provided>") |
| 84 | + endif() |
| 85 | + if(NOT MULL_PLUGIN) |
| 86 | + message( |
| 87 | + WARNING |
| 88 | + "mull-ir-frontend-${version} not found at ${MULL_PLUGIN_DIR}. mull_${name} is a failing test." |
| 89 | + ) |
| 90 | + add_custom_target(mull_${name} ${MULL_PLUGIN_NOT_FOUND_COMMAND}) |
| 91 | + add_dependencies(mull_tests mull_${name}) |
| 92 | + return() |
| 93 | + endif() |
| 94 | + |
| 95 | + target_compile_options(${name} PRIVATE -fpass-plugin=${MULL_PLUGIN} -O0 -g |
| 96 | + -grecord-command-line) |
| 97 | + target_link_libraries(${name} PRIVATE coverage) |
| 98 | + |
| 99 | + set(mull_test_command $<TARGET_FILE:${name}>) |
| 100 | + add_custom_target(mull_${name} DEPENDS ${name}.mull) |
| 101 | + add_custom_command( |
| 102 | + OUTPUT ${name}.mull |
| 103 | + COMMAND ${MULL_RUNNER} ${MULL_RUNNER_ARGS} ${mull_test_command} |
| 104 | + COMMAND ${CMAKE_COMMAND} "-E" "touch" "${name}.mull" |
| 105 | + DEPENDS ${name} |
| 106 | + COMMAND_EXPAND_LISTS) |
| 107 | + |
| 108 | + if(NOT MULL_EXCLUDE_CTEST) |
| 109 | + add_test(NAME MULL.${name} |
| 110 | + COMMAND ${MULL_RUNNER} ${MULL_RUNNER_ARGS} |
| 111 | + ${mull_test_command} COMMAND_EXPAND_LISTS) |
| 112 | + endif() |
| 113 | + |
| 114 | + add_dependencies(mull_tests mull_${name}) |
| 115 | +endfunction() |
0 commit comments