Browse Source

New CMake option ENABLE_CODECOVERAGE to toggle instrumentation of code for code coverage

pull/1979/head
obligaron 5 years ago committed by Anders Jenbo
parent
commit
ac6a398cb6
  1. 2
      .circleci/config.yml
  2. 18
      CMakeLists.txt

2
.circleci/config.yml

@ -25,7 +25,7 @@ jobs:
- checkout
- run: apt-get update -y
- run: apt-get install -y cmake curl g++ git lcov libgtest-dev libfmt-dev libsdl2-dev libsdl2-ttf-dev libsodium-dev
- run: cmake -S. -Bbuild -DRUN_TESTS=ON
- run: cmake -S. -Bbuild -DRUN_TESTS=ON -DENABLE_CODECOVERAGE=ON
- run: cmake --build build -j 2
- run: cmake --build build -j 2 --target test
- run: bash <(curl -s https://codecov.io/bash)

18
CMakeLists.txt

@ -26,6 +26,7 @@ option(USE_SDL1 "Use SDL1.2 instead of SDL2" OFF)
option(NONET "Disable network support" OFF)
option(NOSOUND "Disable sound support" OFF)
option(RUN_TESTS "Build and run tests" OFF)
option(ENABLE_CODECOVERAGE "Instrument code for code coverage (only enabled with RUN_TESTS)" OFF)
option(USE_GETTEXT "Build translation files using gettext" OFF)
option(DISABLE_STREAMING_MUSIC "Disable streaming music (to work around broken platform implementations)" OFF)
@ -542,11 +543,20 @@ if(RUN_TESTS)
include(GoogleTest)
find_package(GTest REQUIRED)
target_include_directories(devilutionx-tests PRIVATE ${GTEST_INCLUDE_DIRS})
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(devilutionx-tests PRIVATE -fprofile-arcs -ftest-coverage)
target_link_libraries(devilutionx-tests PRIVATE libdevilutionx)
target_link_libraries(devilutionx-tests PRIVATE ${GTEST_LIBRARIES})
if(ENABLE_CODECOVERAGE)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
message(WARNING "Codecoverage not supported with MSVC")
else()
target_compile_options(devilutionx-tests PRIVATE -fprofile-arcs -ftest-coverage)
target_compile_options(libdevilutionx PRIVATE -fprofile-arcs -ftest-coverage)
target_compile_options(${BIN_TARGET} PRIVATE -fprofile-arcs -ftest-coverage)
target_link_options(devilutionx-tests PRIVATE -fprofile-arcs)
target_link_options(libdevilutionx PRIVATE -fprofile-arcs)
target_link_options(${BIN_TARGET} PRIVATE -fprofile-arcs)
endif()
endif()
target_link_libraries(devilutionx-tests PRIVATE -fprofile-arcs libdevilutionx)
target_link_libraries(devilutionx-tests PRIVATE -fprofile-arcs ${GTEST_LIBRARIES})
gtest_add_tests(devilutionx-tests "" AUTO)
endif()

Loading…
Cancel
Save