🔨 trying to use Coveralls with CMake #698

This commit is contained in:
Niels Lohmann 2017-10-04 22:18:21 +02:00
parent 99ee4c1eaf
commit 1b3df3a63f
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
2 changed files with 27 additions and 18 deletions

View file

@ -1,6 +1,7 @@
option(JSON_Sanitizer "Build test suite with Clang sanitizer" OFF)
option(JSON_Valgrind "Execute test suite with Valgrind" OFF)
option(JSON_NoExceptions "Build test suite without exceptions" OFF)
option(JSON_Coverage "Build test suite with coverage information" OFF)
if(JSON_Sanitizer)
message(STATUS "Building test suite with Clang sanitizer")
@ -25,6 +26,29 @@ if(JSON_NoExceptions)
set(CATCH_TEST_FILTER -e)
endif()
if(JSON_Coverage)
message(STATUS "Building test suite with coverage information")
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message(FATAL_ERROR "JSON_Coverage requires GCC.")
endif()
# enable profiling
set(CMAKE_CXX_FLAGS "--coverage -g -O0 -fprofile-arcs -ftest-coverage")
# from https://github.com/RWTH-HPC/CMake-codecov/blob/master/cmake/FindGcov.cmake
get_filename_component(COMPILER_PATH "${CMAKE_CXX_COMPILER}" PATH)
string(REGEX MATCH "^[0-9]+" GCC_VERSION "${CMAKE_CXX_COMPILER_VERSION}")
find_program(GCOV_BIN NAMES gcov-${GCC_VERSION} gcov HINTS ${COMPILER_PATH})
# add target to collect coverage information and generate HTML file
add_custom_target(lcov_html
COMMAND lcov --directory . --capture --output-file json.info --gcov-tool ${GCOV_BIN} --rc lcov_branch_coverage=1
COMMAND lcov -e json.info ${CMAKE_SOURCE_DIR}/src/json.hpp --output-file json.info.filtered --rc lcov_branch_coverage=1
COMMAND genhtml --title "JSON for Modern C++" --legend --demangle-cpp --output-directory html --show-details --branch-coverage json.info.filtered
COMMENT "Generating HTML report test/html/index.html"
)
endif()
#############################################################################
# Catch library with the main function to speed up build
#############################################################################
@ -65,11 +89,6 @@ foreach(file ${files})
set_target_properties(${testcase} PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wno-float-equal")
endif()
include(cotire OPTIONAL)
if(COMMAND cotire)
cotire(${testcase})
endif()
add_test(NAME "${testcase}_default"
COMMAND ${testcase} ${CATCH_TEST_FILTER}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}