From a51a6fd9e70e3f1d96a4f234310f4e5fe4e45283 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Tue, 8 Oct 2019 16:12:18 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BA=D1=80=D1=8B=D1=82=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMLibCodeCoverage.cmake | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 CMLibCodeCoverage.cmake diff --git a/CMLibCodeCoverage.cmake b/CMLibCodeCoverage.cmake new file mode 100644 index 0000000..54abfdd --- /dev/null +++ b/CMLibCodeCoverage.cmake @@ -0,0 +1,31 @@ +function(add_code_coverage) + list(GET ARGN 0 _target) + + find_program(LCOV_EXE NAMES lcov) + find_program(GENHTML_EXE NAMES genhtml) + target_compile_options(_target PUBLIC "--coverage") + + if(LCOV_EXE) + 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} + COMMAND ${GENHTML_EXE} + --output-directory + "report-${_target}" + "${_target}.lcov") + add_dependencies(coverage-report-${_target} coverage-${_target}) + endif() + endif() +endfunction()