-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
224 lines (186 loc) · 7.12 KB
/
CMakeLists.txt
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
cmake_minimum_required(VERSION 3.28)
project(Prescriptivism VERSION 0.1.0 LANGUAGES CXX C)
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(FATAL_ERROR "Prescriptivism must be built with Clang 19 or later. Other compilers are not supported.")
endif()
## ============================================================================
## Global CMake Variables.
## ============================================================================
set(CMAKE_CXX_STANDARD 26)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
## ============================================================================
## Global compiler options.
## ============================================================================
## Turn on diagnostics colours.
add_compile_options(-fcolor-diagnostics)
## Use mold as the default linker, if it exists.
find_program(MOLD_LINKER "mold")
if (MOLD_LINKER)
add_link_options(-fuse-ld=mold)
endif()
## ============================================================================
## Compiler options.
## ============================================================================
set(LIBBASE_CXXFLAGS "-fno-exceptions")
add_library(options INTERFACE)
target_compile_options(options INTERFACE
-fms-extensions
-fdeclspec
-ftemplate-backtrace-limit=0
-fno-exceptions
## Warnings.
-Wall -Wextra # Enable ‘all’ warnings.
-Wundef # Invalid #undef or undefined macro in #if.
-Wcast-align # Casting that changes alignment.
-Wconversion # Implicit conversions.
-Wformat=2 # Stricter format checking.
## Disabled warnings.
-Wno-sign-conversion
-Wno-unused-function
-Wno-unused-local-typedefs
-Wno-implicit-int-float-conversion
-Wno-c99-designator
## NULL Errors.
-Werror=nonnull # Passing NULL to nonnull parameter.
## Memory Errors.
-Werror=address # Suspicious use of addresses.
-Werror=init-self # Initialization of a variable with itself.
-Werror=uninitialized
-Werror=return-stack-address
-Werror=dangling
## Return type.
-Werror=return-type
-Wmissing-noreturn
## C/C++.
-Werror=implicit-fallthrough
-Werror=pointer-arith # Disallow void* and function pointer arithmetic.
-Werror=string-compare # Nonsensical string comparisons.
-Werror=switch # Missing switch cases.
# -Werror=switch-enum # Switch on enum (even if there is a default case).
-Werror=write-strings # Strings in C should be const char*.
## C++.
-Werror=missing-field-initializers
-Werror=non-virtual-dtor
-Werror=pessimizing-move
## Optimisation flags.
$<$<CONFIG:DEBUG>:-O0 -g3 -ggdb3>
$<$<CONFIG:RELEASE>:-O3 -march=native>
)
target_link_options(options INTERFACE
$<$<CONFIG:DEBUG>:-O0 -g3 -ggdb3 -rdynamic>
$<$<CONFIG:RELEASE>:-O3 -march=native>
)
if (PRESCRIPTIVISM_ENABLE_SANITISERS)
target_compile_options(options INTERFACE
-fsanitize=undefined,address
)
target_link_options(options INTERFACE
-fsanitize=undefined,address
)
target_compile_definitions(options INTERFACE
-DPRESCRIPTIVISM_ENABLE_SANITISERS=1
)
endif()
target_include_directories(options INTERFACE
"${PROJECT_SOURCE_DIR}/include"
)
## ============================================================================
## Submodules and include dirs.
## ============================================================================
include(FetchContent)
FetchContent_Declare(base
GIT_REPOSITORY https://github.com/Sirraide/libbase
GIT_TAG master
)
FetchContent_Declare(sdl3
GIT_REPOSITORY https://github.com/libsdl-org/SDL
GIT_TAG main
)
FetchContent_Declare(webp
GIT_REPOSITORY https://github.com/webmproject/libwebp
GIT_TAG v1.4.0
)
set(OPTION_BUILD_TOOLS OFF)
set(OPTION_BUILD_EXAMPLES OFF)
FetchContent_Declare(glbinding
GIT_REPOSITORY https://github.com/cginternals/glbinding
GIT_TAG v3.3.0
)
FetchContent_Declare(freetype
GIT_REPOSITORY https://gitlab.freedesktop.org/freetype/freetype
GIT_TAG VER-2-13-3
)
FetchContent_Declare(harfbuzz
GIT_REPOSITORY https://github.com/harfbuzz/harfbuzz
GIT_TAG 10.0.1
)
FetchContent_Declare(glm
GIT_REPOSITORY https://github.com/g-truc/glm
GIT_TAG 1.0.1
)
FetchContent_MakeAvailable(base sdl3 webp glbinding freetype harfbuzz glm)
## ============================================================================
## Tools
## ============================================================================
add_executable(runner tools/DevRunner.cc)
target_link_libraries(runner PRIVATE options libbase)
set_target_properties(runner PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_NAME "start"
)
## ============================================================================
## Shared
## ============================================================================
file(GLOB_RECURSE common_sources src/Shared/*.cc)
file(GLOB_RECURSE common_headers include/Shared/*.hh)
add_library(PrescriptivismShared STATIC ${common_sources})
target_link_libraries(PrescriptivismShared PUBLIC options libbase)
target_sources(PrescriptivismShared PUBLIC FILE_SET HEADERS FILES ${common_headers})
## ============================================================================
## Server
## ============================================================================
file(GLOB_RECURSE server_sources src/Server/*.cc)
file(GLOB_RECURSE server_headers include/Server/*.hh)
add_executable(PrescriptivismServer ${server_sources})
target_sources(PrescriptivismServer PUBLIC FILE_SET HEADERS FILES ${server_headers})
target_link_libraries(PrescriptivismServer PRIVATE
PrescriptivismShared
)
## ============================================================================
## Client
## ============================================================================
file(GLOB_RECURSE client_sources src/Client/*.cc)
file(GLOB_RECURSE client_headers include/Client/*.hh)
add_executable(Prescriptivism ${client_sources})
target_sources(Prescriptivism PUBLIC FILE_SET HEADERS FILES ${client_headers})
target_link_libraries(Prescriptivism PRIVATE
PrescriptivismShared
SDL3::SDL3
glbinding::glbinding
glbinding::glbinding-aux
glm::glm
harfbuzz
freetype
webp
)
target_compile_options(Prescriptivism PRIVATE
"--embed-dir=${PROJECT_SOURCE_DIR}/assets"
-Wno-c23-extensions
)
## Allow overriding the default font w/o having to make it part of the project;
## the path must be absolute or relative to the assets directory.
if (NOT DEFINED PRESCRIPTIVISM_DEFAULT_FONT_PATH)
set(PRESCRIPTIVISM_DEFAULT_FONT_PATH "NotoSans-Medium.ttf")
endif()
target_compile_definitions(Prescriptivism PRIVATE
"PRESCRIPTIVISM_DEFAULT_FONT_PATH=\"${PRESCRIPTIVISM_DEFAULT_FONT_PATH}\""
)
set_target_properties(Prescriptivism PROPERTIES
WIN32_EXECUTABLE ON
)
## ============================================================================
## Shared Properties
## ============================================================================
set_target_properties(PrescriptivismServer Prescriptivism PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}"
)