You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.2 KiB

3 months ago
  1. option( COVERAGE "Enable collection of coverage statistics" OFF )
  2. if (COVERAGE)
  3. if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
  4. #message(SEND_ERROR "Coverage collection with clang is not supported yet.")
  5. #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -g -O0")
  6. #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
  7. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
  8. add_custom_target(coverage-collect
  9. COMMAND ${CMAKE_SOURCE_DIR}/cmake/coverage-clang.sh ${CMAKE_BINARY_DIR}
  10. WORKING_DIRECTORY ${CMAKE_BUILD_DIR}
  11. )
  12. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  13. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage --coverage -g -O0")
  14. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov")
  15. add_custom_target(coverage-collect
  16. COMMAND lcov --directory . --zerocounters
  17. COMMAND make test
  18. COMMAND lcov --directory . --base-directory . --capture -o coverage.info
  19. COMMAND lcov --remove coverage.info '/usr/*' 'build/resources/*' 'src/tests/*' --output-file coverage.info
  20. COMMAND genhtml coverage.info -o "coverage/"
  21. WORKING_DIRECTORY ${CMAKE_BUILD_DIR}
  22. )
  23. endif()
  24. endif()