1 # 2 # Loosely based on: 3 # https://raw.githubusercontent.com/peti/autoconf-archive/master/m4/ax_code_coverage.m4 4 # - and - 5 # https://raw.githubusercontent.com/bilke/cmake-modules/master/CodeCoverage.cmake 6 # 7 8 find_program( GCOV_PATH gcov ) 9 10 if(NOT GCOV_PATH) 11 message(FATAL_ERROR "gcov not found! Aborting...") 12 endif() 13 14 if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") 15 if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3) 16 message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...") 17 endif() 18 elseif(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") 19 message(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") 20 endif() 21 22 set(COVERAGE_COMPILER_FLAGS "-O0 -g -fprofile-arcs -ftest-coverage") 23 24 if(CMAKE_C_COMPILER_ID STREQUAL "GNU") 25 set(COVERAGE_LINKER_FLAGS "") 26 set(COVERAGE_LIBRARIES "gcov") 27 else() 28 set(COVERAGE_LINKER_FLAGS "--coverage") 29 set(COVERAGE_LIBRARIES "") 30 endif() 31 32 mark_as_advanced( 33 COVERAGE_COMPILER_FLAGS 34 COVERAGE_LINKER_FLAGS 35 COVERAGE_LIBRARIES 36 )