
set(GCOV_TOOL "gcov-8")
set(LCOV_TOOL "lcov")
set(GENHTML_TOOL "genhtml")
set(CODE_COVERAGE_LCOV_REPORT_PATH "${CMAKE_BINARY_DIR}/coverage.info")
set(CODE_COVERAGE_HTML_REPORT_PATH "report")
set(ADDITIONAL_PATHS "/usr/local/bin" )

find_program(GCOV_PROG NAME ${GCOV_TOOL} PATHS ${ADDITIONAL_PATHS})
find_program(LCOV_PROG NAME ${LCOV_TOOL} PATHS ${ADDITIONAL_PATHS})
find_program(GENHTML_PROG NAME ${GENHTML_TOOL} PATHS ${ADDITIONAL_PATHS})

set(LCOV_COMMAND_ARGS --gcov-tool ${GCOV_PROG} -d ${CMAKE_BINARY_DIR} -c -o ${CODE_COVERAGE_LCOV_REPORT_PATH})
set(GENHTML_COMMAND_ARGS -o ${CODE_COVERAGE_HTML_REPORT_PATH} ${CODE_COVERAGE_LCOV_REPORT_PATH})

add_custom_target(coverage ${LCOV_PROG} ${LCOV_COMMAND_ARGS}
    COMMAND ${GENHTML_PROG} ${GENHTML_COMMAND_ARGS})
