Skip to content

Commit

Permalink
Merge pull request #226 from robertodr/code-coverage
Browse files Browse the repository at this point in the history
Update code coverage module
  • Loading branch information
bast authored Feb 7, 2018
2 parents 9953b65 + eee3ef9 commit 0f3ee1a
Showing 1 changed file with 40 additions and 16 deletions.
56 changes: 40 additions & 16 deletions modules/code_coverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,54 @@
#
# autocmake.yml configuration::
#
# docopt: "--coverage Enable code coverage [default: False]."
# docopt: "--coverage Enable code coverage [default: OFF]."
# define: "'-DENABLE_CODE_COVERAGE={0}'.format(arguments['--coverage'])"

option(ENABLE_CODE_COVERAGE "Enable code coverage" OFF)

if(ENABLE_CODE_COVERAGE)
if(DEFINED CMAKE_Fortran_COMPILER_ID)
if(CMAKE_Fortran_COMPILER_ID MATCHES GNU)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fprofile-arcs -ftest-coverage")
endif()
if(NOT CMAKE_BUILD_TYPE STREQUAL "debug")
message(WARNING "Code coverage analysis results with an optimized (non-Debug) build may be misleading")
endif()

find_program(GCOV_PATH gcov)
if(NOT GCOV_PATH)
message(FATAL_ERROR "Code coverage analysis requires gcov!")
endif()

if(DEFINED CMAKE_Fortran_COMPILER_ID)
if(CMAKE_Fortran_COMPILER_ID MATCHES GNU)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fprofile-arcs -ftest-coverage")
else()
message(FATAL_ERROR "Code coverage analysis requires the GNU Fortran compiler!")
endif()
endif()

if(DEFINED CMAKE_C_COMPILER_ID)
if(CMAKE_C_COMPILER_ID MATCHES GNU)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
endif()
if(DEFINED CMAKE_C_COMPILER_ID)
if(CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
if(CMAKE_C_COMPILER_VERSION VERSION_LESS 3)
message(FATAL_ERROR "Code coverage analysis on Mac OS X requires Clang version 3.0.0 or greater!")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
endif()
elseif(CMAKE_C_COMPILER_ID MATCHES GNU)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
else()
message(FATAL_ERROR "Code coverage analysis requires the GNU C compiler!")
endif()
endif()

if(DEFINED CMAKE_CXX_COMPILER_ID)
if(CMAKE_CXX_COMPILER_ID MATCHES GNU)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES Clang)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
endif()
if(DEFINED CMAKE_CXX_COMPILER_ID)
if(CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3)
message(FATAL_ERROR "Code coverage analysis on Mac OS X requires Clang version 3.0.0 or greater!")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES GNU)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
else()
message(FATAL_ERROR "Code coverage analysis requires the GNU C++ compiler!")
endif()
endif()
endif()

0 comments on commit 0f3ee1a

Please sign in to comment.