CMake: Add option COVERAGE

This also removed PROFILE option that also adds --coverage flag. Instead you can use -DCMAKE_EXE_LINKER_FLAGS=-lprofiler. The profiling options can be added back when better investigated (e.g. -lprofiler vs -pg options).
This commit is contained in:
Paweł Bylica 2018-07-04 15:12:08 +02:00
parent 721b7bbf70
commit 807f7533d9
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF

View File

@ -151,21 +151,23 @@ if (SANITIZE)
endif() endif()
endif() endif()
if (PROFILING AND (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))) # Code coverage support.
set(CMAKE_CXX_FLAGS "-g ${CMAKE_CXX_FLAGS}") # Copied from Cable:
set(CMAKE_C_FLAGS "-g ${CMAKE_C_FLAGS}") # https://github.com/ethereum/cable/blob/v0.2.4/CableCompilerSettings.cmake#L118-L132
add_definitions(-DETH_PROFILING_GPERF) option(COVERAGE "Build with code coverage support" OFF)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lprofiler") if(COVERAGE)
# set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -lprofiler") # Set the linker flags first, they are required to properly test the compiler flag.
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lprofiler") set(CMAKE_SHARED_LINKER_FLAGS "--coverage ${CMAKE_SHARED_LINKER_FLAGS}")
endif () set(CMAKE_EXE_LINKER_FLAGS "--coverage ${CMAKE_EXE_LINKER_FLAGS}")
if (PROFILING AND (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU"))) set(CMAKE_REQUIRED_LIBRARIES "--coverage ${CMAKE_REQUIRED_LIBRARIES}")
set(CMAKE_CXX_FLAGS "-g --coverage ${CMAKE_CXX_FLAGS}") check_cxx_compiler_flag(--coverage have_coverage)
set(CMAKE_C_FLAGS "-g --coverage ${CMAKE_C_FLAGS}") string(REPLACE "--coverage " "" CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_SHARED_LINKER_FLAGS "--coverage ${CMAKE_SHARED_LINKER_FLAGS} -lprofiler") if(NOT have_coverage)
set(CMAKE_EXE_LINKER_FLAGS "--coverage ${CMAKE_EXE_LINKER_FLAGS} -lprofiler") message(FATAL_ERROR "Coverage not supported")
endif () endif()
add_compile_options(-g --coverage)
endif()
if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")) if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
option(USE_LD_GOLD "Use GNU gold linker" ON) option(USE_LD_GOLD "Use GNU gold linker" ON)