From 6d41482576e614fbb8c821ba4a729534df8713c0 Mon Sep 17 00:00:00 2001 From: light7734 Date: Mon, 21 Jul 2025 12:29:29 +0330 Subject: [PATCH] build: minor refactors --- CMakeLists.txt | 29 ++++++++++++++++++++++------- conanfile.py | 6 +++--- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c1508b..19da931 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,23 +1,38 @@ cmake_minimum_required(VERSION 3.14) project(Light) set(CMAKE_CXX_STANDARD 23) +set(CMAKE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake) + +include(${CMAKE_DIR}/functions.cmake) +include(${CMAKE_DIR}/definitions.cmake) +include(${CMAKE_DIR}/dependencies.cmake) 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) -add_option(ENABLE_STATIC_ANALYSIS "Performs static analysis via clang-tidy and fails build on failing checks") +add_option(ENABLE_STATIC_ANALYSIS "Makes clang-tidy checks mandatory for compilation") if (ENABLE_STATIC_ANALYSIS) set(CMAKE_CXX_CLANG_TIDY "clang-tidy;--warnings-as-errors=*;--allow-no-checks") endif () -add_option(ENABLE_LCOV "Enables the code coverage instrumentation for clang") -if(ENABLE_LCOV) +add_option(ENABLE_LLVM_COVERAGE "Enables the code coverage instrumentation for clang") +if(ENABLE_LLVM_COVERAGE) if (CMAKE_CXX_COMPILER_ID NOT STREQUAL "Clang") - message(FATAL_ERROR "ENABLE_LCOV option is only supported when compiling with clang") + message(FATAL_ERROR "ENABLE_LLVM_COVERAGE only supports the clang compiler") endif () + # Check for libc++ + check_cxx_source_compiles(" + #include + #ifdef _LIBCPP_VERSION + int main() { return 0; } + #else + #error Not using libc++ + #endif + " USING_LIBCXX) + if(NOT USING_LIBCXX) + message(FATAL_ERROR "ENABLE_LLVM_COVERAGE requires libc++, please compile with -stdlib=libc++") + endif() + add_compile_options(-fprofile-instr-generate -fcoverage-mapping) add_link_options(-fprofile-instr-generate -fcoverage-mapping) endif () diff --git a/conanfile.py b/conanfile.py index b9e6f07..18e21bc 100644 --- a/conanfile.py +++ b/conanfile.py @@ -12,7 +12,7 @@ class LightRecipe(ConanFile): options = { "enable_tests": [True, False], - "enable_lcov": [True, False], + "enable_llvm_coverage": [True, False], "enable_static_analysis": [True, False], "use_mold": [True, False], "export_compile_commands": [True, False], @@ -20,7 +20,7 @@ class LightRecipe(ConanFile): default_options = { "enable_tests": True, - "enable_lcov": False, + "enable_llvm_coverage": False, "enable_static_analysis": False, "use_mold": False, "export_compile_commands": True, @@ -47,7 +47,7 @@ class LightRecipe(ConanFile): tc.cache_variables["CMAKE_EXPORT_COMPILE_COMMANDS"] = self.options.export_compile_commands tc.cache_variables["ENABLE_TESTS"] = self.options.enable_tests - tc.cache_variables["ENABLE_LCOV"] = self.options.enable_lcov + tc.cache_variables["ENABLE_LLVM_COVERAGE"] = self.options.enable_llvm_coverage tc.cache_variables["ENABLE_STATIC_ANALYSIS"] = self.options.enable_static_analysis repo = git.Repo(search_parent_directories=True)