summaryrefslogtreecommitdiff
path: root/neozip/cmake/detect-coverage.cmake
diff options
context:
space:
mode:
authorMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 19:56:09 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 19:56:09 +0300
commit7fb132859fda54aa96bc9dd46d302b343eeb5a02 (patch)
treeb43ae77d7451fb470a260c03349a1caf2846c5e5 /neozip/cmake/detect-coverage.cmake
parentb1e34e861b5d732afe828d58aad2c638135061fd (diff)
parentc2712b8a345191f6ed79558c089777df94590087 (diff)
downloadProject-Tick-7fb132859fda54aa96bc9dd46d302b343eeb5a02.tar.gz
Project-Tick-7fb132859fda54aa96bc9dd46d302b343eeb5a02.zip
Add 'neozip/' from commit 'c2712b8a345191f6ed79558c089777df94590087'
git-subtree-dir: neozip git-subtree-mainline: b1e34e861b5d732afe828d58aad2c638135061fd git-subtree-split: c2712b8a345191f6ed79558c089777df94590087
Diffstat (limited to 'neozip/cmake/detect-coverage.cmake')
-rw-r--r--neozip/cmake/detect-coverage.cmake50
1 files changed, 50 insertions, 0 deletions
diff --git a/neozip/cmake/detect-coverage.cmake b/neozip/cmake/detect-coverage.cmake
new file mode 100644
index 0000000000..ff993cf9ff
--- /dev/null
+++ b/neozip/cmake/detect-coverage.cmake
@@ -0,0 +1,50 @@
+# detect-coverage.cmake -- Detect supported compiler coverage flags
+# Licensed under the Zlib license, see LICENSE.md for details
+
+# Attempt to enable gcov-style code coverage
+macro(add_code_coverage)
+ # Check for --coverage flag support
+ set(CMAKE_REQUIRED_LINK_OPTIONS -coverage)
+ check_c_compiler_flag("--coverage" HAVE_COVERAGE)
+ set(CMAKE_REQUIRED_LINK_OPTIONS)
+ if(HAVE_COVERAGE)
+ # Check for --coverage -fcondition-coverage flag support
+ set(CMAKE_REQUIRED_LINK_OPTIONS -coverage -fcondition-coverage)
+ check_c_compiler_flag("--coverage -fcondition-coverage -Wno-coverage-too-many-conditions" HAVE_CONDITION_COVERAGE)
+ set(CMAKE_REQUIRED_LINK_OPTIONS)
+
+ if(HAVE_CONDITION_COVERAGE)
+ # Both --coverage and -fcondition-coverage supported
+ add_link_options(-coverage -fcondition-coverage)
+ add_compile_options(--coverage -fcondition-coverage -Wno-coverage-too-many-conditions)
+ message(STATUS "Code coverage enabled using: --coverage -fcondition-coverage")
+ else()
+ # Only --coverage supported.
+ add_link_options(-coverage)
+ add_compile_options(--coverage)
+ message(STATUS "Code coverage enabled using: --coverage")
+ endif()
+ else()
+ # Some versions of GCC don't support --coverage shorthand
+ set(CMAKE_REQUIRED_LINK_OPTIONS -lgcov -fprofile-arcs)
+ check_c_compiler_flag("-ftest-coverage -fprofile-arcs" HAVE_TEST_COVERAGE)
+ set(CMAKE_REQUIRED_LINK_OPTIONS)
+
+ if(HAVE_TEST_COVERAGE)
+ add_link_options(-lgcov -fprofile-arcs)
+ add_compile_options(-ftest-coverage -fprofile-arcs)
+ message(STATUS "Code coverage enabled using: -ftest-coverage -fprofile-arcs")
+ else()
+ # Failed to enable coverage, this is fatal to avoid silent failures in CI
+ message(FATAL_ERROR "WITH_CODE_COVERAGE requested, but unable to turn on code coverage with compiler/linker")
+ set(WITH_CODE_COVERAGE OFF)
+ endif()
+ endif()
+
+ # Set optimization level to zero for code coverage builds
+ if (WITH_CODE_COVERAGE)
+ # Use CMake compiler flag variables due to add_compile_options failure on Windows GCC
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
+ endif()
+endmacro()