]> granicus.if.org Git - libevent/commitdiff
Fix cmake -DEVENT__COVERAGE=ON
authorAzat Khuzhin <a3at.mail@gmail.com>
Tue, 1 Nov 2016 20:33:11 +0000 (23:33 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Wed, 2 Nov 2016 08:36:24 +0000 (11:36 +0300)
- 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.

CMakeLists.txt
cmake/CodeCoverage.cmake

index 1b7a36a2ede3e0873f8ef202d4e23503447480b8..99be4435ae325e742e4430b0ce30427e914d08a6 100644 (file)
@@ -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 <options> ..")
-    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.
index 969f273253e60c8a9edaf5e3e2191f3e7f75f80e..eba85b3fb77e5cb17903be8ed6f29f511b32922e 100644 (file)
@@ -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