Skip to content

Instantly share code, notes, and snippets.

@gengjiawen
Created October 17, 2019 02:30
Show Gist options
  • Save gengjiawen/8ca54e38fff384b9ea229dbb087c9d5f to your computer and use it in GitHub Desktop.
Save gengjiawen/8ca54e38fff384b9ea229dbb087c9d5f to your computer and use it in GitHub Desktop.
CMake
# Code Coverage Configuration
add_library(coverage_config INTERFACE)
option(CODE_COVERAGE "Enable coverage reporting" ON)
if(CODE_COVERAGE AND CMAKE_C_COMPILER_ID MATCHES "AppleClang|GNU|Clang")
# Add required flags (GCC & LLVM/Clang)
target_compile_options(coverage_config INTERFACE
-O0 # no optimization
-g # generate debug info
--coverage # sets all required flags
)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
target_link_options(coverage_config INTERFACE --coverage)
else()
target_link_libraries(coverage_config INTERFACE --coverage)
endif()
endif()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment