|
| 1 | +define_property(TARGET PROPERTY EXCLUDE_FROM_COVERAGE) |
| 2 | + |
| 3 | +function(emil_exclude_from_coverage target) |
| 4 | + set_target_properties(${target} PROPERTIES EXCLUDE_FROM_COVERAGE TRUE) |
| 5 | +endfunction() |
| 6 | + |
| 7 | +function(emil_exclude_directory_from_coverage directory) |
| 8 | + emil_get_subdirectories(directories DIRECTORIES ${directory}) |
| 9 | + list(APPEND directories ${directory}) |
| 10 | + emil_get_targets_from_directories(targets DIRECTORIES ${directories}) |
| 11 | + |
| 12 | + foreach(target ${targets}) |
| 13 | + emil_exclude_from_coverage(${target}) |
| 14 | + endforeach() |
| 15 | +endfunction() |
| 16 | + |
| 17 | +function(emil_enable_coverage_for target) |
| 18 | + if (EMIL_ENABLE_COVERAGE) |
| 19 | + message(DEBUG "enable coverage for: ${target}") |
| 20 | + target_compile_options(${target} PRIVATE |
| 21 | + -g -O0 --coverage -fprofile-arcs -ftest-coverage -fno-inline |
| 22 | + $<$<COMPILE_LANGUAGE:CXX>:-fno-elide-constructors> |
| 23 | + ) |
| 24 | + |
| 25 | + if (CMAKE_C_COMPILER_ID STREQUAL "GNU") |
| 26 | + target_link_libraries(${target} PRIVATE gcov) |
| 27 | + else() |
| 28 | + target_link_options(${target} PRIVATE --coverage) |
| 29 | + endif() |
| 30 | + endif() |
| 31 | +endfunction() |
| 32 | + |
| 33 | +function(emil_enable_mutation_for target) |
| 34 | + if (EMIL_ENABLE_MUTATION_TESTING) |
| 35 | + message(DEBUG "enable mutation for: ${target}") |
| 36 | + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 37 | + target_compile_options(${target} PRIVATE |
| 38 | + -g -O0 -grecord-command-line -fprofile-instr-generate -fcoverage-mapping -fpass-plugin=/usr/lib/mull-ir-frontend |
| 39 | + ) |
| 40 | + |
| 41 | + target_link_options(${target} PRIVATE -fprofile-instr-generate) |
| 42 | + else() |
| 43 | + message(FATAL_ERROR "Mutation testing is currently only supported for Clang/LLVM; not for ${CMAKE_CXX_COMPILER_ID}") |
| 44 | + endif() |
| 45 | + endif() |
| 46 | +endfunction() |
| 47 | + |
| 48 | +function(emil_coverage_targets directories) |
| 49 | + set(singleArgs COVERAGE_FILE) |
| 50 | + set(multiValueArgs DIRECTORIES) |
| 51 | + cmake_parse_arguments(PARSE_ARGV 0 MY "" "${singleArgs}" "${multiValueArgs}") |
| 52 | + |
| 53 | + emil_get_subdirectories(subdirectories DIRECTORIES ${MY_DIRECTORIES}) |
| 54 | + emil_get_targets_from_directories(targets DIRECTORIES ${subdirectories}) |
| 55 | + |
| 56 | + set(non_generated_target_sources) |
| 57 | + foreach(target ${targets}) |
| 58 | + get_target_property(exclude ${target} EXCLUDE_FROM_COVERAGE) |
| 59 | + get_target_property(type ${target} TYPE) |
| 60 | + |
| 61 | + if (NOT exclude AND NOT ${type} STREQUAL "INTERFACE_LIBRARY" AND NOT ${type} STREQUAL "UTILITY") |
| 62 | + emil_enable_coverage_for(${target}) |
| 63 | + emil_enable_mutation_for(${target}) |
| 64 | + else() |
| 65 | + message(DEBUG "skipping coverage and mutation for: ${target}") |
| 66 | + endif() |
| 67 | + endforeach() |
| 68 | +endfunction() |
0 commit comments