-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
305 lines (251 loc) · 8.72 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
cmake_minimum_required(VERSION 3.19)
message ("CMAKE VERSION: " "${CMAKE_VERSION}")
project( BaKGL )
# Project wide CXX flags
string(CONCAT CXX_IGNORES
"-Wno-unknown-warning-option "
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105329
"-Wno-restrict "
# std::optional is triggering this a lot
"-Wno-maybe-uninitialized "
# imgui
"-Wno-format-security "
# GCC is overzealous
"-Wno-dangling-reference "
# The usual things I don't worry about
"-Wno-unused-variable "
"-Wno-unused-parameter "
"-Wno-unused-but-set-variable "
"-Wno-unused-private-field "
"-Wno-unused-function "
"-Wno-deprecated-enum-enum-conversion "
# This is currently needed for glm
#glm/gtx/string_cast.inl:25:40: error: comparison of unsigned expression in ‘>= 0’ is always true [-Werror=type-limits]
# 25 | assert(strlen(message) >= 0 && strlen(message) < STRING_BUFFER);
"-Wno-type-limits "
"-Wno-volatile ")
#set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if (MSVC)
# Statically link MSVC runtime
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CXX_IGNORE "/wd4244 /wd4267 /wd4996 /wd4305 /wd4065 /wd4146 /wd4101 /wd4312 /wd4311 /wd4302 /wd4068")
set(CXX_FLAGS "/W3 /WX /EHsc /bigobj")
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_EXE_LINKER_FLAGS "-static")
set(CXX_USAN "")
# MS asan is pretty brutal on performance
set(CXX_ASAN "/fsanitize=address")
set(CXX_ASAN "")
else()
set(CXX_IGNORE ${CXX_IGNORES})
# -ftime-trace" clang build profile
set(CXX_FLAGS "-Wall -Wextra -Werror -Wpedantic")
# FileBuffer violates alignment pretty regularly. Will need to fix at some point
#set(CXX_USAN "-fvisibility=hidden -fsanitize=undefined -fno-sanitize=vptr -fno-sanitize=alignment")
set(CXX_ASAN "-fsanitize=address -fno-omit-frame-pointer")
#set(CXX_TSAN "-fsanitize=thread")
set(CXX_USAN "")
set(CXX_ASAN "")
set(CXX_TSAN "")
endif()
enable_testing()
set(CMAKE_BUILD_TYPE Debug)
set(LSAN_OPTS "LSAN_OPTIONS=suppressions=${CMAKE_SOURCE_DIR}/.lsan.supp")
# --- # --- External Packages --- # --- #
set(ENABLE_CPPTRACE FALSE)
if (ENABLE_CPPTRACE)
include(FetchContent)
FetchContent_Declare(
cpptrace
GIT_REPOSITORY https://github.com/jeremy-rifkin/cpptrace.git
GIT_TAG v0.6.2
)
FetchContent_MakeAvailable(cpptrace)
add_compile_definitions(ENABLE_CPPTRACE)
endif()
# --- OpenGL related packages --- #
find_package(OpenGL REQUIRED)
list(APPEND CMAKE_PREFIX_PATH "C:/Program Files/Common Files/MSVC/freeglut")
find_package(GLUT REQUIRED)
list(APPEND CMAKE_PREFIX_PATH "C:/Program Files/Common Files/MSVC/glew-2.1.0")
find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIR})
include(FetchContent)
# --- GLM --- #
FetchContent_Declare(
glm
GIT_REPOSITORY https://github.com/g-truc/glm
GIT_TAG 0.9.9.8
)
FetchContent_MakeAvailable(glm)
# --- GLFW --- #
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw
GIT_TAG 3.3.9
)
FetchContent_GetProperties(glfw)
if(NOT glfw_POPULATED)
FetchContent_Populate(glfw)
set(GLFW_BUILD_EXAMPLES OFF CACHE INTERNAL "Build the GLFW example programs")
set(GLFW_BUILD_TESTS OFF CACHE INTERNAL "Build the GLFW test programs")
set(GLFW_BUILD_DOCS OFF CACHE INTERNAL "Build the GLFW documentation")
set(GLFW_INSTALL OFF CACHE INTERNAL "Generate installation target")
add_subdirectory(${glfw_SOURCE_DIR} ${glfw_BINARY_DIR})
endif()
if (NOT GLFW3_LIBRARY)
set(GLFW3_LIBRARY glfw)
endif()
include_directories(${GLFW_SOURCE_DIR}/include)
# --- GOOGLETEST --- #
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/release-1.11.0.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
# --- SDL 2 --- #
list(APPEND CMAKE_PREFIX_PATH "C:\\Program Files\\Common Files\\MSVC\\SDL2-2.0.22")
list(APPEND CMAKE_PREFIX_PATH "C:\\Program Files\\Common Files\\MSVC\\SDL2-2.0.22\\lib\\x64")
find_package(SDL2 REQUIRED)
# Required for SDL_mixer or #include "SDL.h" doesn't work
foreach (INCLUDE_DIR IN LISTS SDL2_INCLUDE_DIRS)
include_directories(${INCLUDE_DIR})
message("SDL DIR: " ${INCLUDE_DIR})
endforeach()
message ("SDL LIB: " ${SDL2_LIBRARIES})
# Hack for SDL < 2.0.12
if(NOT TARGET SDL2::SDL2)
add_library(SDL2::SDL2 INTERFACE IMPORTED)
set_target_properties(SDL2::SDL2 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}" "${SDL2_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${SDL2_LIBRARIES}" "${SDL2_LIBRARY}"
)
endif()
if (NOT (TARGET SDL2::SDL2-static))
message ("Didn't find SDL2::SDL2-static, adding dummy target")
add_library(SDL2::SDL2-static ALIAS SDL2::SDL2)
endif()
if(NOT TARGET SDL2::SDL2main)
message ("Didn't find SDL2::SDL2main, adding dummy target")
add_library(SDL2::SDL2main ALIAS SDL2::SDL2)
endif()
# --- AudioCodecs for SDLMixerX --- #
FetchContent_Declare(
AudioCodecs
GIT_REPOSITORY https://github.com/WohlSoft/AudioCodecs
GIT_TAG f299826f4f32e6582c5a2ac363ac2cd963c68d86
)
FetchContent_GetProperties(AudioCodecs)
if(NOT AudioCodecs_POPULATED)
FetchContent_Populate(AudioCodecs)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(CODECS_BUILD_STATIC ON)
set(BUILD_OGG_VORBIS OFF)
set(BUILD_MPG123 OFF)
set(BUILD_FLAC OFF)
set(BUILD_GME OFF)
set(BUILD_TIMIDITYSDL OFF)
set(BUILD_MODPLUG OFF)
set(BUILD_LIBXMP OFF)
set(BUILD_OPUS OFF)
set(BUILD_WAVPACK OFF)
set(BUILD_FLUIDLITE OFF)
set(BUILD_ADLMIDI ON)
set(BUILD_OPNMIDI ON)
set(BUILD_EDMIDI OFF)
endif()
add_subdirectory(${audiocodecs_SOURCE_DIR} ${audiocodecs_BINARY_DIR})
# --- SDL2 Mixer X--- #
FetchContent_Declare(
SDLMixerX
GIT_REPOSITORY https://github.com/WohlSoft/SDL-Mixer-X
GIT_TAG f7d4549e98afd6436791a70c1cf9b79781895dc1
)
FetchContent_GetProperties(SDLMixerX)
if(NOT SDLMixerX_POPULATED)
FetchContent_Populate(SDLMixerX)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(BUILD_SHARED_LIBS OFF)
set(MIXERX_ZLIB FALSE)
set(MIXERX_ENABLE_GPL ON)
set(MIXERX_ENABLE_LGPL ON)
set(SDL_MIXER_X_STATIC ON)
set(SDL_MIXER_X_SHARED OFF)
set(USE_MIDI_ADLMIDI ON)
set(USE_MIDI_OPNMIDI ON)
set(USE_MIDI_FLUIDSYNTH ON)
set(USE_MIDI_FLUIDLITE OFF)
set(USE_MIDI_TIMIDITY OFF)
set(USE_GME OFF)
set(USE_OPUS OFF)
set(USE_MODPLUG OFF)
set(USE_MP3_MPG123 OFF)
set(USE_XMP OFF)
set(USE_SYSTEM_SDL2 ON)
set(USE_SYSTEM_AUDIO_LIBRARIES OFF)
set(DOWNLOAD_AUDIO_CODECS_DEPENDENCY OFF)
set(AUDIO_CODECS_REPO_PATH ${AudioCodecs_SOURCE_DIR})
# libADLMIDI and libOPNMIDI will be placed here to be found by SDLMixerX below...
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/lib)
list(APPEND CMAKE_PREFIX_PATH ${audiocodecs_SOURCE_DIR}/libADLMIDI/include)
list(APPEND CMAKE_PREFIX_PATH ${audiocodecs_SOURCE_DIR}/libOPNMIDI/include)
# Trick SDLMixerX into thinking these libraries exists.
# which they will, they just haven't been compiled yet...
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
file(TOUCH ${CMAKE_BINARY_DIR}/lib/libADLMIDI.a)
file(TOUCH ${CMAKE_BINARY_DIR}/lib/libOPNMIDI.a)
file(TOUCH ${CMAKE_BINARY_DIR}/lib/libADLMIDI.lib)
file(TOUCH ${CMAKE_BINARY_DIR}/lib/libOPNMIDI.lib)
add_subdirectory(${sdlmixerx_SOURCE_DIR} ${sdlmixerx_BINARY_DIR})
file(REMOVE ${CMAKE_BINARY_DIR}/lib/libADLMIDI.a)
file(REMOVE ${CMAKE_BINARY_DIR}/lib/libOPNMIDI.a)
file(REMOVE ${CMAKE_BINARY_DIR}/lib/libADLMIDI.lib)
file(REMOVE ${CMAKE_BINARY_DIR}/lib/libOPNMIDI.lib)
endif()
include_directories(${SDLMixerX_SOURCE_DIR}/include)
link_directories(${SDLMixerX_BINARY_DIR}/lib)
# --- Common Link Libraries --- #
set(LINK_3D_LIBRARIES
${GLEW_LIBRARIES}
glm
${OPENGL_LIBRARY}
${GLFW3_LIBRARY}
)
message ("System: ${CMAKE_SYSTEM}")
if (UNIX)
set(LINK_UNIX_LIBRARIES
m
dl
rt
stdc++
pthread)
endif()
# --- My project CXX flags --- #
set(CMAKE_CXX_FLAGS "${CXX_FLAGS} ${CXX_USAN} ${CXX_ASAN} ${CXX_TSAN} ${CXX_IGNORE}")
set(CMAKE_CXX_STANDARD 23)
# --- Put all binaries in the root of the build dir ---
set(
CMAKE_RUNTIME_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR})
# --- Install Path
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/installed")
include(InstallRequiredSystemLibraries)
# --- My project directories --- #
include_directories(".")
list(APPEND SOURCE_DIRECTORIES
"app"
"audio"
"bak"
"com"
"game"
"graphics"
"gui"
"imgui"
"shaders"
)
foreach (DIR IN LISTS SOURCE_DIRECTORIES)
add_subdirectory(${DIR})
endforeach()