2021-12-08 11:32:04 +00:00
|
|
|
option(MYX_CMAKE_CODE_COVERAGE "MyxCMake: enable code coverage" OFF)
|
|
|
|
|
|
|
|
if(MYX_CMAKE_CODE_COVERAGE)
|
|
|
|
find_program(LCOV_EXE NAMES lcov)
|
|
|
|
find_program(GENHTML_EXE NAMES genhtml)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
function(myx_cmake_code_coverage target)
|
|
|
|
if(CMAKE_CXX_COMPILER_IS_GCC AND MYX_CMAKE_CODE_COVERAGE)
|
|
|
|
target_compile_options(${target} PUBLIC "--coverage")
|
|
|
|
set_property(
|
|
|
|
TARGET ${target}
|
|
|
|
APPEND_STRING
|
|
|
|
PROPERTY LINK_FLAGS " --coverage")
|
|
|
|
|
|
|
|
if(LCOV_EXE)
|
|
|
|
add_custom_target(
|
|
|
|
${target}-coverage
|
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
2021-12-23 11:00:56 +00:00
|
|
|
COMMAND ${LCOV_EXE} --test-name ${target} --output "${target}.lcov" --capture
|
|
|
|
--exclude "/usr/\\\*"
|
|
|
|
--exclude "${CMAKE_BINARY_DIR}/\\\*"
|
|
|
|
--directory ${CMAKE_BINARY_DIR})
|
2021-12-08 11:32:04 +00:00
|
|
|
add_dependencies(${target}-coverage ${target})
|
|
|
|
|
|
|
|
if(GENHTML_EXE)
|
|
|
|
add_custom_target(
|
|
|
|
${target}-coverage-report
|
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
|
|
COMMAND ${GENHTML_EXE} --output-directory "${target}-coverage-html"
|
|
|
|
"${target}.lcov")
|
|
|
|
add_dependencies(${target}-coverage-report ${target}-coverage)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|