From 9d31a5eb1a56293eb3ce46f5908fd20efaa6a812 Mon Sep 17 00:00:00 2001 From: light7734 Date: Sun, 20 Jul 2025 14:53:58 +0330 Subject: [PATCH] build: add enable_lcov compiler option --- CMakeLists.txt | 12 +++++++++++- conanfile.py | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a88bf5..0c1508b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.14) project(Light) set(CMAKE_CXX_STANDARD 23) +add_option(ENABLE_TESTS "Enables the building of the test modules") include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/functions.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/definitions.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/dependencies.cmake) @@ -11,6 +12,15 @@ if (ENABLE_STATIC_ANALYSIS) set(CMAKE_CXX_CLANG_TIDY "clang-tidy;--warnings-as-errors=*;--allow-no-checks") endif () -add_option(ENABLE_TESTS "Enables the building of the test modules") +add_option(ENABLE_LCOV "Enables the code coverage instrumentation for clang") +if(ENABLE_LCOV) + if (CMAKE_CXX_COMPILER_ID NOT STREQUAL "Clang") + message(FATAL_ERROR "ENABLE_LCOV option is only supported when compiling with clang") + endif () + + add_compile_options(-fprofile-instr-generate -fcoverage-mapping) + add_link_options(-fprofile-instr-generate -fcoverage-mapping) +endif () + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/modules) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/glad) diff --git a/conanfile.py b/conanfile.py index 47348bc..b9e6f07 100644 --- a/conanfile.py +++ b/conanfile.py @@ -12,6 +12,7 @@ class LightRecipe(ConanFile): options = { "enable_tests": [True, False], + "enable_lcov": [True, False], "enable_static_analysis": [True, False], "use_mold": [True, False], "export_compile_commands": [True, False], @@ -19,6 +20,7 @@ class LightRecipe(ConanFile): default_options = { "enable_tests": True, + "enable_lcov": False, "enable_static_analysis": False, "use_mold": False, "export_compile_commands": True, @@ -44,8 +46,9 @@ class LightRecipe(ConanFile): tc.cache_variables["CMAKE_LINKER_TYPE"] = "MOLD" tc.cache_variables["CMAKE_EXPORT_COMPILE_COMMANDS"] = self.options.export_compile_commands - tc.cache_variables["ENABLE_STATIC_ANALYSIS"] = self.options.enable_static_analysis tc.cache_variables["ENABLE_TESTS"] = self.options.enable_tests + tc.cache_variables["ENABLE_LCOV"] = self.options.enable_lcov + tc.cache_variables["ENABLE_STATIC_ANALYSIS"] = self.options.enable_static_analysis repo = git.Repo(search_parent_directories=True) tc.cache_variables["GIT_HASH"] = repo.head.object.hexsha