build CHANGE coverage information
By default, switch off generating coverage information.
Due to the recent changes of the tests building, it is necessary to add
coverage information also to the library objects, so do it only when
explicitely stated that the coverage target will be used.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2ffa4b7..1d7aabf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -32,21 +32,11 @@
set(CMAKE_BUILD_TYPE debug)
endif()
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-missing-field-initializers -std=c99")
-set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
-set(CMAKE_C_FLAGS_PACKAGE "-g -O2 -DNDEBUG")
-set(CMAKE_C_FLAGS_DEBUG "-g -O0")
-
# options
if((CMAKE_BUILD_TYPE STREQUAL debug) OR (CMAKE_BUILD_TYPE STREQUAL Package))
option(ENABLE_BUILD_TESTS "Build tests" ON)
option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON)
-
- if(CMAKE_COMPILER_IS_GNUCC)
- option(ENABLE_COVERAGE "Build code coverage report from tests" ON)
- else()
- option(ENABLE_COVERAGE "Build code coverage report from tests" OFF)
- endif()
+ option(ENABLE_COVERAGE "Build code coverage report from tests" OFF)
else()
option(ENABLE_BUILD_TESTS "Build tests" OFF)
option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF)
@@ -80,6 +70,39 @@
set(COMPILER_PACKED_ATTR "")
endif()
+if(ENABLE_COVERAGE)
+ find_program(PATH_GCOV NAMES gcov)
+ if(NOT PATH_GCOV)
+ message(WARNING "'gcov' executable not found! Disabling building code coverage report.")
+ set(ENABLE_COVERAGE OFF)
+ endif()
+
+ find_program(PATH_LCOV NAMES lcov)
+ if(NOT PATH_GCOV)
+ message(WARNING "'lcov' executable not found! Disabling building code coverage report.")
+ set(ENABLE_COVERAGE OFF)
+ endif()
+
+ find_program(PATH_GENHTML NAMES genhtml)
+ if(NOT PATH_GCOV)
+ message(WARNING "'genhtml' executable not found! Disabling building code coverage report.")
+ set(ENABLE_COVERAGE OFF)
+ endif()
+
+ if(NOT CMAKE_COMPILER_IS_GNUCC)
+ message(WARNING "Compiler is not gcc! Coverage may break the tests!")
+ endif()
+
+ if(ENABLE_COVERAGE)
+ set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
+ endif()
+endif()
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_COVERAGE} -Wall -Wextra -Wno-missing-field-initializers -std=c99")
+set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
+set(CMAKE_C_FLAGS_PACKAGE "-g -O2 -DNDEBUG")
+set(CMAKE_C_FLAGS_DEBUG "-g -O0")
+
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
check_symbol_exists(get_current_dir_name unistd.h HAVE_GET_CURRENT_DIR_NAME)
check_symbol_exists(vdprintf stdio.h HAVE_VDPRINTF)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 8cf25fa..01cb370 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -9,34 +9,6 @@
find_program(VALGRIND_FOUND valgrind)
endif()
-if(ENABLE_COVERAGE)
- find_program(PATH_GCOV NAMES gcov)
- if(NOT PATH_GCOV)
- message(WARNING "'gcov' executable not found! Disabling building code coverage report.")
- set(ENABLE_COVERAGE OFF)
- endif()
-
- find_program(PATH_LCOV NAMES lcov)
- if(NOT PATH_GCOV)
- message(WARNING "'lcov' executable not found! Disabling building code coverage report.")
- set(ENABLE_COVERAGE OFF)
- endif()
-
- find_program(PATH_GENHTML NAMES genhtml)
- if(NOT PATH_GCOV)
- message(WARNING "'genhtml' executable not found! Disabling building code coverage report.")
- set(ENABLE_COVERAGE OFF)
- endif()
-
- if(NOT CMAKE_COMPILER_IS_GNUCC)
- message(WARNING "Compiler is not gcc! Coverage may break the tests!")
- endif()
-
- if(ENABLE_COVERAGE)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
- endif()
-endif()
-
configure_file("${PROJECT_SOURCE_DIR}/tests/config.h.in" "${PROJECT_BINARY_DIR}/tests/config.h" ESCAPE_QUOTES @ONLY)
include_directories(SYSTEM ${CMOCKA_INCLUDE_DIR})
include_directories(${PROJECT_BINARY_DIR})
@@ -44,6 +16,7 @@
set(tests)
set(tests_wraps)
add_subdirectory(src)
+add_subdirectory(features)
foreach(test_name IN LISTS tests)
message(STATUS ${test_name})
@@ -88,7 +61,7 @@
# Add coverage target
add_custom_target(coverage
COMMENT "Generating code coverage..."
- WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests"
+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
# Cleanup code counters
COMMAND "${PATH_LCOV}" --directory . --zerocounters --quiet
@@ -104,7 +77,7 @@
--output-file "${COVERAGE_FILE_RAW}"
# Remove coverage of tests, system headers, etc.
COMMAND "${PATH_LCOV}"
- --remove "${COVERAGE_FILE_RAW}" '${CMAKE_BINARY_DIR}/*' '${CMAKE_BINARY_DIR}/tests/*' '/usr/*'
+ --remove "${COVERAGE_FILE_RAW}" '${CMAKE_SOURCE_DIR}/tests/*'
--rc lcov_branch_coverage=1
--quiet --output-file "${COVERAGE_FILE_CLEAN}"
# Generate HTML report