From e31bfeb8b20633d2ade832953136113dee3dbcfe Mon Sep 17 00:00:00 2001 From: Chris Goller Date: Mon, 9 Dec 2019 11:36:28 -0600 Subject: [PATCH] build: add FALCO_Coverage CMake option With cmake FALCO_Coverage=on the --coverage option is passed to both clang and gcc to help analyze untested portions of the code base. It produces gcov files. These files can be analyzed by many tools such as lcov, gcovr, etc. Here is an example of one such tool, lcov: lcov --directory . --capture --output-file coverage.info lcov --extract coverage.info '/source/*' --output-file coverage.info genhtml coverage.info Signed-off-by: Chris Goller --- CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 490e6a81..2ff02914 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,8 @@ cmake_minimum_required(VERSION 3.3.2) project(falco) +option(FALCO_Coverage "Build test suite with coverage information" OFF) + if(NOT SYSDIG_DIR) get_filename_component(SYSDIG_DIR "${PROJECT_SOURCE_DIR}/../sysdig" REALPATH) endif() @@ -633,6 +635,18 @@ endif() install(FILES falco.yaml DESTINATION "${FALCO_ETC_DIR}") +if(FALCO_Coverage) + if (NOT (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))) + message(FATAL_ERROR "FALCO_Coverage requires GCC or Clang.") + endif() + + message(STATUS "Building with coverage information") + add_compile_options(-g --coverage) + set(CMAKE_SHARED_LINKER_FLAGS "--coverage ${CMAKE_SHARED_LINKER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "--coverage ${CMAKE_EXE_LINKER_FLAGS}") +endif() + + add_subdirectory(test) add_subdirectory(rules) add_subdirectory(docker)