-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
324 lines (260 loc) · 10.9 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
cmake_minimum_required(VERSION 3.16.3 FATAL_ERROR)
# SETUP UTILS
include("cmake/rawrbox_utils.cmake")
# -----
# SETUP CPM -----
include("cmake/cpm.cmake")
# ---------------
# Versioning
set(RAWRBOX_VERSION_MAJOR 2 CACHE STRING "major version" FORCE)
set(RAWRBOX_VERSION_MINOR 4 CACHE STRING "minor version" FORCE)
set(RAWRBOX_VERSION_PATCH 0 CACHE STRING "patch version" FORCE)
set(RAWRBOX_VERSION ${RAWRBOX_VERSION_MAJOR}.${RAWRBOX_VERSION_MINOR}.${RAWRBOX_VERSION_PATCH} CACHE STRING "version" FORCE)
project("RAWRBOX" VERSION ${RAWRBOX_VERSION} DESCRIPTION "Game engine - By edunad" LANGUAGES C CXX)
# ---
# Fix cmake paths
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(PREPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
# ---
# OPTIONS ---
option(RAWRBOX_USE_WAYLAND "Use Wayland for linux" OFF)
# Build -----
option(RAWRBOX_BUILD_TESTING "Build tests" OFF)
option(RAWRBOX_BUILD_SAMPLES "Build samples" OFF)
option(RAWRBOX_BUILD_RAWRBOX_RENDER "Build rawrbox renderer, disable for renderless programs" ON)
option(RAWRBOX_BUILD_RAWRBOX_UI "Build rawrbox UI" OFF)
option(RAWRBOX_BUILD_RAWRBOX_RESOURCES "Build rawrbox resources utils" OFF)
option(RAWRBOX_BUILD_RAWRBOX_3D_PHYSICS "Build 3D physics support" OFF)
option(RAWRBOX_BUILD_RAWRBOX_2D_PHYSICS "Build 2D physics support" OFF)
option(RAWRBOX_BUILD_RAWRBOX_BASS "Build bass & add sound loading support" OFF)
option(RAWRBOX_BUILD_RAWRBOX_GLTF "Build gltf model loading support" OFF)
option(RAWRBOX_BUILD_RAWRBOX_WEBM "Build libwebm & add video loading support" OFF)
option(RAWRBOX_BUILD_RAWRBOX_NETWORK "Build network support" OFF)
option(RAWRBOX_BUILD_RAWRBOX_SCRIPTING "Build lua & mod support" OFF)
option(RAWRBOX_SCRIPTING_UNSAFE "Enable unsafe scripting (io / etc)" OFF)
option(RAWRBOX_SCRIPTING_WORKSHOP_MODDING "Enables workshop utilities (useful for steam workshop / mod.io)" OFF)
option(RAWRBOX_SCRIPTING_EXCEPTION "Enables scripting throwing exceptions instead of catching them" OFF)
option(RAWRBOX_BUILD_RAWRBOX_STEAMWORKS "Build steamworks support" OFF)
option(RAWRBOX_BUILD_RAWRBOX_IMGUI "Build imgui support" OFF)
option(RAWRBOX_BUILD_MSVC_MULTITHREADED_RUNTIME "Build with msvc multithreading" OFF)
option(RAWRBOX_BUILD_QHULL "Include QHull on utils" OFF)
# ---------------
# Supports -----
option(RAWRBOX_DISABLE_SUPPORT_DX12 "Disable dx12 support" OFF)
option(RAWRBOX_DISABLE_SUPPORT_VULKAN "Disable vulkan support" OFF)
# ---------------
# Other -----
option(RAWRBOX_DEV_MODE "Builds all modules, used for developing rawrbox" OFF)
option(RAWRBOX_INTERPROCEDURAL_OPTIMIZATION "Enables IPO" ON)
# ---------------
# -----
if(RAWRBOX_INTERPROCEDURAL_OPTIMIZATION AND NOT ("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM64") AND NOT ("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM"))
message(STATUS "Enabled INTERPROCEDURAL_OPTIMIZATION for release and distribution")
cmake_policy(SET CMP0069 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
include(CheckIPOSupported)
check_ipo_supported(RESULT ipoSupported OUTPUT error)
if(ipoSupported)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DISTRIBUTION TRUE)
else()
message(FATAL_ERROR "IPO / LTO is not supported, please disable RAWRBOX_INTERPROCEDURAL_OPTIMIZATION")
endif()
endif()
if(RAWRBOX_DEV_MODE)
message(WARNING "RAWRBOX Dev mode enabled!")
set(RAWRBOX_BUILD_TESTING ON)
set(RAWRBOX_BUILD_SAMPLES ON)
set(RAWRBOX_BUILD_RAWRBOX_UI ON)
set(RAWRBOX_BUILD_RAWRBOX_RESOURCES ON)
set(RAWRBOX_BUILD_RAWRBOX_GLTF ON)
set(RAWRBOX_BUILD_RAWRBOX_3D_PHYSICS ON)
set(RAWRBOX_BUILD_RAWRBOX_2D_PHYSICS ON)
set(RAWRBOX_BUILD_RAWRBOX_BASS ON)
set(RAWRBOX_BUILD_RAWRBOX_WEBM ON)
set(RAWRBOX_BUILD_RAWRBOX_NETWORK ON)
set(RAWRBOX_BUILD_RAWRBOX_SCRIPTING ON)
set(RAWRBOX_SCRIPTING_UNSAFE ON)
set(RAWRBOX_SCRIPTING_WORKSHOP_MODDING ON)
set(RAWRBOX_BUILD_RAWRBOX_STEAMWORKS ON)
set(RAWRBOX_BUILD_RAWRBOX_IMGUI ON)
set(RAWRBOX_BUILD_QHULL ON)
if(NOT DEFINED STEAMWORKS_APPID)
message(STATUS "Set STEAMWORKS_APPID to 480 (SpaceWars example game)")
set(STEAMWORKS_APPID 480) # SpaceWars example game
endif()
set(CPM_SOURCE_CACHE "${PROJECT_SOURCE_DIR}/.cache/cpm")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}")
endif()
# OTHER SETTINGS ----
set(RAWRBOX_CONTENT_FOLDER "assets" CACHE STRING "The assets folder (aka where models, textures, etc are)")
set(RAWRBOX_LIBRARY_TYPE "STATIC" CACHE STRING "Linking type for library")
# ----------------
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSPDLOG_FMT_EXTERNAL -DNOMINMAX")
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(BUILD_SHARED_LIBS OFF)
# Apple needs this flag to compile mixed objective/c++
if(APPLE AND NOT XCODE)
set(CMAKE_CXX_FLAGS "-ObjC++")
endif()
# Linux and Wayland support
if(NOT WIN32)
set(RAWRBOX_EXTRA_LIBS pthread GL X11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi")
if(RAWRBOX_USE_WAYLAND)
list(APPEND RAWRBOX_EXTRA_LIBS wayland-egl)
set(GLFW_BUILD_WAYLAND ON CACHE INTERNAL "")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti -fexceptions") # Enable exceptions and RTTI
else()
# Ignore warnings about missing pdb
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4099")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /ignore:4099")
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4099")
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive- /EHsc /GR") # Enable strict mode, exceptions and RTTI
endif()
set(CMAKE_SKIP_RPATH TRUE)
set(CMAKE_SKIP_BUILD_RPATH TRUE)
# ---------------------------------
# Patch vs studio paths
if(WIN32 AND NOT VS_DXC_COMPILER_PATH AND NOT VS_DXIL_SIGNER_PATH AND NOT VS_D3D_COMPILER_PATH)
get_filename_component(CMAKE_DEVKIT_LOCATION ${CMAKE_RC_COMPILER} DIRECTORY)
set(VS_DXC_COMPILER_PATH "${CMAKE_DEVKIT_LOCATION}/dxcompiler.dll" CACHE INTERNAL "")
set(VS_DXIL_SIGNER_PATH "${CMAKE_DEVKIT_LOCATION}/dxil.dll" CACHE INTERNAL "")
set(VS_D3D_COMPILER_PATH "${CMAKE_DEVKIT_LOCATION}/d3dcompiler_47.dll" CACHE INTERNAL "")
message(STATUS "Patching DirectX Visual Studio paths:\n\tVS_DXC_COMPILER_PATH: ${VS_DXC_COMPILER_PATH}\n\tVS_DXIL_SIGNER_PATH: ${VS_DXIL_SIGNER_PATH}\n\tVS_D3D_COMPILER_PATH: ${VS_D3D_COMPILER_PATH}")
endif()
# ---------------------
set(RAWRBOX_BUILD_MSVC_MULTITHREADED_RUNTIME OFF)
## CHECKS ---
if(NOT RAWRBOX_BUILD_RAWRBOX_RENDER)
message(WARNING "----------------------------------------\nRAWRBOX_BUILD_RAWRBOX_RENDER is disabled!\nDisabling UI / GLTF / IMGUI / WEBM and samples..\n----------------------------------------")
set(RAWRBOX_BUILD_RAWRBOX_UI OFF)
set(RAWRBOX_BUILD_RAWRBOX_GLTF OFF)
set(RAWRBOX_BUILD_RAWRBOX_IMGUI OFF)
set(RAWRBOX_BUILD_RAWRBOX_WEBM OFF)
set(RAWRBOX_BUILD_SAMPLES OFF)
else()
# Samples & UI ---
if(RAWRBOX_BUILD_SAMPLES AND NOT RAWRBOX_BUILD_RAWRBOX_RESOURCES)
message(WARNING "Samples require RAWRBOX.RESOURCES to be enabled, enabling...")
set(RAWRBOX_BUILD_RAWRBOX_RESOURCES ON)
endif()
if(RAWRBOX_BUILD_RAWRBOX_UI AND NOT RAWRBOX_BUILD_RAWRBOX_RESOURCES)
message(WARNING "RAWRBOX.UI requires RAWRBOX.RESOURCES to be enabled, enabling...")
set(RAWRBOX_BUILD_RAWRBOX_RESOURCES ON)
endif()
# -----------
endif()
if(NOT RAWRBOX_BUILD_MSVC_MULTITHREADED_RUNTIME AND RAWRBOX_BUILD_RAWRBOX_3D_PHYSICS)
set(RAWRBOX_BUILD_MSVC_MULTITHREADED_RUNTIME ON) # Jolt requires msvc multithreaded runtime
message(WARNING "JoltPhysics is enabled, forcing RAWRBOX_BUILD_MSVC_MULTITHREADED_RUNTIME")
endif()
# -------------------------
# GLOBAL PACKAGES ------
CPMAddPackage("gh:fmtlib/fmt#11.0.2")
if(fmt_ADDED)
set_lib_runtime_mt(fmt)
endif()
CPMAddPackage("gh:Neargye/magic_enum@0.9.6")
if(magic_enum_ADDED)
set_lib_runtime_mt(magic_enum)
endif()
if(RAWRBOX_BUILD_RAWRBOX_RENDER)
if(NOT WIN32 AND RAWRBOX_USE_WAYLAND)
CPMAddPackage("https://gitlab.freedesktop.org/wayland/weston@14.0.0")
endif()
endif()
CPMAddPackage("gh:stephenberry/glaze@4.0.0")
# ---
if(RAWRBOX_BUILD_RAWRBOX_NETWORK)
message(WARNING "RAWRBOX.NETWORK is enabled, adding zlib-ng package")
CPMFindPackage(
NAME
zlib
GITHUB_REPOSITORY
zlib-ng/zlib-ng
USE_CACHE
OFF
GIT_TAG
2.2.2
OPTIONS
"ZLIB_COMPAT ON"
"ZLIB_BUILD_EXAMPLES OFF"
"ZLIB_ENABLE_TESTS OFF"
"POSITION_INDEPENDENT_CODE ON"
"WITH_GTEST OFF"
)
if(zlib_ADDED)
include_directories(${zlib_SOURCE_DIR} ${zlib_BINARY_DIR})
set_lib_runtime_mt(zlib)
endif()
endif()
# --------------------
add_subdirectory("rawrbox.math")
add_subdirectory("rawrbox.utils")
add_subdirectory("rawrbox.engine")
if(RAWRBOX_BUILD_RAWRBOX_RENDER)
message(STATUS "Enabled RAWRBOX.RENDER support")
add_subdirectory("rawrbox.render")
endif()
if(RAWRBOX_BUILD_RAWRBOX_SCRIPTING)
message(STATUS "Enabled RAWRBOX.SCRIPTING support")
add_subdirectory("rawrbox.scripting")
endif()
if(RAWRBOX_BUILD_RAWRBOX_RESOURCES)
message(STATUS "Enabled RAWRBOX.RESOURCES support")
add_subdirectory("rawrbox.resources")
endif()
if(RAWRBOX_BUILD_RAWRBOX_NETWORK)
message(STATUS "Enabled RAWRBOX.NETWORK support")
add_subdirectory("rawrbox.network")
endif()
if(RAWRBOX_BUILD_RAWRBOX_WEBM)
message(STATUS "Enabled RAWRBOX.WEBM support")
add_subdirectory("rawrbox.webm")
endif()
if(RAWRBOX_BUILD_RAWRBOX_GLTF)
message(STATUS "Enabled RAWRBOX.GLTF support")
add_subdirectory("rawrbox.gltf")
endif()
if(RAWRBOX_BUILD_RAWRBOX_UI)
message(STATUS "Enabled RAWRBOX.UI support")
add_subdirectory("rawrbox.ui")
endif()
if(RAWRBOX_BUILD_RAWRBOX_BASS)
message(STATUS "Enabled RAWRBOX.BASS support")
add_subdirectory("rawrbox.bass")
endif()
if(RAWRBOX_BUILD_RAWRBOX_2D_PHYSICS)
message(STATUS "Enabled RAWRBOX.2D_PHYSICS support")
add_subdirectory("rawrbox.physics_2d")
endif()
if(RAWRBOX_BUILD_RAWRBOX_STEAMWORKS)
message(STATUS "Enabled RAWRBOX.STEAMWORKS support")
add_subdirectory("rawrbox.steamworks")
endif()
if(RAWRBOX_BUILD_RAWRBOX_IMGUI)
message(STATUS "Enabled RAWRBOX.IMGUI support")
add_subdirectory("rawrbox.imgui")
endif()
# Jolt enables some weird flags, make sure it's the last one
if(RAWRBOX_BUILD_RAWRBOX_3D_PHYSICS)
message(STATUS "Enabled RAWRBOX.3D_PHYSICS support")
add_subdirectory("rawrbox.physics_3d")
endif()
# --------------------
# Shhhhh windows... shhhh....
mute_dependencies_warnings(".*RAWRBOX.*")
# --------------------
if(RAWRBOX_BUILD_SAMPLES)
message(STATUS "Enabled SAMPLES building")
add_subdirectory("samples")
endif()
if(WIN32)
string(REPLACE "/WX" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()