Added compiler flags for test coverage, active when using with
authorEugeny Kalishenko <ydginster@gmail.com>
Sat, 19 Dec 2015 12:39:50 +0000 (15:39 +0300)
committerEugeny Kalishenko <ydginster@gmail.com>
Sat, 19 Dec 2015 12:39:50 +0000 (15:39 +0300)
-DWITH_TESTS_COVERAGE (#46)

CMakeLists.txt
build/cmake/readme.md

index ba1092faaa40860edeb4e87de125d512e349ac35..1e062440ba728fe141864a2e1033706bd353380d 100644 (file)
@@ -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...###############################################################################
index ae2034e505258c271095a03c5a7d5622e534d57a..65f13d767b0acc6b7a613146ba06155f39d2d254 100644 (file)
@@ -19,6 +19,7 @@ Compiling and testing
 After using command *cmake -L <path to the project's root directory with CMakeLists.txt>* 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)
 - ...