Чистка функции для покрытия кода

This commit is contained in:
Andrei Astafev 2019-10-08 16:33:29 +03:00
parent abfce824d2
commit d57bbeb634

View File

@ -1,34 +1,38 @@
function(add_code_coverage) function(add_code_coverage)
list(GET ARGN 0 _target) list(GET ARGN 0 _target)
find_program(LCOV_EXE NAMES lcov) if(CMAKE_CXX_COMPILER_IS_GCC)
find_program(GENHTML_EXE NAMES genhtml) find_program(LCOV_EXE NAMES lcov)
target_compile_options(${_target} PUBLIC "--coverage") find_program(GENHTML_EXE NAMES genhtml)
get_target_property(LF ${_target} LINK_FLAGS) target_compile_options(${_target} PUBLIC "--coverage")
list(APPEND LF "--coverage") get_target_property(LF ${_target} LINK_FLAGS)
set_target_properties(${_target} PROPERTIES LINK_FLAGS ${LF}) string(APPEND LF " --coverage")
set_target_properties(${_target} PROPERTIES LINK_FLAGS ${LF})
if(LCOV_EXE) if(LCOV_EXE)
add_custom_target(coverage-${_target} add_custom_target(coverage-${_target}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${LCOV_EXE}
--test-name
${_target}
--output
"${_target}.lcov"
--capture
--directory
${CMAKE_BINARY_DIR})
add_dependencies(coverage-${_target} ${_target})
if(GENHTML_EXE)
add_custom_target(coverage-report-${_target}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${GENHTML_EXE} COMMAND ${LCOV_EXE}
--output-directory --test-name
"report-${_target}" ${_target}
"${_target}.lcov") --output
add_dependencies(coverage-report-${_target} coverage-${_target}) "${_target}.lcov"
--capture
--directory
${CMAKE_BINARY_DIR})
add_dependencies(coverage-${_target} ${_target})
if(GENHTML_EXE)
add_custom_target(coverage-report-${_target}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${GENHTML_EXE}
--output-directory
"report-${_target}"
"${_target}.lcov")
add_dependencies(coverage-report-${_target} coverage-${_target})
endif()
endif() endif()
else()
message("Only GCC is supported for code coverage")
endif() endif()
endfunction() endfunction()