From f9bfd8adec6c0a7bf1d9d57b9be2f59d3557e5fd Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Fri, 14 May 2021 12:39:25 +0200 Subject: [PATCH] takes ECMCoverageOption from ECM to enable code coverage analysis Signed-off-by: Matthieu Gallien --- CMakeLists.txt | 2 ++ cmake/modules/ECMCoverageOption.cmake | 29 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 cmake/modules/ECMCoverageOption.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c27ab3d49..ce4807428 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,8 @@ endif() set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules ) +include(ECMCoverageOption) + if(NOT CRASHREPORTER_EXECUTABLE) set(CRASHREPORTER_EXECUTABLE "${APPLICATION_EXECUTABLE}_crash_reporter") endif() diff --git a/cmake/modules/ECMCoverageOption.cmake b/cmake/modules/ECMCoverageOption.cmake new file mode 100644 index 000000000..7a96280e9 --- /dev/null +++ b/cmake/modules/ECMCoverageOption.cmake @@ -0,0 +1,29 @@ +# SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez +# +# SPDX-License-Identifier: BSD-3-Clause + +#[=======================================================================[.rst: +ECMCoverageOption +-------------------- + +Allow users to easily enable GCov code coverage support. + +Code coverage allows you to check how much of your codebase is covered by +your tests. This module makes it easy to build with support for +`GCov `_. + +When this module is included, a ``BUILD_COVERAGE`` option is added (default +OFF). Turning this option on enables GCC's coverage instrumentation, and +links against ``libgcov``. + +Note that this will probably break the build if you are not using GCC. + +Since 1.3.0. +#]=======================================================================] + +option(BUILD_COVERAGE "Build the project with gcov support" OFF) + +if(BUILD_COVERAGE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov") +endif()