aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRodney Dawes <dobey.pwns@gmail.com>2018-03-16 07:33:13 +0100
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2018-03-16 10:44:38 +0100
commit744720d0a29eb327aa0c25b4f3c4c134eb78e855 (patch)
tree61700490ba50b028a3144f1b4be5c34ad5e79b07
parent970f3823f1c14e094630e63d8d9b79235cb9bacf (diff)
downloadayatana-indicator-power-744720d0a29eb327aa0c25b4f3c4c134eb78e855.tar.gz
ayatana-indicator-power-744720d0a29eb327aa0c25b4f3c4c134eb78e855.tar.bz2
ayatana-indicator-power-744720d0a29eb327aa0c25b4f3c4c134eb78e855.zip
Use coverage support from cmake-extras.
-rw-r--r--CMakeLists.txt27
-rw-r--r--cmake/GCov.cmake51
-rw-r--r--debian/control2
-rw-r--r--src/CMakeLists.txt6
-rw-r--r--tests/CMakeLists.txt8
5 files changed, 22 insertions, 72 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4e17f11..fa06e7a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,9 +6,6 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
set(PROJECT_VERSION "2.0.92")
set(PACKAGE ${CMAKE_PROJECT_NAME})
-option (enable_tests "Build the package's automatic tests." ON)
-option (enable_lcov "Generate lcov code coverage reports." ON)
-
##
## GNU standard installation directories
##
@@ -61,9 +58,6 @@ add_custom_target (dist
COMMAND bzr export --root=${ARCHIVE_NAME} ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.gz
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
-add_custom_target (clean-coverage
- COMMAND find ${CMAKE_BINARY_DIR} -name '*.gcda' | xargs rm -f)
-
add_custom_target (cppcheck COMMAND cppcheck --enable=all -q --error-exitcode=2 --inline-suppr
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/tests)
@@ -85,19 +79,18 @@ set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-missing-field-initializers") # GActio
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories (${CMAKE_CURRENT_BINARY_DIR}/include)
-# testing & coverage
-if (${enable_tests})
- enable_testing ()
- if (${enable_lcov})
- include(GCov)
- endif ()
-endif ()
-
# actually build things
add_subdirectory(src)
add_subdirectory(data)
add_subdirectory(po)
-if (${enable_tests})
- add_subdirectory(tests)
-endif ()
+
+# testing & coverage
+enable_testing ()
+add_subdirectory(tests)
+find_package(CoverageReport)
+ENABLE_COVERAGE_REPORT(
+ TARGETS ${SERVICE_LIB} ${SERVICE_EXEC}
+ TESTS ${COVERAGE_TEST_TARGETS}
+ FILTER /usr/include ${CMAKE_BINARY_DIR}/*
+)
diff --git a/cmake/GCov.cmake b/cmake/GCov.cmake
deleted file mode 100644
index 81c0c40..0000000
--- a/cmake/GCov.cmake
+++ /dev/null
@@ -1,51 +0,0 @@
-if (CMAKE_BUILD_TYPE MATCHES coverage)
- set(GCOV_FLAGS "${GCOV_FLAGS} --coverage")
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCOV_FLAGS}")
- set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${GCOV_FLAGS}")
- set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GCOV_FLAGS}")
- set(GCOV_LIBS ${GCOV_LIBS} gcov)
-
- find_program(GCOVR_EXECUTABLE gcovr HINTS ${GCOVR_ROOT} "${GCOVR_ROOT}/bin")
- if (NOT GCOVR_EXECUTABLE)
- message(STATUS "Gcovr binary was not found, can not generate XML coverage info.")
- else ()
- message(STATUS "Gcovr found, can generate XML coverage info.")
- add_custom_target (coverage-xml
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
- COMMAND "${GCOVR_EXECUTABLE}" --exclude="test.*" -x -r "${CMAKE_SOURCE_DIR}"
- --object-directory=${CMAKE_BINARY_DIR} -o coverage.xml)
- endif()
-
- find_program(LCOV_EXECUTABLE lcov HINTS ${LCOV_ROOT} "${GCOVR_ROOT}/bin")
- find_program(GENHTML_EXECUTABLE genhtml HINTS ${GENHTML_ROOT})
- if (NOT LCOV_EXECUTABLE)
- message(STATUS "Lcov binary was not found, can not generate HTML coverage info.")
- else ()
- if(NOT GENHTML_EXECUTABLE)
- message(STATUS "Genthml binary not found, can not generate HTML coverage info.")
- else()
- message(STATUS "Lcov and genhtml found, can generate HTML coverage info.")
- add_custom_target (coverage-html
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
- COMMAND "${CMAKE_CTEST_COMMAND}" --force-new-ctest-process --verbose
- COMMAND "${LCOV_EXECUTABLE}" --directory ${CMAKE_BINARY_DIR} --capture | ${CMAKE_SOURCE_DIR}/trim-lcov.py > dconf-lcov.info
- COMMAND "${LCOV_EXECUTABLE}" -r dconf-lcov.info /usr/include/\\* -o nosys-lcov.info
- COMMAND LANG=C "${GENHTML_EXECUTABLE}" --prefix ${CMAKE_BINARY_DIR} --output-directory lcov-html --legend --show-details nosys-lcov.info
- COMMAND ${CMAKE_COMMAND} -E echo ""
- COMMAND ${CMAKE_COMMAND} -E echo "file://${CMAKE_BINARY_DIR}/lcov-html/index.html"
- COMMAND ${CMAKE_COMMAND} -E echo "")
- #COMMAND "${LCOV_EXECUTABLE}" --directory ${CMAKE_BINARY_DIR} --capture --output-file coverage.info --no-checksum
- #COMMAND "${GENHTML_EXECUTABLE}" --prefix ${CMAKE_BINARY_DIR} --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
- #COMMAND ${CMAKE_COMMAND} -E echo "\\#define foo \\\"bar\\\""
- #)
- endif()
- endif()
-endif()
-
-
- #$(MAKE) $(AM_MAKEFLAGS) check
- #lcov --directory $(top_builddir) --capture --test-name dconf | $(top_srcdir)/trim-lcov.py > dconf-lcov.info
- #LANG=C genhtml --prefix $(top_builddir) --output-directory lcov-html --legend --show-details dconf-lcov.info
- #@echo
- #@echo " file://$(abs_top_builddir)/lcov-html/index.html"
- #@echo
diff --git a/debian/control b/debian/control
index 63b9306..0cdd903 100644
--- a/debian/control
+++ b/debian/control
@@ -4,6 +4,8 @@ Priority: optional
Maintainer: Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
Build-Depends: cmake,
cmake-extras (>= 0.10),
+ gcovr,
+ lcov,
libnotify-dev (>= 0.7.6),
libglib2.0-dev (>= 2.36),
liburl-dispatcher1-dev | hello,
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d803f1e..afd0b0d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -46,7 +46,7 @@ set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-disabled-macro-expansion") # G_DEFINE
set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-assign-enum") # GParamFlags
set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-switch-enum")
set_source_files_properties(${SERVICE_MANUAL_SOURCES}
- PROPERTIES COMPILE_FLAGS "${C_WARNING_ARGS} ${GCOV_FLAGS} -g -std=c99")
+ PROPERTIES COMPILE_FLAGS "${C_WARNING_ARGS} -g -std=c99")
# the service library for tests to link against (basically, everything except main())
add_library(${SERVICE_LIB} STATIC ${SERVICE_MANUAL_SOURCES} ${SERVICE_GENERATED_SOURCES})
@@ -55,6 +55,6 @@ link_directories(${SERVICE_DEPS_LIBRARY_DIRS})
# the executable: lib + main()
add_executable (${SERVICE_EXEC} main.c)
-set_source_files_properties(${SERVICE_SOURCES} main.c PROPERTIES COMPILE_FLAGS "${C_WARNING_ARGS} -g -std=c99")
-target_link_libraries (${SERVICE_EXEC} ${SERVICE_LIB} ${SERVICE_DEPS_LIBRARIES} ${GCOV_LIBS} ${URLDISPATCHER_LIBRARIES})
+set_source_files_properties(${SERVICE_SOURCES} main.c PROPERTIES COMPILE_FLAGS "${C_WARNING_ARGS} -std=c99")
+target_link_libraries (${SERVICE_EXEC} ${SERVICE_LIB} ${SERVICE_DEPS_LIBRARIES} ${URLDISPATCHER_LIBRARIES})
install (TARGETS ${SERVICE_EXEC} RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_PKGLIBEXECDIR})
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 55e0b24..4010b54 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -7,7 +7,7 @@ pkg_check_modules(DBUSTEST REQUIRED
include_directories (SYSTEM ${DBUSTEST_INCLUDE_DIRS})
# add warnings
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g ${C_WARNING_ARGS}")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ${C_WARNING_ARGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-weak-vtables -Wno-global-constructors") # Google Test
# build the necessary schemas
@@ -42,6 +42,7 @@ include_directories (${CMAKE_CURRENT_BINARY_DIR})
function(add_test_by_name name)
set (TEST_NAME ${name})
+ set (COVERAGE_TEST_TARGETS ${COVERAGE_TEST_TARGETS} ${TEST_NAME} PARENT_SCOPE)
add_executable (${TEST_NAME} ${TEST_NAME}.cc)
add_test (${TEST_NAME} ${TEST_NAME})
add_dependencies (${TEST_NAME} ayatanaindicatorpowerservice gschemas-compiled)
@@ -50,3 +51,8 @@ endfunction()
add_test_by_name(test-notify)
add_test(NAME dear-reader-the-next-test-takes-80-seconds COMMAND true)
add_test_by_name(test-device)
+
+set(COVERAGE_TEST_TARGETS
+ ${COVERAGE_TEST_TARGETS}
+ PARENT_SCOPE
+)