diff options
| author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2025-12-23 11:59:45 +0100 |
|---|---|---|
| committer | Sander Vrijders <sander@ouroboros.rocks> | 2026-01-07 10:00:06 +0100 |
| commit | 48c294105f5123dc876fbad199ec1e0166d82a18 (patch) | |
| tree | c49ce8ac75a7d63c10ea1ff960eeff750c680a8e /cmake/compiler.cmake | |
| parent | 145be13e8c18fcb39476d8f65fed23d82320f22f (diff) | |
| download | ouroboros-48c294105f5123dc876fbad199ec1e0166d82a18.tar.gz ouroboros-48c294105f5123dc876fbad199ec1e0166d82a18.zip | |
build: Refactor CMake modules
This moves the CMake build logic out of the source tree and splits it
up into a more modular form. The tests now have a CMakeLists.txt file
in their respective source directory.
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.cmake | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/cmake/compiler.cmake b/cmake/compiler.cmake new file mode 100644 index 00000000..4fa0e2ea --- /dev/null +++ b/cmake/compiler.cmake @@ -0,0 +1,60 @@ +include(utils/CompilerUtils) + +test_and_set_c_compiler_flag_global(-std=c89) +test_and_set_c_compiler_flag_global(-Wall) +# -Wextra may fail on clobbered warning due to pthread_cleanup +test_and_set_c_compiler_flag_global(-Wno-clobbered) +test_and_set_c_compiler_flag_global(-Wextra) +# explicitly add other flags in -Wextra +test_and_set_c_compiler_flag_global(-Wempty-body) +test_and_set_c_compiler_flag_global(-Wignored-qualifiers) +test_and_set_c_compiler_flag_global(-Wimplicit-fallthrough=4) +test_and_set_c_compiler_flag_global(-Wmissing-field-initializers) +test_and_set_c_compiler_flag_global(-Wmissing-parameter-type) +test_and_set_c_compiler_flag_global(-Wold-style-declaration) +test_and_set_c_compiler_flag_global(-Woverride-init) +test_and_set_c_compiler_flag_global(-Wsign-compare) +test_and_set_c_compiler_flag_global(-Wtype-limits) +test_and_set_c_compiler_flag_global(-Wuninitialized) +test_and_set_c_compiler_flag_global(-Wshift-negative-value) +test_and_set_c_compiler_flag_global(-Wunused-parameter) +test_and_set_c_compiler_flag_global(-Wunused-but-set-parameter) +test_and_set_c_compiler_flag_global(-Werror) +test_and_set_c_compiler_flag_global(-Wundef) +test_and_set_c_compiler_flag_global(-Wpointer-arith) +test_and_set_c_compiler_flag_global(-Wstrict-prototypes) +test_and_set_c_compiler_flag_global(-Wvla) +test_and_set_c_compiler_flag_global(-Wswitch-default) +test_and_set_c_compiler_flag_global(-Wreturn-type) +test_and_set_c_compiler_flag_global(-Wunreachable-code) +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) + +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") + test_and_set_c_compiler_flag_global(-O3) +elseif (CMAKE_BUILD_TYPE STREQUAL "Debug") + test_and_set_c_compiler_flag_global(-g) +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") + test_and_set_c_compiler_flag_global(-g) + test_and_set_c_compiler_flag_global(-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") + test_and_set_c_compiler_flag_global(-g) + test_and_set_c_compiler_flag_global(-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 () |
