~unity-team/libqtdbusmock/trunk

« back to all changes in this revision

Viewing changes to cmake/Coverage.cmake

  • Committer: Bileto Bot
  • Author(s): Pete Woods
  • Date: 2017-01-06 10:44:18 UTC
  • mfrom: (45.1.1 stable)
  • Revision ID: ci-train-bot@canonical.com-20170106104418-gvma1zy1zykerf62
Compatibility with unversioned cmake-extras modules (LP: #1563573)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
if (CMAKE_BUILD_TYPE MATCHES coverage)
2
 
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
3
 
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
4
 
  set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --coverage")
5
 
  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
6
 
 
7
 
  find_program(GCOVR_EXECUTABLE gcovr HINTS ${GCOVR_ROOT} "${GCOVR_ROOT}/bin")
8
 
  if (NOT GCOVR_EXECUTABLE)
9
 
    message(STATUS "Gcovr binary was not found, can not generate XML coverage info.")
10
 
  else ()
11
 
    message(STATUS "Gcovr found, can generate XML coverage info.")
12
 
    add_custom_target (coverage-xml
13
 
      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
14
 
      COMMAND "${GCOVR_EXECUTABLE}" --exclude="test.*" --exclude="obj.*" -x -r "${CMAKE_SOURCE_DIR}" 
15
 
      --object-directory=${CMAKE_BINARY_DIR} -o coverage.xml)
16
 
  endif()
17
 
 
18
 
  find_program(LCOV_EXECUTABLE lcov HINTS ${LCOV_ROOT} "${GCOVR_ROOT}/bin")
19
 
  find_program(GENHTML_EXECUTABLE genhtml HINTS ${GENHTML_ROOT})
20
 
  if (NOT LCOV_EXECUTABLE)
21
 
    message(STATUS "Lcov binary was not found, can not generate HTML coverage info.")
22
 
  else ()
23
 
    if(NOT GENHTML_EXECUTABLE)
24
 
      message(STATUS "Genthml binary not found, can not generate HTML coverage info.")
25
 
    else()
26
 
      message(STATUS "Lcov and genhtml found, can generate HTML coverage info.")
27
 
      add_custom_target (coverage-html
28
 
        WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
29
 
        COMMAND "${LCOV_EXECUTABLE}" --capture --output-file "${CMAKE_BINARY_DIR}/coverage.info" --no-checksum --directory "${CMAKE_BINARY_DIR}/src"
30
 
        COMMAND "${LCOV_EXECUTABLE}" --remove "${CMAKE_BINARY_DIR}/coverage.info" '/usr/*' --output-file "${CMAKE_BINARY_DIR}/coverage.info" 
31
 
        COMMAND "${LCOV_EXECUTABLE}" --remove "${CMAKE_BINARY_DIR}/coverage.info" '${CMAKE_BINARY_DIR}/*' --output-file "${CMAKE_BINARY_DIR}/coverage.info" 
32
 
        COMMAND "${LCOV_EXECUTABLE}" --remove "${CMAKE_BINARY_DIR}/coverage.info" '${CMAKE_SOURCE_DIR}/tests/*' --output-file "${CMAKE_BINARY_DIR}/coverage.info" 
33
 
        COMMAND "${GENHTML_EXECUTABLE}" --prefix "${CMAKE_BINARY_DIR}" --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
34
 
        )
35
 
    endif()
36
 
  endif()
37
 
endif()