-
Notifications
You must be signed in to change notification settings - Fork 80
/
CMakeLists.txt
335 lines (288 loc) · 9.82 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# BEGIN CMake setup
# 3.12 added add_compile_definitions
cmake_minimum_required(VERSION 3.12)
if(DEFINED ENV{CXX})
message("")
message("We do not support injecting a compiler in via ENV.")
message("")
message(
FATAL_ERROR
"CXX is set on the ENV. Please only use the the flag '-D CMAKE_CXX_COMPILER='."
)
endif()
# Default to debug builds
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
# Default to dynamic linking
if(NOT CMAKE_LINK_TYPE)
set(CMAKE_LINK_TYPE Dynamic)
endif()
# Use vcpkg for static builds
if (CMAKE_LINK_TYPE MATCHES Static)
set(CMAKE_TOOLCHAIN_FILE ./vcpkg/scripts/buildsystems/vcpkg.cmake)
endif()
# Default to using LTO for Release builds
if (CMAKE_BUILD_TYPE MATCHES Release)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
# Include repo local modules
set(
CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake-includes/modules"
)
# END CMake setup
# BEGIN Project config
# Build target for CXX project "anura"
project(anura LANGUAGES CXX)
# Use ccache to accelerate iterating on CXX files, if available
find_program(CCACHE "ccache")
if(CCACHE)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE}")
endif(CCACHE)
# Add the source code
file(
GLOB
anura_SRC
"${CMAKE_CURRENT_LIST_DIR}/src/*.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/hex/*.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/imgui/imgui_draw.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/imgui/imgui_tables.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/imgui/imgui_widgets.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/imgui/imgui.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/imgui_additions/*.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/kre/*.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/svg/*.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/tiled/*.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/treetree/*.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/xhtml/*.cpp"
)
# Configure compiling against system provided libraries
# XXX - At the moment (2023-08) we have no idea of the upper and lower bounds
# XXX - At the moment (2023-08) we have no idea of the full minimal set
# https://cmake.org/cmake/help/v3.12/module/FindThreads.html
find_package(Threads REQUIRED)
# https://cmake.org/cmake/help/v3.12/module/FindBoost.html
find_package(Boost REQUIRED COMPONENTS filesystem locale regex system)
# https://cmake.org/cmake/help/v3.12/module/FindZLIB.html
find_package(ZLIB REQUIRED)
# https://cmake.org/cmake/help/v3.12/module/FindOpenGL.html
find_package(OpenGL REQUIRED)
# https://cmake.org/cmake/help/v3.12/module/FindGLEW.html
find_package(GLEW REQUIRED)
# https://cmake.org/cmake/help/v3.12/module/FindFreetype.html
find_package(Freetype REQUIRED)
# https://github.com/assimp/assimp/blob/60989a598e2eec923612597b1516604b816d404a/cmake-modules/FindRT.cmake
find_package(RT REQUIRED)
# https://chromium.googlesource.com/external/github.com/g-truc/glm/+/refs/heads/0.9.6/util/FindGLM.cmake
find_package(GLM REQUIRED)
# https://github.com/tcbrindle/sdl2-cmake-scripts/blob/e037fb54f32973343fada6a051d3a3f8adf3a4a0/FindSDL2.cmake
find_package(SDL2 REQUIRED)
# https://github.com/tcbrindle/sdl2-cmake-scripts/blob/e037fb54f32973343fada6a051d3a3f8adf3a4a0/FindSDL2_image.cmake
find_package(SDL2_image REQUIRED)
# https://github.com/tcbrindle/sdl2-cmake-scripts/blob/e037fb54f32973343fada6a051d3a3f8adf3a4a0/FindSDL2_mixer.cmake
find_package(SDL2_mixer REQUIRED)
# https://github.com/tcbrindle/sdl2-cmake-scripts/blob/e037fb54f32973343fada6a051d3a3f8adf3a4a0/FindSDL2_ttf.cmake
find_package(SDL2_ttf REQUIRED)
# https://github.com/libsndfile/libsndfile/blob/ec104e3631a06c4a16f5cbae93b4af2c554fab20/cmake/FindOgg.cmake
find_package(Ogg REQUIRED)
# https://github.com/libsndfile/libsndfile/blob/ec104e3631a06c4a16f5cbae93b4af2c554fab20/cmake/FindVorbis.cmake
find_package(Vorbis REQUIRED)
# https://github.com/WebKit/WebKit/blob/acece69bd261c37f0a66d82d4abc80bed8b09bd7/Source/cmake/FindCairo.cmake
find_package(Cairo REQUIRED)
if (CMAKE_LINK_TYPE MATCHES Static)
find_package(harfbuzz CONFIG REQUIRED)
find_package(WebP CONFIG REQUIRED)
find_package(unofficial-lerc CONFIG REQUIRED)
find_package(zstd CONFIG REQUIRED)
endif()
# Add the headers
if (CMAKE_LINK_TYPE MATCHES Static)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)
include_directories(
"${CMAKE_CURRENT_LIST_DIR}/src"
"${CMAKE_CURRENT_LIST_DIR}/src/hex"
"${CMAKE_CURRENT_LIST_DIR}/src/imgui"
"${CMAKE_CURRENT_LIST_DIR}/src/imgui_additions"
"${CMAKE_CURRENT_LIST_DIR}/src/kre"
"${CMAKE_CURRENT_LIST_DIR}/src/svg"
"${CMAKE_CURRENT_LIST_DIR}/src/tiled"
"${CMAKE_CURRENT_LIST_DIR}/src/treetree"
"${CMAKE_CURRENT_LIST_DIR}/src/xhtml"
"${CMAKE_CURRENT_LIST_DIR}/vcpkg_installed/x64-linux/include"
)
else()
# XXX - Unknown as of 2023-08 why only Freetype ft2build and SLD2 are needed
include_directories(
"${CMAKE_CURRENT_LIST_DIR}/src"
"${CMAKE_CURRENT_LIST_DIR}/src/hex"
"${CMAKE_CURRENT_LIST_DIR}/src/imgui"
"${CMAKE_CURRENT_LIST_DIR}/src/imgui_additions"
"${CMAKE_CURRENT_LIST_DIR}/src/kre"
"${CMAKE_CURRENT_LIST_DIR}/src/svg"
"${CMAKE_CURRENT_LIST_DIR}/src/tiled"
"${CMAKE_CURRENT_LIST_DIR}/src/treetree"
"${CMAKE_CURRENT_LIST_DIR}/src/xhtml"
"${FREETYPE_INCLUDE_DIR_ft2build}"
"${SDL2_INCLUDE_DIR}"
)
endif()
# END Project config
# BEGIN Compiler config
# Good things, to keep
# Set C++ standard to C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Turn off (GNU) extensions (-std=c++17 vs. -std=gnu++17)
set(CMAKE_CXX_EXTENSIONS OFF)
if (CMAKE_BUILD_TYPE MATCHES Debug)
# Debug builds need to be debuggable
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og")
set(VCPKG_TARGET_TRIPLET x64-linux-dbg)
set(VCPKG_BUILD_TYPE debug)
link_directories("${CMAKE_CURRENT_LIST_DIR}/vcpkg_installed/x64-linux/debug/lib")
endif()
if (CMAKE_BUILD_TYPE MATCHES Release)
# Optimize release builds
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
set(VCPKG_TARGET_TRIPLET x64-linux-rel)
set(VCPKG_BUILD_TYPE release)
link_directories("${CMAKE_CURRENT_LIST_DIR}/vcpkg_installed/x64-linux/release/lib")
endif()
# Warnings as errors
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
# Enable all compiler warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
# Enable extra compiler warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
# Enable pedantic compiler warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
# Inject our own imgui config for our own vector operations
add_compile_definitions(IMGUI_USER_CONFIG="${CMAKE_CURRENT_LIST_DIR}/src/imgui_additions/imconfig_anura.h")
if (CMAKE_BUILD_TYPE MATCHES Release)
# Turn all things debug, like assertions, off for a release build
add_compile_definitions(NDEBUG)
endif()
# Bad things, to get rid of
# Use imgui provided vector math
# XXX - imgui_custom.cpp relies on these
add_compile_definitions(IMGUI_DEFINE_MATH_OPERATORS)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Older compilers should not trip up when we selectively silence warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option")
endif()
# We need to hide a ton of warnings
include("${CMAKE_CURRENT_LIST_DIR}/cmake-includes/silence-warnings/CMakeLists.txt")
# END Compiler config
# BEGIN Linker config
# Output an executable from the anura sources for anura
add_executable(anura "${anura_SRC}")
# Link libraries
# XXX - The order of the static linking matters!
# XXX - The grouping of the static linking matters!
# XXX - DO NOT BUMP VCPKG BASELINE - ANURA CODE CHANGES REQUIRED FIRST!
# XXX - Some stuff is simply not staticly linkable:
# - Audio stuff (samplerate, ALSA, Pulseaudio)
# - Graphics stuff (OpenGL, EGL, DRM, GBM)
# - X11
# - Wayland
# - libc (with: realtme, dlopen)
#
# We must YOLO and trust the platform has these things
if (CMAKE_LINK_TYPE MATCHES Static)
target_link_libraries(
anura
PRIVATE
-Wl,-Bstatic
-Wl,--start-group
SDL2
-Wl,--end-group
-Wl,--start-group
Boost::filesystem
-Wl,--end-group
-Wl,--start-group
cairo
pixman-1
freetype
ZLIB::ZLIB
fontconfig
png
expat
brotlidec
brotlicommon
uuid
# XXX - For whatever reason on Debian Bookworm you have to add the below
# jbig
-Wl,--end-group
-Wl,--start-group
GLEW::GLEW
-Wl,--end-group
-Wl,--start-group
vorbisfile
vorbis
ogg
-Wl,--end-group
-Wl,--start-group
SDL2_ttf
harfbuzz::harfbuzz
-Wl,--end-group
-Wl,--start-group
Boost::locale
-Wl,--end-group
-Wl,--start-group
SDL2_image
WebP::webp
WebP::webpdemux
WebP::webpdecoder
tiff
lzma
deflate
WebP::webp
jpeg
unofficial::Lerc::Lerc
zstd::libzstd_static
-Wl,--end-group
-Wl,-Bdynamic
-lrt
-ldl
-ldrm
-lgbm
-lX11
-lXcursor
-lXext
-lXfixes
-lXi
-lXrandr
-lXss
-lxkbcommon
-ldecor-0
-lwayland-client
-lwayland-cursor
-lwayland-egl
-lsamplerate
-lasound
-lpulse
)
else()
target_link_libraries(
anura
PRIVATE
"${RT_LIBRARIES}"
"${CMAKE_THREAD_LIBS_INIT}"
"${Boost_LIBRARIES}"
"${ZLIB_LIBRARIES}"
"${OPENGL_LIBRARIES}"
"${GLEW_LIBRARIES}"
"${FREETYPE_LIBRARIES}"
"${SDL2_LIBRARY}"
"${SDL2_IMAGE_LIBRARIES}"
"${SDL2_MIXER_LIBRARIES}"
"${SDL2_TTF_LIBRARIES}"
"${Vorbis_File_LIBRARY}"
"${Cairo_LIBRARIES}"
)
endif()
# END Linker config