blob: b9f4d70b9d05cf3b95955622c9d1c5c2f00b10da (
plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
cmake_minimum_required(VERSION 3.24)
project(daw VERSION 0.0.1 LANGUAGES C)
# We really don't want any in-source builds
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON CACHE BOOL "Prevents cmake -S. -B.")
set(CMAKE_DISABLE_SOURCE_CHANGES ON CACHE BOOL "Prevent writing files to CMAKE_SOURCE_DIR under configure")
# Check if we are used as a sub project/module or not
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(NOT_SUBPROJECT ON)
else()
set(NOT_SUBPROJECT OFF)
endif()
include(CMakeDependentOption)
option(ASAN "Enable address sanitizer. Only enabled when DAW_BUILD_DEBUG=ON")
option(UBSAN "Enable undefined behaviour sanitizer. Only enabled when DAW_BUILD_DEBUG=ON")
cmake_dependent_option(DAW_BUILD_DEBUG
"Compile daw engine with debugging features" ON
"CMAKE_BUILD_TYPE STREQUAL Debug" OFF)
cmake_dependent_option(DAW_BUILD_HOTRELOAD
"Compile daw engine with hot reloading enabled" ON
"NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME;CMAKE_BUILD_TYPE STREQUAL Debug;NOT WIN32;BUILD_SHARED_LIBS" OFF)
cmake_dependent_option(DAW_BUILD_ASAN
"Compile daw engine with address sanitizer (asan)" ON
"DAW_BUILD_DEBUG;ASAN" OFF)
cmake_dependent_option(DAW_BUILD_UBSAN
"Compile daw engine with undefined behaviour sanitizer (ubsan)" ON
"DAW_BUILD_DEBUG;UBSAN" OFF)
# unused
cmake_dependent_option(DAW_BUILD_TOOLS
"Build tools to manipulate a daw project" ON
"CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME" OFF)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
message("Enabling LTO")
set(${CMAKE_INTERPROCEDURAL_OPTIMIZATION} TRUE)
endif()
if(DAW_BUILD_DEBUG AND NOT_SUBPROJECT)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()
if(DAW_BUILD_UBSAN AND DAW_BUILD_ASAN)
message(FATAL_ERROR "You cannot build both asan and ubsan")
endif()
if(DAW_BUILD_DEBUG)
set(BUILD_OPTS -Og -ggdb3 -fno-omit-frame-pointer)
else()
set(BUILD_OPTS -O2 -flto=auto -fuse-linker-plugin -ffat-lto-objects
-funroll-loops -ffast-math -fno-signed-zeros -fno-trapping-math
-ffunction-sections -fdata-sections)
endif()
##
set(ENGINE_SOURCES
src/btree.c
src/dltools.c
src/engine.c
src/fov.c
src/hashmap.c
src/input.c
src/logging.c
src/memory.c
src/rendering.c
src/stack.c
src/state.c
src/ui_positioning.c
src/ui_rendering.c
src/utils.c
src/vector.c
)
add_compile_options(${RELEASE_OPTS})
add_link_options(${RELEASE_OPTS})
add_library(daw
${ENGINE_SOURCES})
target_include_directories(daw PUBLIC
include ${CMAKE_BINARY_DIR}/include ${ENGINE_INCLUDE})
target_link_libraries(${PROJECT_NAME}
SDL2 SDL2_image SDL2_ttf
$<$<NOT:$<PLATFORM_ID:Windows>>:m>
$<$<BOOL:${DAW_BUILD_HOTRELOAD}>:dl>
$<$<AND:$<NOT:$<C_COMPILER_ID:MSVC>>,$<BOOL:${DAW_BUILD_UBSAN}>>:ubsan>
)
target_compile_features(${PROJECT_NAME} PRIVATE c_std_99)
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)
if(DAW_BUILD_ASAN AND NOT C_COMPILER_ID STREQUAL MSVC)
add_compile_options(-fsanitize=address -fsanitize=leak -fsanitize-address-use-after-scope)
add_link_options(-fsanitize=address -fsanitize=leak -fsanitize-address-use-after-scope)
endif()
if(DAW_BUILD_UBSAN AND NOT C_COMPILER_ID STREQUAL MSVC)
add_compile_options(-fsanitize=undefined -fsanitize-undefined-trap-on-error -fno-sanitize-recover)
add_link_options(-fsanitize=undefined -fsanitize-undefined-trap-on-error -fno-sanitize-recover)
endif()
target_compile_options(${PROJECT_NAME} PUBLIC
$<$<NOT:$<C_COMPILER_ID:MSVC>>:-Wall -Wextra>
# Dont be pedantic when using hot reloading.
$<$<AND:$<NOT:$<C_COMPILER_ID:MSVC>>,$<NOT:$<BOOL:${DAW_BUILD_HOTRELOAD}>>>:-pedantic>
$<$<C_COMPILER_ID:MSVC>:/W4>
# Debug related flags. sorry windows, you're just not that important.
)
target_compile_definitions(${PROJECT_NAME} PUBLIC
$<$<BOOL:${DAW_BUILD_DEBUG}>:_DEBUG>
$<$<BOOL:${DAW_BUILD_HOTRELOAD}>:DAW_BUILD_HOTRELOAD>
)
configure_file(${CMAKE_CURRENT_LIST_DIR}/tools/cmake/list_of_states.h.in
${CMAKE_BINARY_DIR}/include/states/list_of_states.h)
configure_file(${CMAKE_CURRENT_LIST_DIR}/tools/cmake/all_states.h.in
${CMAKE_BINARY_DIR}/include/states/all_states.h)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/tools/cmake")
if (NOT NOT_SUBPROJECT)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
endif()
include(DawAddState)
message("Configured ${PROJECT_NAME} ${PROJECT_VERSION}")
message("Build type: ${CMAKE_BUILD_TYPE}")
message("enable debug: ${DAW_BUILD_DEBUG}")
message("enable hotreload: ${DAW_BUILD_HOTRELOAD}")
message("enable asan: ${DAW_BUILD_ASAN}")
message("enable ubsan: ${DAW_BUILD_UBSAN}")
message("build tools: ${DAW_BUILD_TOOLS}")
|