-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompilerFlag.cmake
More file actions
59 lines (50 loc) · 2.24 KB
/
CompilerFlag.cmake
File metadata and controls
59 lines (50 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# CompilerFlag.cmake — CFBox compiler/flag configuration
include_guard()
# ── Build options ──────────────────────────────────────────────
option(CFBOX_OPTIMIZE_FOR_SIZE "Use -Os instead of -O2 for Release builds" OFF)
option(CFBOX_STATIC_LINK "Link cfbox statically (-static)" OFF)
# ── C++ standard ──────────────────────────────────────────────
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# ── Common warning flags (GCC / Clang) ────────────────────────
add_library(cfbox_compiler_flags INTERFACE)
target_compile_options(cfbox_compiler_flags INTERFACE
-Wall -Wextra -Wpedantic -Werror
-Wconversion
-Wshadow
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-align
-Wunused
-Woverloaded-virtual
-Wmisleading-indentation
-Wnull-dereference
-Wdouble-promotion
-Wformat=2
)
# ── Debug-specific flags ──────────────────────────────────────
target_compile_options(cfbox_compiler_flags INTERFACE
$<$<CONFIG:Debug>:-g3 -O0 -fno-omit-frame-pointer>
$<$<CONFIG:Debug>:-fsanitize=address,undefined>
$<$<CONFIG:Debug>:-fno-sanitize-recover=all>
)
target_link_options(cfbox_compiler_flags INTERFACE
$<$<CONFIG:Debug>:-fsanitize=address,undefined>
)
# ── Release-specific flags ────────────────────────────────────
if(CFBOX_OPTIMIZE_FOR_SIZE)
target_compile_options(cfbox_compiler_flags INTERFACE
$<$<CONFIG:Release>:-Os -DNDEBUG>
$<$<CONFIG:Release>:-flto>
)
else()
target_compile_options(cfbox_compiler_flags INTERFACE
$<$<CONFIG:Release>:-O2 -DNDEBUG>
$<$<CONFIG:Release>:-flto>
)
endif()
# ── Static linking ────────────────────────────────────────────
if(CFBOX_STATIC_LINK)
target_link_options(cfbox_compiler_flags INTERFACE -static)
endif()