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.

58 satır
1.8KB

  1. # Find Lcov tools
  2. find_program(LCOV lcov DOC "LCov")
  3. find_program(LCOV_GENHTML genhtml DOC "LCov GenHtml" HINTS ${LCOV}/..)
  4. if( NOT LCOV OR NOT LCOV_GENHTML )
  5. message(SEND_ERROR "LCov tools not found")
  6. endif()
  7. # Files and folders
  8. set(COV_DIR "${CMAKE_BINARY_DIR}/coverage")
  9. set(COV_FILE "${COV_DIR}/${PROJECT_NAME}.info")
  10. if( NOT EXISTS ${COV_DIR} )
  11. file(MAKE_DIRECTORY ${COV_DIR})
  12. endif()
  13. # Compiler flags
  14. set(flag --coverage)
  15. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
  16. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
  17. set(INPUT_DIR "${CMAKE_SOURCE_DIR}")
  18. # Make targets
  19. add_custom_target(coverage-clean ${CMAKE_COMMAND} -E make_directory ${COV_DIR}
  20. COMMAND ${LCOV}
  21. --directory ${INPUT_DIR}
  22. --zerocounters
  23. WORKING_DIRECTORY ${COV_DIR}
  24. COMMENT "Zerocounter coverage data"
  25. VERBATIM
  26. )
  27. add_custom_target(coverage ${CMAKE_COMMAND} -E make_directory ${COV_DIR}
  28. COMMAND ${LCOV}
  29. --capture
  30. --directory ${INPUT_DIR}
  31. --output-file ${COV_FILE}
  32. --no-external
  33. COMMAND ${LCOV}
  34. --remove ${COV_FILE} "*/test/*"
  35. --remove ${COV_FILE} "*/generated/*"
  36. --output-file ${COV_FILE}
  37. COMMAND ${LCOV_GENHTML} --legend ${COV_FILE}
  38. WORKING_DIRECTORY ${COV_DIR}
  39. COMMENT "Generate coverage data"
  40. VERBATIM
  41. )