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 <goller@gmail.com>
This commit is contained in:
Chris Goller 2019-12-09 11:36:28 -06:00 committed by Leo Di Donato
parent 7159b43f68
commit e31bfeb8b2

View File

@ -18,6 +18,8 @@ cmake_minimum_required(VERSION 3.3.2)
project(falco) project(falco)
option(FALCO_Coverage "Build test suite with coverage information" OFF)
if(NOT SYSDIG_DIR) if(NOT SYSDIG_DIR)
get_filename_component(SYSDIG_DIR "${PROJECT_SOURCE_DIR}/../sysdig" REALPATH) get_filename_component(SYSDIG_DIR "${PROJECT_SOURCE_DIR}/../sysdig" REALPATH)
endif() endif()
@ -633,6 +635,18 @@ endif()
install(FILES falco.yaml install(FILES falco.yaml
DESTINATION "${FALCO_ETC_DIR}") 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(test)
add_subdirectory(rules) add_subdirectory(rules)
add_subdirectory(docker) add_subdirectory(docker)