Warning, /graphics/glaxnimate/cmake/testing.cmake is written in an unsupported language. File is not indexed.

0001 # Copyright 2015-2019 Mattia Basaglia
0002 #
0003 # This program is free software: you can redistribute it and/or modify
0004 # it under the terms of the GNU General Public License as published by
0005 # the Free Software Foundation, either version 3 of the License, or
0006 # (at your option) any later version.
0007 #
0008 # This program is distributed in the hope that it will be useful,
0009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0011 # GNU General Public License for more details.
0012 #
0013 # You should have received a copy of the GNU General Public License
0014 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
0015 
0016 
0017 # Variables:
0018 #   COVERAGE_TOOL - (lcov or gcovr) Which coverage reporting tool to use
0019 #   COVERAGE_SOURCE_BASE_DIR - Base dir to extract the sources from for coverage
0020 #   COVERAGE_REMOVE_PATTERNS  - Patterns to remove from the trace file
0021 #   COVERAGE_FILTER_PATTERNS  - Patterns to keep in the trace file
0022 #
0023 
0024 if(NOT DEFINED COVERAGE_TARGET_PREFIX)
0025     set(COVERAGE_TARGET_PREFIX tests_)
0026 endif()
0027 
0028 enable_testing()
0029 add_custom_target(${COVERAGE_TARGET_PREFIX}compile
0030     COMMENT "Building all tests"
0031 )
0032 
0033 add_custom_target(${COVERAGE_TARGET_PREFIX}run
0034     COMMAND ctest -V
0035     DEPENDS ${COVERAGE_TARGET_PREFIX}compile
0036     COMMENT "Running all tests"
0037 )
0038 
0039 set(TRACEFILE "${CMAKE_BINARY_DIR}/coverage.info")
0040 set(COVERAGE_DIR "${CMAKE_BINARY_DIR}/coverage")
0041 
0042 if(NOT COVERAGE_SOURCE_BASE_DIR)
0043     set(COVERAGE_SOURCE_BASE_DIR "${CMAKE_SOURCE_DIR}")
0044 endif()
0045 
0046 if (NOT COVERAGE_TOOL)
0047     set(COVERAGE_TOOL "lcov")
0048 endif()
0049 
0050 message(STATUS "Coverage tool is ${COVERAGE_TOOL}")
0051 
0052 if (${COVERAGE_TOOL} STREQUAL lcov)
0053     add_custom_target(${COVERAGE_TARGET_PREFIX}coverage
0054         COMMAND cd ${CMAKE_BINARY_DIR}
0055         COMMAND lcov -c -d "${CMAKE_CURRENT_BINARY_DIR}" -b "${COVERAGE_SOURCE_BASE_DIR}" -o ${TRACEFILE} --no-external --rc lcov_branch_coverage=1
0056         COMMAND lcov --remove ${TRACEFILE} ${COVERAGE_REMOVE_PATTERNS} -o ${TRACEFILE} --rc lcov_branch_coverage=1
0057         COMMAND genhtml ${TRACEFILE} -o ${COVERAGE_DIR} -p "${COVERAGE_SOURCE_BASE_DIR}" --demangle-cpp --branch-coverage --rc genhtml_hi_limit=80
0058         DEPENDS ${COVERAGE_TARGET_PREFIX}run
0059     )
0060 elseif(${COVERAGE_TOOL} STREQUAL gcovr)
0061     set(GCOVR_CMD
0062         gcovr --root ${COVERAGE_SOURCE_BASE_DIR} --object-directory ${CMAKE_BINARY_DIR}
0063         -s --branches --exclude-throw-branches
0064         --html --html-details "${COVERAGE_DIR}/index.html"
0065     )
0066 
0067     foreach(remove IN ITEMS ${COVERAGE_REMOVE_PATTERNS})
0068         list(APPEND GCOVR_CMD -e ${remove})
0069     endforeach()
0070 
0071     foreach(filter IN ITEMS ${COVERAGE_FILTER_PATTERNS})
0072         list(APPEND GCOVR_CMD -f ${filter})
0073     endforeach()
0074 
0075     add_custom_target(${COVERAGE_TARGET_PREFIX}coverage
0076         COMMAND cd ${CMAKE_BINARY_DIR}
0077         COMMAND mkdir -p ${COVERAGE_DIR}
0078         COMMAND ${GCOVR_CMD}
0079         DEPENDS ${COVERAGE_TARGET_PREFIX}run
0080     )
0081 else()
0082 endif()
0083 
0084 add_custom_target(${COVERAGE_TARGET_PREFIX}coverage_view
0085     COMMAND xdg-open "${COVERAGE_DIR}/index.html"
0086 )