forked from jorio/MightyMike
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
325 lines (277 loc) · 11.3 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.13)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_CXX_STANDARD 20)
# macOS options
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "Minimum macOS deployment version")
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "Target macOS architectures")
project(MightyMike
VERSION 3.0.0
LANGUAGES C CXX
)
set(GAME_TARGET ${PROJECT_NAME})
set(GAME_ICNS cmake/${GAME_TARGET}.icns)
get_filename_component(GAME_ICNS_FILENAME ${GAME_ICNS} NAME)
#------------------------------------------------------------------------------
# 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 ${GAME_TARGET})
endif()
set(POMME_NO_VIDEO true)
set(POMME_NO_QD3D true)
#------------------------------------------------------------------------------
# DEPENDENCIES
#------------------------------------------------------------------------------
add_subdirectory(extern/Pomme)
find_package(SDL2 REQUIRED COMPONENTS main)
find_package(Threads 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_SOURCES
${GAME_SRCDIR}/Heart/Cinema.c
${GAME_SRCDIR}/Heart/Collision.c
${GAME_SRCDIR}/Heart/Filter.cpp
${GAME_SRCDIR}/Heart/Infobar.c
${GAME_SRCDIR}/Heart/input.c
${GAME_SRCDIR}/Heart/InputDefaults.c
${GAME_SRCDIR}/Heart/IO.c
${GAME_SRCDIR}/Heart/Misc.c
${GAME_SRCDIR}/Heart/Picture.c
${GAME_SRCDIR}/Heart/Spin.c
${GAME_SRCDIR}/Heart/Window.c
${GAME_SRCDIR}/Heart/Main.c
${GAME_SRCDIR}/Heart/SettingsScreen.c
${GAME_SRCDIR}/Drivers/Animation.c
${GAME_SRCDIR}/Drivers/ObjectManager.c
${GAME_SRCDIR}/Drivers/Palette.c
${GAME_SRCDIR}/Drivers/Shape.c
${GAME_SRCDIR}/Drivers/Sound.c
${GAME_SRCDIR}/Drivers/TGA.c
${GAME_SRCDIR}/Drivers/Font.c
${GAME_SRCDIR}/MeAndMo/Enemy.c
${GAME_SRCDIR}/MeAndMo/MyGuy.c
${GAME_SRCDIR}/MeAndMo/MyGuy2.c
${GAME_SRCDIR}/MeAndMo/Weapon.c
${GAME_SRCDIR}/MeAndMo/Weapon2.c
${GAME_SRCDIR}/Misc/Bonus.c
${GAME_SRCDIR}/Misc/MiscAnims.c
${GAME_SRCDIR}/Misc/Traps.c
${GAME_SRCDIR}/Misc/Triggers.c
${GAME_SRCDIR}/Playfield/Playfield.c
${GAME_SRCDIR}/Enemies/Bargain/Enemy_8Ball.c
${GAME_SRCDIR}/Enemies/Bargain/Enemy_Battery.c
${GAME_SRCDIR}/Enemies/Bargain/Enemy_doggy.c
${GAME_SRCDIR}/Enemies/Bargain/Enemy_Robot.c
${GAME_SRCDIR}/Enemies/Bargain/Enemy_Slinky.c
${GAME_SRCDIR}/Enemies/Bargain/Enemy_Top.c
${GAME_SRCDIR}/Enemies/Bargain/RaceCar.c
${GAME_SRCDIR}/Enemies/Candy/Enemy_Carmel.c
${GAME_SRCDIR}/Enemies/Candy/Enemy_ChocBunny.c
${GAME_SRCDIR}/Enemies/Candy/Enemy_GBread.c
${GAME_SRCDIR}/Enemies/Candy/Enemy_GummyBear.c
${GAME_SRCDIR}/Enemies/Candy/Enemy_LemonDrop.c
${GAME_SRCDIR}/Enemies/Candy/Enemy_Mint.c
${GAME_SRCDIR}/Enemies/Clown/Enemy_Clown.c
${GAME_SRCDIR}/Enemies/Clown/Enemy_ClownCar.c
${GAME_SRCDIR}/Enemies/Clown/Enemy_FlowerClown.c
${GAME_SRCDIR}/Enemies/Clown/Enemy_HatBunny.c
${GAME_SRCDIR}/Enemies/Fairy/Enemy_BBWolf.c
${GAME_SRCDIR}/Enemies/Fairy/Enemy_Dragon.c
${GAME_SRCDIR}/Enemies/Fairy/Enemy_Giant.c
${GAME_SRCDIR}/Enemies/Fairy/Enemy_Soldier.c
${GAME_SRCDIR}/Enemies/Fairy/Enemy_Spider.c
${GAME_SRCDIR}/Enemies/Fairy/Enemy_Witch.c
${GAME_SRCDIR}/Enemies/Jurassic/Enemy_BabyDino.c
${GAME_SRCDIR}/Enemies/Jurassic/Enemy_CaveMan.c
${GAME_SRCDIR}/Enemies/Jurassic/Enemy_DinoEgg.c
${GAME_SRCDIR}/Enemies/Jurassic/Enemy_Rex.c
${GAME_SRCDIR}/Enemies/Jurassic/Enemy_Triceratops.c
${GAME_SRCDIR}/Enemies/Jurassic/Enemy_Turtle.c
${GAME_SRCDIR}/Main.cpp
)
set(GAME_HEADERS
${GAME_SRCDIR}/Headers/bonus.h
${GAME_SRCDIR}/Headers/cinema.h
${GAME_SRCDIR}/Headers/collision.h
${GAME_SRCDIR}/Headers/enemy.h
${GAME_SRCDIR}/Headers/enemy2.h
${GAME_SRCDIR}/Headers/enemy3.h
${GAME_SRCDIR}/Headers/enemy4.h
${GAME_SRCDIR}/Headers/enemy5.h
${GAME_SRCDIR}/Headers/equates.h
${GAME_SRCDIR}/Headers/externs.h
${GAME_SRCDIR}/Headers/font.h
${GAME_SRCDIR}/Headers/infobar.h
${GAME_SRCDIR}/Headers/input.h
${GAME_SRCDIR}/Headers/io.h
${GAME_SRCDIR}/Headers/main.h
${GAME_SRCDIR}/Headers/misc.h
${GAME_SRCDIR}/Headers/miscanims.h
${GAME_SRCDIR}/Headers/myglobals.h
${GAME_SRCDIR}/Headers/myguy.h
${GAME_SRCDIR}/Headers/myguy2.h
${GAME_SRCDIR}/Headers/object.h
${GAME_SRCDIR}/Headers/objecttypes.h
${GAME_SRCDIR}/Headers/picture.h
${GAME_SRCDIR}/Headers/playfield.h
${GAME_SRCDIR}/Headers/racecar.h
${GAME_SRCDIR}/Headers/shape.h
${GAME_SRCDIR}/Headers/sound2.h
${GAME_SRCDIR}/Headers/spin.h
${GAME_SRCDIR}/Headers/structures.h
${GAME_SRCDIR}/Headers/tga.h
${GAME_SRCDIR}/Headers/traps.h
${GAME_SRCDIR}/Headers/triggers.h
${GAME_SRCDIR}/Headers/version.h
${GAME_SRCDIR}/Headers/weapon.h
${GAME_SRCDIR}/Headers/window.h
)
set(GAME_ALL_SOURCES
${GAME_SOURCES}
${GAME_HEADERS}
)
#------------------------------------------------------------------------------
# SOURCE GROUPS
#------------------------------------------------------------------------------
source_group(TREE ${GAME_SRCDIR} PREFIX "" FILES ${GAME_ALL_SOURCES})
#------------------------------------------------------------------------------
# SOURCE FILE PROPERTIES
#------------------------------------------------------------------------------
if(NOT MSVC)
set_source_files_properties(${GAME_SOURCES} PROPERTIES COMPILE_FLAGS "-include Pomme.h")
else()
set_source_files_properties(${GAME_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"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/${GAME_TARGET}.exe.manifest"
)
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}
extern/Pomme/src
${GAME_SRCDIR}
${GAME_SRCDIR}/Headers
)
target_link_libraries(${GAME_TARGET}
Pomme
${SDL2_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
"$<$<BOOL:${APPLE}>:-framework Foundation>" # Required for KillMacMouseAcceleration
"$<$<BOOL:${APPLE}>:-framework IOKit>" # Required for KillMacMouseAcceleration
)
#------------------------------------------------------------------------------
# DEFINES
#------------------------------------------------------------------------------
add_compile_definitions(
"$<$<CONFIG:DEBUG>:_DEBUG>"
)
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
$<$<CXX_COMPILER_ID:GNU>:-Wno-unused-but-set-variable>
-Werror=return-type
)
else()
# By default, MSVC may add /EHsc to CMAKE_CXX_FLAGS, which we don't want (we use /EHs below)
string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
# By default, MSVC may add /W3 to CMAKE_CXX_FLAGS, which we don't want (we use /W4 below)
# Note that this is not required with "cmake_minimum_required(VERSION 3.15)" or later
string(REPLACE "/W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REPLACE "/W3" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
target_compile_options(${GAME_TARGET} PRIVATE
/EHs # synchronous exceptions; also, extern "C" functions may throw exceptions
/W4
/wd4068 # ignore unrecognized pragmas
/wd4100 # unreferenced formal parameters
/wd4200 # nonstandard extension: zero-sized array in struct
/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 ${GAME_ICNS_FILENAME}
MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}"
MACOSX_BUNDLE_COPYRIGHT "© 1995 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
)