diff options
author | Florent Le Coz <louiz@louiz.org> | 2015-10-29 03:20:39 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2015-10-29 03:20:39 +0100 |
commit | 9fe94215daecf21246e19ba59ef83755129a4a8b (patch) | |
tree | 997469992e1bda04ca1a22f77d0e89d3143781f7 | |
parent | 3b7bbe147229ee06de8b024e42e86d435cb0f72e (diff) | |
download | biboumi-9fe94215daecf21246e19ba59ef83755129a4a8b.tar.gz biboumi-9fe94215daecf21246e19ba59ef83755129a4a8b.tar.bz2 biboumi-9fe94215daecf21246e19ba59ef83755129a4a8b.tar.xz biboumi-9fe94215daecf21246e19ba59ef83755129a4a8b.zip |
Make lcov gcov etc optional
make coverage will display an error instead
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | cmake/Modules/CodeCoverage.cmake | 42 |
2 files changed, 24 insertions, 20 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d8633d8..64e21e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -186,7 +186,7 @@ add_custom_target(check COMMAND "test_suite" # ## Code coverage # -if(CMAKE_BUILD_TYPE MATCHES DEBUG) +if(CMAKE_BUILD_TYPE MATCHES Debug) include(CodeCoverage) SETUP_TARGET_FOR_COVERAGE(coverage test_suite diff --git a/cmake/Modules/CodeCoverage.cmake b/cmake/Modules/CodeCoverage.cmake index 2e2d4a0..5954846 100644 --- a/cmake/Modules/CodeCoverage.cmake +++ b/cmake/Modules/CodeCoverage.cmake @@ -73,18 +73,30 @@ FIND_PROGRAM( LCOV_PATH lcov ) FIND_PROGRAM( GENHTML_PATH genhtml ) FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests) -IF(NOT GCOV_PATH) - MESSAGE(FATAL_ERROR "gcov not found! Aborting...") -ENDIF() # NOT GCOV_PATH +# Display an error when the target is called. If no error is found, this +# function will be overridden by the real one later in this file +FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname) + ADD_CUSTOM_TARGET(${_targetname} + COMMAND echo "Coverage is not available: ${ERROR_MSG}" + ) +ENDFUNCTION() +IF(NOT GCOV_PATH) + set(ERROR_MSG "gcov not found") + return() +ENDIF() +IF(NOT LCOV_PATH) + set(ERROR_MSG "lcov not found") + return() +ENDIF() +IF(NOT GENHTML_PATH) + set(ERROR_MSG "genhtml not found") + return() +ENDIF() IF(NOT CMAKE_COMPILER_IS_GNUCXX) - # Clang version 3.0.0 and greater now supports gcov as well. - MESSAGE(WARNING "Compiler is not GNU gcc! Clang Version 3.0.0 and greater supports gcov as well, but older versions don't.") - - IF(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") - ENDIF() -ENDIF() # NOT CMAKE_COMPILER_IS_GNUCXX + set(ERROR_MSG "Compiler is not gcc") + return() +ENDIF() SET(CMAKE_CXX_FLAGS_COVERAGE "-g -O0 --coverage -fprofile-arcs -ftest-coverage" @@ -123,19 +135,11 @@ ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug" # Pass them in list form, e.g.: "-j;2" for -j 2 FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname) - IF(NOT LCOV_PATH) - MESSAGE(FATAL_ERROR "lcov not found! Aborting...") - ENDIF() # NOT LCOV_PATH - - IF(NOT GENHTML_PATH) - MESSAGE(FATAL_ERROR "genhtml not found! Aborting...") - ENDIF() # NOT GENHTML_PATH - # Setup target ADD_CUSTOM_TARGET(${_targetname} # Cleanup lcov - ${LCOV_PATH} --directory . --zerocounters + COMMAND ${LCOV_PATH} --directory . --zerocounters # Create baseline coverage data file COMMAND ${LCOV_PATH} -c -i -d . -o ${_outputname}.baseline.info -q |