|
5 | 5 | project(taco)
|
6 | 6 | option(CUDA "Build for NVIDIA GPU (CUDA must be preinstalled)" OFF)
|
7 | 7 | option(PYTHON "Build TACO for python environment" OFF)
|
8 |
| -option(OPENMP" Build with OpenMP execution support" OFF) |
| 8 | +option(OPENMP "Build with OpenMP execution support" OFF) |
| 9 | +option(COVERAGE "Build with code coverage analysis" OFF) |
9 | 10 | if(CUDA)
|
10 | 11 | message("-- Searching for CUDA Installation")
|
11 | 12 | find_package(CUDA REQUIRED)
|
@@ -75,6 +76,15 @@ if(OPENMP)
|
75 | 76 | set(C_CXX_FLAGS "-fopenmp ${C_CXX_FLAGS}")
|
76 | 77 | endif(OPENMP)
|
77 | 78 |
|
| 79 | +if(COVERAGE) |
| 80 | + find_program(PATH_TO_GCOVR gcovr REQUIRED) |
| 81 | + # add coverage tooling to build flags |
| 82 | + set(C_CXX_FLAGS "${C_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage") |
| 83 | + # name the coverage files "foo.gcno", not "foo.cpp.gcno" |
| 84 | + set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1) |
| 85 | + message("-- Code coverage analysis (gcovr) enabled") |
| 86 | +endif(COVERAGE) |
| 87 | + |
78 | 88 | set(C_CXX_FLAGS "${C_CXX_FLAGS}")
|
79 | 89 | set(CMAKE_C_FLAGS "${C_CXX_FLAGS}")
|
80 | 90 | set(CMAKE_CXX_FLAGS "${C_CXX_FLAGS} -std=c++14")
|
@@ -103,3 +113,23 @@ if(PYTHON)
|
103 | 113 | endif(PYTHON)
|
104 | 114 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-declarations")
|
105 | 115 | add_custom_target(src DEPENDS apps)
|
| 116 | + |
| 117 | +if(COVERAGE) |
| 118 | + # code coverage analysis target |
| 119 | + add_custom_target(gcovr |
| 120 | + COMMAND mkdir -p coverage |
| 121 | + COMMAND ${CMAKE_MAKE_PROGRAM} test |
| 122 | + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
| 123 | + ) |
| 124 | + add_custom_command(TARGET gcovr |
| 125 | + COMMAND echo "Running gcovr..." |
| 126 | + COMMAND ${PATH_TO_GCOVR} -r ${CMAKE_SOURCE_DIR} --html --html-details -o coverage/index.html ${CMAKE_BINARY_DIR} |
| 127 | + COMMAND echo "See coverage/index.html for coverage information." |
| 128 | + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
| 129 | + ) |
| 130 | + add_dependencies(gcovr taco-test) |
| 131 | + if(PYTHON) |
| 132 | + add_dependencies(gcovr core_modules) |
| 133 | + endif(PYTHON) |
| 134 | + set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES coverage) |
| 135 | +endif(COVERAGE) |
0 commit comments