From: Azat Khuzhin Date: Tue, 1 Nov 2016 20:33:11 +0000 (+0300) Subject: Fix cmake -DEVENT__COVERAGE=ON X-Git-Tag: release-2.1.7-rc~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=40fbffc0df78085180513fd143fa87bff1e7cd6f;p=libevent Fix cmake -DEVENT__COVERAGE=ON - do not use compiler check from the root cmake rules with syntax error, let CodeCoverage check it - fix CodeCoverage to check C compiler not CXX - case insensitive checking of CMAKE_BUILD_TYPE - replace flags with --coverage, and fix flags with linking with --coverate, otherwise it will not compile during checking flags and fails. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b7a36a2..99be4435 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Set build type to Debug o Release (default Release)" FORCE) endif() +string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) # get rid of the extra default configurations # what? why would you get id of other useful build types? - Ellzey @@ -152,16 +153,15 @@ endif() # Setup compiler flags for coverage. if (EVENT__COVERAGE) - if ((NOT CMAKE_COMPILER_IS_GNUCC) AND (NOT ${CMAKE_CXX_COMPILER_ID} STREQAL "Clang")) - message(FATAL_ERROR "Trying to compile coverage support, but compiler is not GNU gcc! Try CC=/usr/bin/gcc CXX=/usr/bin/g++ cmake ..") - endif() - - if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + if (NOT "${CMAKE_BUILD_TYPE_LOWER}" STREQUAL "debug") message(FATAL_ERROR "Coverage requires -DCMAKE_BUILD_TYPE=Debug") endif() message(STATUS "Setting coverage compiler flags") - add_compiler_flags(-g -O0 -fprofile-arcs -ftest-coverage) + + set(CMAKE_REQUIRED_LIBRARIES "--coverage") + add_compiler_flags(-g -O0 --coverage) + set(CMAKE_REQUIRED_LIBRARIES "") endif() # GCC specific options. diff --git a/cmake/CodeCoverage.cmake b/cmake/CodeCoverage.cmake index 969f2732..eba85b3f 100644 --- a/cmake/CodeCoverage.cmake +++ b/cmake/CodeCoverage.cmake @@ -30,6 +30,9 @@ # - Added support for Clang. # - Some additional usage instructions. # +# 2016-11-02, Azat Khuzhin +# - Adopt for C compiler only (libevent) +# # USAGE: # 1. Copy this file into your cmake modules path. # @@ -68,11 +71,11 @@ IF(NOT GCOV_PATH) MESSAGE(FATAL_ERROR "gcov not found! Aborting...") ENDIF() # NOT GCOV_PATH -IF(NOT CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_COMPILER_IS_GNUCXX) +IF(NOT CMAKE_COMPILER_IS_GNUCC) # 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") + IF(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") ENDIF() ENDIF() # NOT CMAKE_COMPILER_IS_GNUCC