summaryrefslogtreecommitdiff
path: root/cmake/compiler.cmake
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2026-02-02 22:50:17 +0100
committerSander Vrijders <sander@ouroboros.rocks>2026-02-04 08:17:24 +0100
commit4c64d7daef8819d644ab78a911067b16943f023d (patch)
tree7545488b224d510017f08a99006d9949367a9d77 /cmake/compiler.cmake
parentb1687570df3e080c961cdcc0d59b708cfbdf955e (diff)
downloadouroboros-4c64d7daef8819d644ab78a911067b16943f023d.tar.gz
ouroboros-4c64d7daef8819d644ab78a911067b16943f023d.zip
build: Refactor CMake back to in-tree CMakeListsbe
This moves the build definitions back to src/ subdirectories (CMakeLists.txt per component). Configuration and dependencies are kept out of tree. Configuration options are bundled into cmake/config/ modules. Dependencies are grouped by component (system/, crypt/, eth/, coverage/, etc.). It now consistently uses target-based commands (target_include_directories, target_link_libraries) instead of global include_directories(). Proper PRIVATE/PUBLIC visibility for executable link libraries. CONFIG_OUROBOROS_DEBUG now properly set based on being a valid debug config (not just checking the string name). It also adds OuroborosTargets export for find_package() support and CMake package config files (OuroborosConfig.cmake) for easier integration with CMake projects. The build logic now follows more idiomatic CMake practices with configuration separated from target definitions. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'cmake/compiler.cmake')
-rw-r--r--cmake/compiler.cmake38
1 files changed, 15 insertions, 23 deletions
diff --git a/cmake/compiler.cmake b/cmake/compiler.cmake
index 6258cca0..5d452e02 100644
--- a/cmake/compiler.cmake
+++ b/cmake/compiler.cmake
@@ -31,42 +31,34 @@ test_and_set_c_compiler_flag_global(-Wdeclaration-after-statement)
test_and_set_c_compiler_flag_global(-Winfinite-recursion)
test_and_set_c_compiler_flag_global(-fmax-errors=5)
-set(DISABLE_COVERAGE ON CACHE BOOL "Disable code coverage analysis")
-
-if (NOT DISABLE_COVERAGE)
- test_and_set_c_compiler_flag_global(-g)
- test_and_set_c_compiler_flag_global(--coverage)
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
- set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
- set(ENABLE_COVERAGE ON)
-else()
- set(ENABLE_COVERAGE OFF)
-endif()
-
-if (NOT CMAKE_BUILD_TYPE)
+if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Build type (Release, Debug, DebugASan, DebugTSan, DebugLSan, DebugUSan, DebugAnalyzer)" FORCE)
endif()
-if (CMAKE_BUILD_TYPE STREQUAL "Release")
+if(CMAKE_BUILD_TYPE STREQUAL "Release")
test_and_set_c_compiler_flag_global(-O3)
-elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
+elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
test_and_set_c_compiler_flag_global(-g)
-elseif (CMAKE_BUILD_TYPE STREQUAL "DebugASan")
+elseif(CMAKE_BUILD_TYPE STREQUAL "DebugASan")
test_and_set_c_compiler_flag_global(-g)
test_and_set_c_compiler_flag_global(-fsanitize=address)
-elseif (CMAKE_BUILD_TYPE STREQUAL "DebugTSan")
+ add_link_options(-fsanitize=address)
+elseif(CMAKE_BUILD_TYPE STREQUAL "DebugTSan")
test_and_set_c_compiler_flag_global(-g)
test_and_set_c_compiler_flag_global(-fsanitize=thread)
-elseif (CMAKE_BUILD_TYPE STREQUAL "DebugLSan")
+ add_link_options(-fsanitize=thread)
+elseif(CMAKE_BUILD_TYPE STREQUAL "DebugLSan")
test_and_set_c_compiler_flag_global(-g)
test_and_set_c_compiler_flag_global(-fsanitize=leak)
-elseif (CMAKE_BUILD_TYPE STREQUAL "DebugUSan")
+ add_link_options(-fsanitize=leak)
+elseif(CMAKE_BUILD_TYPE STREQUAL "DebugUSan")
test_and_set_c_compiler_flag_global(-g)
test_and_set_c_compiler_flag_global(-fsanitize=undefined)
-elseif (CMAKE_BUILD_TYPE STREQUAL "DebugAnalyzer")
+ add_link_options(-fsanitize=undefined)
+elseif(CMAKE_BUILD_TYPE STREQUAL "DebugAnalyzer")
test_and_set_c_compiler_flag_global(-g)
test_and_set_c_compiler_flag_global(-fanalyzer)
-else ()
- message(FATAL_ERROR "Unkown build type ${CMAKE_BUILD_TYPE}")
-endif ()
+else()
+ message(FATAL_ERROR "Unknown build type ${CMAKE_BUILD_TYPE}")
+endif()