From 5ea38ea3038edfc3da3e056e8214f1adb55c5217 Mon Sep 17 00:00:00 2001 From: Eugeny Kalishenko Date: Sat, 19 Dec 2015 15:39:50 +0300 Subject: [PATCH] Added compiler flags for test coverage, active when using with -DWITH_TESTS_COVERAGE (#46) --- CMakeLists.txt | 13 +++++++++++++ build/cmake/readme.md | 1 + 2 files changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba1092fa..1e062440 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ set(PROJECT_VERSION 2.1.0) # Options option(WITH_TESTS "Build unit tests" OFF) +option(WITH_TESTS_COVERAGE "Analyze test coverage using gcov (only for gcc)" OFF) option(WITH_BOOST_ATOMIC "Use boost atomics (only for boost >= 1.54)" OFF) find_package(Threads REQUIRED) @@ -21,6 +22,17 @@ if(WITH_BOOST_ATOMIC) endif() endif(WITH_BOOST_ATOMIC) +if(WITH_TESTS_COVERAGE) + if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") + message(STATUS "Test coverage analysis: activated") + else() + message(WARNING "Compiler is not GNU gcc! Test coverage couldn't be analyzed") + endif() +endif(WITH_TESTS_COVERAGE) + set(CDS_SHARED_LIBRARY ${PROJECT_NAME}) set(CDS_STATIC_LIBRARY ${PROJECT_NAME}-s) @@ -71,6 +83,7 @@ install(DIRECTORY ${CMAKE_SOURCE_DIR}/cds DESTINATION include COMPONENT ${HEADER if(WITH_TESTS) enable_testing() add_subdirectory(${CMAKE_SOURCE_DIR}/tests) + message(STATUS "Build tests: activated") endif(WITH_TESTS) ### FOR PACKAGING in RPM, TGZ, DEB, NSYS...############################################################################### diff --git a/build/cmake/readme.md b/build/cmake/readme.md index ae2034e5..65f13d76 100644 --- a/build/cmake/readme.md +++ b/build/cmake/readme.md @@ -19,6 +19,7 @@ Compiling and testing After using command *cmake -L * one can see some additional variables, that can activate additional features: - *WITH_TESTS:BOOL=OFF*: if you want to build library with unit testing support use *-DWITH_TESTS=ON* on prepare step. Be careful with this flag, because compile time will dramatically increase +- *WITH_TESTS_COVERAGE:BOOL=OFF*: Analyze test coverage using gcov (only for gcc) - *WITH_BOOST_ATOMIC:BOOL=OFF*: Use boost atomics (only for boost >= 1.54) - ... -- 2.34.1