From fa8a1c53b4ea555a89d2728f67834c18ceb65114 Mon Sep 17 00:00:00 2001 From: light7734 Date: Sun, 21 Sep 2025 14:29:19 +0330 Subject: [PATCH] build: refactor cmake options out of root CMakeLists.txt --- CMakeLists.txt | 39 +++------------------------------------ tools/cmake/options.cmake | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 36 deletions(-) create mode 100644 tools/cmake/options.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 10c4085..4f5e47b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,41 +1,8 @@ cmake_minimum_required(VERSION 3.14) project(Light) -set(CMAKE_CXX_STANDARD 23) -set(CMAKE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake) -include(CheckCXXSourceCompiles) -include(${CMAKE_DIR}/functions.cmake) -include(${CMAKE_DIR}/definitions.cmake) - -add_option(ENABLE_UNIT_TESTS "Enables the building of the unit test modules") -add_option(ENABLE_FUZZ_TESTS "Enables the building of the fuzz test modules") - -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_LLVM_COVERAGE "Enables the code coverage instrumentation for clang") -if(ENABLE_LLVM_COVERAGE) - if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "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 () +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/options.cmake) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/modules) diff --git a/tools/cmake/options.cmake b/tools/cmake/options.cmake new file mode 100644 index 0000000..c3b1dd3 --- /dev/null +++ b/tools/cmake/options.cmake @@ -0,0 +1,32 @@ +add_option(ENABLE_UNIT_TESTS "Enables the building of the unit test modules") +add_option(ENABLE_FUZZ_TESTS "Enables the building of the fuzz test modules") +add_option(ENABLE_STATIC_ANALYSIS "Makes the clang-tidy checks mandatory for compilation") +add_option(ENABLE_LLVM_COVERAGE "Enables the code coverage instrumentation for clang") + +if (ENABLE_STATIC_ANALYSIS) + set(CMAKE_CXX_CLANG_TIDY "clang-tidy;--warnings-as-errors=*;--allow-no-checks") +endif () + +if(ENABLE_LLVM_COVERAGE) + include(CheckCXXSourceCompiles) + + if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "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 ()