Skip to content

Commit 01361bc

Browse files
committed
cov
1 parent 2dfbec1 commit 01361bc

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

CMakeLists.txt

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,82 @@ elseif (DEBUG_MEMORY STREQUAL "Leak")
473473
-fno-omit-frame-pointer ")
474474
endif()
475475

476+
# HiGHS coverage update in progress
477+
478+
# For the moment keep above coverage part in case we are testing at CI.
479+
# option(CI_COV "CI extended tests" ON)
480+
481+
# Coverage part
482+
# 'make coverage' to start the coverage process
483+
option(HIGHS_COVERAGE "Activate the code coverage compilation" OFF)
484+
485+
if(HIGHS_COVERAGE)
486+
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
487+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 --coverage")
488+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 --coverage")
489+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O0 --coverage")
490+
endif()
491+
492+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
493+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -Xclang -coverage-cfg-checksum -Xclang -coverage-no-function-names-in-data -Xclang -coverage-version='408*'")
494+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -Xclang -coverage-cfg-checksum -Xclang -coverage-no-function-names-in-data -Xclang -coverage-version='408*'")
495+
endif()
496+
endif()
497+
498+
if(HIGHS_COVERAGE)
499+
if(NOT CMAKE_BUILD_TYPE STREQUAL "DEBUG")
500+
message(FATAL_ERROR "Warning: to enable coverage, you must compile in DEBUG mode")
501+
endif()
502+
endif()
503+
504+
if(HIGHS_COVERAGE)
505+
if(WIN32)
506+
message(FATAL_ERROR "Error: code coverage analysis is only available under Linux for now.")
507+
endif()
508+
509+
find_program(GCOV_PATH gcov)
510+
find_program(LCOV_PATH lcov)
511+
find_program(GENHTML_PATH genhtml)
512+
513+
if(NOT GCOV_PATH)
514+
message(FATAL_ERROR "gcov not found! Please install lcov and gcov. Aborting...")
515+
endif()
516+
517+
if(NOT LCOV_PATH)
518+
message(FATAL_ERROR "lcov not found! Please install lcov and gcov. Aborting...")
519+
endif()
520+
521+
if(NOT GENHTML_PATH)
522+
message(FATAL_ERROR "genhtml not found! Please install lcov and gcov. Aborting...")
523+
endif()
524+
525+
# Capturing lcov counters and generating report
526+
# if(NOT CI)
527+
add_custom_target(coverage
528+
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters
529+
COMMAND ${LCOV_PATH} --capture --initial --directory ${CMAKE_BINARY_DIR}/bin --output-file ${CMAKE_BINARY_DIR}/coverage.info
530+
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR} ${CMAKE_CTEST_COMMAND} -LE "(LONG|FAIL)" || true
531+
COMMAND ${LCOV_PATH} --capture --directory ${CMAKE_BINARY_DIR}/bin --directory ${CMAKE_BINARY_DIR}/src --directory ${CMAKE_BINARY_DIR}/app --directory ${CMAKE_BINARY_DIR}/check --output-file ${CMAKE_BINARY_DIR}/coverage.info
532+
COMMAND ${LCOV_PATH} --remove "*/usr/include/*" --output-file ${CMAKE_BINARY_DIR}/coverage.info.cleaned
533+
COMMAND ${GENHTML_PATH} -o ${CMAKE_BINARY_DIR}/coverage ${CMAKE_BINARY_DIR}/coverage.info.cleaned
534+
COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_BINARY_DIR}/coverage.info.cleaned
535+
VERBATIM
536+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
537+
COMMENT "Resetting code coverage counters to zero.
538+
Processing code coverage counters and generating report.
539+
You can zip the directory ${CMAKE_BINARY_DIR}/coverage and upload the content to a web server.")
540+
# else()
541+
# add_custom_target(ci_cov
542+
# COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters
543+
# COMMAND ${LCOV_PATH} --capture --initial --directory ${CMAKE_BINARY_DIR}/bin --output-file ${CMAKE_BINARY_DIR}/coverage.info
544+
# COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR} ${CMAKE_CTEST_COMMAND} -LE "(LONG|FAIL)" || true
545+
# COMMAND ${LCOV_PATH} --capture --directory ${CMAKE_BINARY_DIR}/bin --directory ${CMAKE_BINARY_DIR}/src --directory ${CMAKE_BINARY_DIR}/app --directory ${CMAKE_BINARY_DIR}/check --output-file ${CMAKE_BINARY_DIR}/coverage.info
546+
# VERBATIM
547+
# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
548+
# COMMENT "Resetting code coverage counters to zero.")
549+
# endif()
550+
endif()
551+
476552
if(NOT FAST_BUILD)
477553
# For the moment keep above coverage part in case we are testing at CI.
478554
option(CI "CI extended tests" ON)

0 commit comments

Comments
 (0)