Add coverage option to cmake

Summary:
Coverage is by default set to OFF, but the new option can be used for convenient
toggle when building.

Reviewers: buda

Reviewed By: buda

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D109
This commit is contained in:
Teon Banek 2017-03-09 13:52:21 +01:00
parent 4bcee620bc
commit 9dada557a3
2 changed files with 10 additions and 4 deletions

View File

@ -255,6 +255,8 @@ option(MANUAL_TESTS "Add manual test binaries" OFF)
message(STATUS "Add manual test binaries: ${MANUAL_TESTS}")
option(UNIT_TESTS "Add unit test binaries" OFF)
message(STATUS "Add unit test binaries: ${UNIT_TESTS}")
option(TEST_COVERAGE "Generate coverage reports from unit tests" OFF)
message(STATUS "Generate coverage from unit tests: ${TEST_COVERAGE}")
# -----------------------------------------------------------------------------
# includes

View File

@ -19,8 +19,10 @@ foreach(test_cpp ${test_type_cpps})
# build exec file
add_executable(${target_name} ${test_cpp})
set_property(TARGET ${target_name} PROPERTY CXX_STANDARD ${cxx_standard})
set_target_properties(${target_name} PROPERTIES COMPILE_FLAGS "-g -O0 -Wall --coverage -fprofile-arcs -ftest-coverage")
set_target_properties(${target_name} PROPERTIES LINK_FLAGS "--coverage -fprofile-arcs -ftest-coverage")
if(${TEST_COVERAGE})
set_target_properties(${target_name} PROPERTIES COMPILE_FLAGS "-g -O0 -Wall --coverage -fprofile-arcs -ftest-coverage")
set_target_properties(${target_name} PROPERTIES LINK_FLAGS "--coverage -fprofile-arcs -ftest-coverage")
endif()
# OUTPUT_NAME sets the real name of a target when it is built and can be
# used to help create two targets of the same name even though CMake
@ -44,8 +46,10 @@ foreach(test_cpp ${test_type_cpps})
target_link_libraries(${target_name} antlr_opencypher_parser_lib)
# dynamic lib
target_link_libraries(${target_name} dl)
# for code coverage
target_link_libraries(${target_name} gcov)
if(${TEST_COVERAGE})
# for code coverage
target_link_libraries(${target_name} gcov)
endif()
# register test
set(output_path ${CMAKE_BINARY_DIR}/test_results/unit/${target_name}.xml)