From ac6a398cb6c3d0ebdf72aa77a7139d7f16cd6305 Mon Sep 17 00:00:00 2001 From: obligaron Date: Fri, 14 May 2021 14:06:47 +0200 Subject: [PATCH] New CMake option ENABLE_CODECOVERAGE to toggle instrumentation of code for code coverage --- .circleci/config.yml | 2 +- CMakeLists.txt | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 395e610e4..78c2aca86 100644 --- a/.circleci/config.yml +++ b/.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) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f92690b6..b8fb9d1e7 100644 --- a/CMakeLists.txt +++ b/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()