forked from jorio/Nanosaur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
345 lines (297 loc) · 11.5 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
336
337
338
339
340
341
342
343
344
cmake_minimum_required(VERSION 3.13)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
#set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "Minimum OS X deployment version")
project(Nanosaur
VERSION 1.4.1
LANGUAGES C CXX
)
set(GAME_TARGET ${PROJECT_NAME})
set(GAME_ICNS cmake/${PROJECT_NAME}.icns)
#------------------------------------------------------------------------------
# GLOBAL OPTIONS (BEFORE ADDING SUBDIRECTORIES)
#------------------------------------------------------------------------------
if(MSVC)
# This lets us detect that MSVC supports C++20 features via the __cplusplus macro
# (See: https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus)
add_compile_options(/Zc:__cplusplus)
add_compile_definitions(UNICODE _UNICODE)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Nanosaur)
endif()
#------------------------------------------------------------------------------
# DEPENDENCIES
#------------------------------------------------------------------------------
add_subdirectory(extern/Quesa)
add_subdirectory(extern/Pomme)
find_package(SDL2 REQUIRED COMPONENTS main)
find_package(OpenGL REQUIRED)
#------------------------------------------------------------------------------
# GAME SOURCES
#------------------------------------------------------------------------------
set(GAME_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
# Write header file containing version info
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.h.in ${GAME_SRCDIR}/Headers/version.h)
set(GAME_CORE_SOURCES
${GAME_SRCDIR}/System/Main.c
${GAME_SRCDIR}/System/File.c
${GAME_SRCDIR}/System/Collision.c
${GAME_SRCDIR}/System/input.c
${GAME_SRCDIR}/System/Misc.c
${GAME_SRCDIR}/System/Objects.c
${GAME_SRCDIR}/System/Objects2.c
${GAME_SRCDIR}/System/Sprites.c
${GAME_SRCDIR}/System/Sound.c
${GAME_SRCDIR}/System/Windows.c
${GAME_SRCDIR}/System/SelfRunDemo.c
${GAME_SRCDIR}/Terrain/Terrain.c
${GAME_SRCDIR}/Terrain/Terrain2.c
${GAME_SRCDIR}/Player/MyGuy.c
${GAME_SRCDIR}/Player/Player_Control.c
${GAME_SRCDIR}/Player/Weapons.c
${GAME_SRCDIR}/Enemies/Enemy.c
${GAME_SRCDIR}/Enemies/Enemy_TriCer.c
${GAME_SRCDIR}/Enemies/Enemy_Stego.c
${GAME_SRCDIR}/Enemies/Enemy_Rex.c
${GAME_SRCDIR}/Enemies/Enemy_Ptera.c
${GAME_SRCDIR}/Enemies/Enemy_Spitter.c
${GAME_SRCDIR}/Items/Items.c
${GAME_SRCDIR}/Items/TimePortal.c
${GAME_SRCDIR}/Items/Pickups.c
${GAME_SRCDIR}/Items/Effects.c
${GAME_SRCDIR}/Items/Traps.c
${GAME_SRCDIR}/Items/Triggers.c
${GAME_SRCDIR}/Skeleton/SkeletonObj.c
${GAME_SRCDIR}/Skeleton/SkeletonJoints.c
${GAME_SRCDIR}/Skeleton/SkeletonAnim.c
${GAME_SRCDIR}/Skeleton/Bones.c
${GAME_SRCDIR}/QD3D/EnvironmentMap.c
${GAME_SRCDIR}/QD3D/Camera.c
${GAME_SRCDIR}/QD3D/QD3D_Support.c
${GAME_SRCDIR}/QD3D/QD3D_Geometry.c
${GAME_SRCDIR}/QD3D/3DMF.c
${GAME_SRCDIR}/QD3D/3DMath.c
${GAME_SRCDIR}/Screens/Infobar.c
${GAME_SRCDIR}/Screens/Title.c
${GAME_SRCDIR}/Screens/MainMenu.c
${GAME_SRCDIR}/Screens/HighScores.c
)
set(GAME_CORE_HEADERS
${GAME_SRCDIR}/Headers/main.h
${GAME_SRCDIR}/Headers/file.h
${GAME_SRCDIR}/Headers/collision.h
${GAME_SRCDIR}/Headers/input.h
${GAME_SRCDIR}/Headers/misc.h
${GAME_SRCDIR}/Headers/objects.h
${GAME_SRCDIR}/Headers/3dmath.h
${GAME_SRCDIR}/Headers/3dmf.h
${GAME_SRCDIR}/Headers/bones.h
${GAME_SRCDIR}/Headers/camera.h
${GAME_SRCDIR}/Headers/effects.h
${GAME_SRCDIR}/Headers/enemy.h
${GAME_SRCDIR}/Headers/environmentmap.h
${GAME_SRCDIR}/Headers/globals.h
${GAME_SRCDIR}/Headers/highscores.h
${GAME_SRCDIR}/Headers/infobar.h
${GAME_SRCDIR}/Headers/items.h
${GAME_SRCDIR}/Headers/mainmenu.h
${GAME_SRCDIR}/Headers/mobjtypes.h
${GAME_SRCDIR}/Headers/movie.h
${GAME_SRCDIR}/Headers/myguy.h
${GAME_SRCDIR}/Headers/mytraps.h
${GAME_SRCDIR}/Headers/objtypes.h
${GAME_SRCDIR}/Headers/pickups.h
${GAME_SRCDIR}/Headers/player_control.h
${GAME_SRCDIR}/Headers/qd3d_geometry.h
${GAME_SRCDIR}/Headers/qd3d_support.h
${GAME_SRCDIR}/Headers/selfrundemo.h
${GAME_SRCDIR}/Headers/skeletonanim.h
${GAME_SRCDIR}/Headers/skeletonjoints.h
${GAME_SRCDIR}/Headers/skeletonobj.h
${GAME_SRCDIR}/Headers/sound2.h
${GAME_SRCDIR}/Headers/sprites.h
${GAME_SRCDIR}/Headers/structs.h
${GAME_SRCDIR}/Headers/terrain.h
${GAME_SRCDIR}/Headers/timeportal.h
${GAME_SRCDIR}/Headers/title.h
${GAME_SRCDIR}/Headers/triggers.h
${GAME_SRCDIR}/Headers/version.h
${GAME_SRCDIR}/Headers/weapons.h
${GAME_SRCDIR}/Headers/windows_nano.h
)
set(GAME_GLUE_SOURCES
${GAME_SRCDIR}/Main.cpp
${GAME_SRCDIR}/Glue/Backdrop.cpp
${GAME_SRCDIR}/Glue/EdgePadding.cpp
${GAME_SRCDIR}/Glue/FrustumCulling.c
${GAME_SRCDIR}/Glue/GamePatches.cpp
${GAME_SRCDIR}/Glue/GLBackdrop.cpp
${GAME_SRCDIR}/Glue/GLFunctions.cpp
${GAME_SRCDIR}/Glue/Patch3DMFModels.c
${GAME_SRCDIR}/Glue/ProMode.c
${GAME_SRCDIR}/Glue/SettingsScreen.cpp
${GAME_SRCDIR}/Glue/Q3FSSpecStorage.cpp
${GAME_SRCDIR}/Headers/Glue/GamePatches.h
${GAME_SRCDIR}/Headers/Glue/GLBackdrop.h
${GAME_SRCDIR}/Headers/Glue/GLFunctions.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3D.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3DCamera.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3DDrawContext.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3DErrors.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3DGeometry.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3DGroup.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3DIO.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3DLight.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3DMath.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3DPick.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3DRenderer.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3DSet.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3DShader.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3DStorage.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3DStyle.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3DTransform.h
${GAME_SRCDIR}/Headers/QD3DCompat/QD3DView.h
)
set(GAME_ALL_SOURCES
${GAME_CORE_SOURCES}
${GAME_CORE_HEADERS}
${GAME_GLUE_SOURCES}
)
#------------------------------------------------------------------------------
# SOURCE GROUPS
#------------------------------------------------------------------------------
source_group(TREE ${GAME_SRCDIR} PREFIX "" FILES ${GAME_ALL_SOURCES})
#------------------------------------------------------------------------------
# SOURCE FILE PROPERTIES
#------------------------------------------------------------------------------
if(NOT MSVC)
set_source_files_properties(${GAME_CORE_SOURCES} PROPERTIES COMPILE_FLAGS "-include Pomme.h")
else()
set_source_files_properties(${GAME_CORE_SOURCES} PROPERTIES COMPILE_FLAGS /FIPomme.h)
endif()
#------------------------------------------------------------------------------
# EXECUTABLE TARGET
#------------------------------------------------------------------------------
if(WIN32)
# "WIN32" here is equivalent to /SUBSYSTEM:WINDOWS for MSVC
add_executable(${GAME_TARGET} WIN32
${GAME_ALL_SOURCES}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/WindowsResources.rc"
)
elseif(APPLE)
add_executable(${GAME_TARGET} MACOSX_BUNDLE
${GAME_ALL_SOURCES}
${GAME_ICNS}
${SDL2_LIBRARIES}
)
else()
add_executable(${GAME_TARGET} ${GAME_ALL_SOURCES})
endif()
target_include_directories(${GAME_TARGET} PRIVATE
${SDL2_INCLUDE_DIRS}
${OPENGL_INCLUDE_DIRS}
extern/Pomme/src
${GAME_SRCDIR}
${GAME_SRCDIR}/Headers
${GAME_SRCDIR}/Headers/Glue
${GAME_SRCDIR}/Headers/QD3DCompat
)
target_link_libraries(${GAME_TARGET}
Quesa_SDL
Pomme
${SDL2_LIBRARIES}
${OPENGL_LIBRARIES}
)
#------------------------------------------------------------------------------
# DEFINES
#------------------------------------------------------------------------------
add_compile_definitions(
"$<$<CONFIG:DEBUG>:_DEBUG>"
)
target_compile_definitions(Quesa_SDL PUBLIC
QUESA_OS_SDL
QUESA_APPLY_FOG_COLOR_IN_ALL_PASSES
)
target_compile_definitions(${GAME_TARGET} PRIVATE
QUESA_OS_SDL
SOURCE_PORT_ENHANCEMENTS
)
if(WIN32)
# On Win32, we need NOGDI and NOUSER to be able to define some Mac functions
# whose names are otherwise taken by Windows APIs.
target_compile_definitions(${GAME_TARGET} PRIVATE WIN32_LEAN_AND_MEAN NOGDI NOUSER)
endif()
#------------------------------------------------------------------------------
# COMPILER OPTIONS
#------------------------------------------------------------------------------
if(NOT MSVC)
target_compile_options(${GAME_TARGET} PRIVATE
-fexceptions
-Wall
-Wextra
-Wshadow
-Wno-multichar
-Wno-unknown-pragmas
-Wno-unused-parameter
)
else()
target_compile_options(${GAME_TARGET} PRIVATE
/EHa # C++ may throw exceptions from extern "C" functions
/W4
/wd4068 # ignore unrecognized pragmas
/wd4100 # unreferenced formal parameters
/wd4201 # nonstandard extension (nameless struct)
/wd4244 # conversion from double to float
/wd4305 # truncation from double to float
)
endif()
#------------------------------------------------------------------------------
# PLATFORM-SPECIFIC PACKAGING
#------------------------------------------------------------------------------
if(APPLE)
set_target_properties(${GAME_TARGET} PROPERTIES
# Set framework search path to (App bundle)/Contents/Frameworks so the game can use its embedded SDL2.framework
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/../Frameworks"
# Explicitly turn off code signing, otherwise downloaded app will be quarantined forever
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
RESOURCE ${GAME_ICNS}
MACOSX_BUNDLE_ICON_FILE ${PROJECT_NAME}.icns
MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}"
MACOSX_BUNDLE_COPYRIGHT "© 1998 Pangea Software, Inc."
)
# Copy stuff to app bundle contents
set_source_files_properties(${GAME_ICNS} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
set_source_files_properties(${SDL2_LIBRARIES} PROPERTIES MACOSX_PACKAGE_LOCATION "Frameworks")
set(BUNDLE_CONTENTS_DIR "$<TARGET_FILE_DIR:${PROJECT_NAME}>/..")
set(APP_PARENT_DIR "${BUNDLE_CONTENTS_DIR}/../..")
add_custom_command(TARGET ${GAME_TARGET} POST_BUILD
# Copy assets to app bundle
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/Data ${BUNDLE_CONTENTS_DIR}/Resources
# Nuke SDL headers in embedded framework
COMMAND rm -rf ${BUNDLE_CONTENTS_DIR}/Frameworks/SDL2.framework/Headers
COMMAND rm -rf ${BUNDLE_CONTENTS_DIR}/Frameworks/SDL2.framework/Versions/Current/Headers
# High-DPI support in Info.plist
# plutil -replace NSHighResolutionCapable -bool true ${BUNDLE_CONTENTS_DIR}/Info.plist
)
else()
set(APP_PARENT_DIR "$<TARGET_FILE_DIR:${GAME_TARGET}>")
# Copy assets besides executable
add_custom_command(TARGET ${GAME_TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/Data ${APP_PARENT_DIR}/Data)
endif()
# Copy SDL2 DLLs to output folder on Windows
if(WIN32)
foreach(DLL ${SDL2_DLLS})
add_custom_command(TARGET ${GAME_TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DLL} ${APP_PARENT_DIR})
endforeach()
set_target_properties(${GAME_TARGET} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
endif()
# Copy documentation to output folder
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ReadMe.txt.in ${CMAKE_CURRENT_BINARY_DIR}/ReadMe.txt)
add_custom_command(TARGET ${GAME_TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/ReadMe.txt ${APP_PARENT_DIR}/ReadMe.txt
# COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md ${APP_PARENT_DIR}/License.txt
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/docs ${APP_PARENT_DIR}/Documentation
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG.md ${APP_PARENT_DIR}/Documentation/CHANGELOG.md
)