forked from kainjow/Glypha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
253 lines (227 loc) · 6.74 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
cmake_minimum_required(VERSION 3.1)
set(EXE_NAME "SlugMan")
string(REPLACE " " "" EXE_NAME_NOSPACES "${EXE_NAME}")
set(EXE_IDENTIFIER "com.kainjow.${EXE_NAME_NOSPACES}")
if(APPLE)
# must be set before project()
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "Minimum macOS deployment version")
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE)
endif()
# Credit to https://stackoverflow.com/questions/65157483/macos-build-universal-binary-2-with-cmake for the instructions on how to compile a Universal Binary using CMake.
project(SlugMan)
set(CPACK_PACKAGE_VERSION_MAJOR "2")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "1")
set(SOURCES
game/GLGame.cpp
game/GLGame.h
game/GLImage.cpp
game/GLImage.h
game/GLRect.cpp
game/GLRect.h
game/GLRenderer.cpp
game/GLRenderer.h
game/GLResources.h
game/GLUtils.cpp
game/GLUtils.h
game/GLBufferReader.cpp
game/GLBufferReader.h
game/GLCursor.h
game/GLSounds.h
game/GLFont.cpp
game/GLFont.h
game/GLPoint.h
game/GLPrefs.cpp
game/GLPrefs.h
)
if(HAVE_QT)
set(CMAKE_AUTOMOC ON)
list(APPEND SOURCES
qt/main.cpp
qt/main.hpp
game/GLCursorQt.cpp
game/GLImage_Qt.cpp
game/GLSoundsQt.cpp
game/GLSoundsQtImp.cpp
game/GLSoundsQtImp.h
)
elseif(BEOS OR HAIKU)
list(APPEND SOURCES
haiku/main.cpp
game/GLCursor.cpp
game/GLImage_libpng.cpp
game/GLSounds.cpp
)
elseif(WIN32)
list(APPEND SOURCES
win/main.cpp
win/resources.rc
win/resources.h
game/GLCursorWin32.cpp
game/GLImage_Win32.cpp
game/GLSoundsWin32.cpp
)
elseif(APPLE)
set(APPICON ${CMAKE_CURRENT_SOURCE_DIR}/mac/icon.icns)
set_source_files_properties(${APPICON} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
list(APPEND SOURCES
mac/main.mm
game/GLCursorCocoa.mm
game/GLImage_CoreImage.cpp
game/GLSoundsCocoa.mm
${APPICON}
)
endif()
add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE ${SOURCES})
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${EXE_NAME})
target_include_directories(${PROJECT_NAME} PRIVATE game)
if(HAVE_QT)
find_package(Qt5 COMPONENTS Core Widgets OpenGL Multimedia REQUIRED)
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Widgets Qt5::OpenGL Qt5::Multimedia)
target_compile_definitions(${PROJECT_NAME} PRIVATE SlugMan_QT=)
if(UNIX)
target_compile_options(${PROJECT_NAME} PRIVATE
-std=c++11
)
endif()
elseif(BEOS OR HAIKU)
elseif(UNIX AND NOT APPLE)
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall
-Wextra
-Werror
-Wconversion
-std=c++11
)
elseif(APPLE)
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall
-Wextra
-Werror
-Wconversion
)
target_compile_definitions(${PROJECT_NAME} PRIVATE
GL_SILENCE_DEPRECATION
)
elseif(WIN32)
target_include_directories(${PROJECT_NAME} PRIVATE win)
target_compile_definitions(${PROJECT_NAME} PRIVATE UNICODE)
endif()
# Separate so macOS version can build Qt version for testing
if(APPLE)
target_compile_options(${PROJECT_NAME} PRIVATE
-std=c++11
-stdlib=libc++
)
endif()
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE
/WX
/W4
)
endif()
list(FIND SOURCES game/GLImage_libpng.cpp HAVE_IMAGE_LIBPNG)
if(NOT HAVE_IMAGE_LIBPNG EQUAL -1)
include(FindPNG)
target_link_libraries(${PROJECT_NAME} ${PNG_LIBRARIES})
target_include_directories(${PROJECT_NAME} PRIVATE ${PNG_INCLUDE_DIRS})
endif()
include(FindOpenGL)
if(NOT OPENGL_FOUND)
message(FATAL_ERROR "OpenGL not found!")
endif()
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES})
if(HAVE_QT)
elseif(BEOS OR HAIKU)
find_library(BE be)
target_link_libraries(${PROJECT_NAME} ${BE})
elseif(WIN32)
target_link_libraries(${PROJECT_NAME} shlwapi windowscodecs winmm)
elseif(APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_LIST_DIR}/mac/Info.plist
MACOSX_BUNDLE_BUNDLE_NAME ${EXE_NAME}
MACOSX_BUNDLE_GUI_IDENTIFIER ${EXE_IDENTIFIER}
# Fix Xcode's Archive functionality
XCODE_ATTRIBUTE_INSTALL_PATH "$(LOCAL_APPS_DIR)"
XCODE_ATTRIBUTE_SKIP_INSTALL "No"
)
if("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
set_target_properties(${PROJECT_NAME} PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Mac Developer"
XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${CMAKE_CURRENT_LIST_DIR}/mac/SlugMan.entitlements"
)
endif()
target_link_libraries(${PROJECT_NAME}
"-framework Cocoa"
"-framework CoreVideo"
"-framework AVFoundation"
)
endif()
# Separate so macOS version can build Qt version for testing
if(APPLE)
target_link_libraries(${PROJECT_NAME}
-stdlib=libc++
)
endif()
install(TARGETS ${PROJECT_NAME} DESTINATION .)
if(APPLE)
set(CPACK_GENERATOR "DragNDrop")
endif()
include(CPack)
target_compile_definitions(${PROJECT_NAME} PRIVATE "GL_GAME_NAME=\"${EXE_NAME}\""
"GL_GAME_VERSION=\"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}\"")
if(WIN32)
target_compile_definitions(${PROJECT_NAME} PRIVATE "GL_GAME_NAME_W=L\"${EXE_NAME}\"")
endif()
add_executable(bin-convert bin-convert.c)
add_dependencies(${PROJECT_NAME} bin-convert)
set(RESOURCES
resources/images/help.png
resources/images/eye.png
resources/images/egg.png
resources/images/enemyFly.png
resources/images/enemyWalk.png
resources/images/background.png
resources/images/hand.png
resources/images/numbers.png
resources/images/obelisks.png
resources/images/platforms.png
resources/images/player.png
resources/images/playerIdle.png
resources/images/torches.png
resources/images/about.png
resources/sounds/boom1.wav
resources/sounds/music.wav
resources/sounds/bonus.wav
resources/sounds/boom2.wav
resources/sounds/spawn.wav
resources/sounds/splash.wav
resources/sounds/bird.wav
resources/sounds/flap.wav
resources/sounds/flap2.wav
resources/sounds/grate.wav
resources/sounds/lightning.wav
resources/sounds/scrape2.wav
resources/sounds/screech.wav
resources/sounds/walk.wav
resources/fonts/font11.png
resources/fonts/font11.fnt
)
foreach(rsrc ${RESOURCES})
get_filename_component(rsrc_filename ${rsrc} NAME)
string(REPLACE "." "_" rsrc_filename ${rsrc_filename})
set(input_path ${CMAKE_CURRENT_LIST_DIR}/${rsrc})
set(output_dir ${CMAKE_CURRENT_BINARY_DIR}/resources)
set(output_path ${output_dir}/${rsrc_filename}.cpp)
target_sources(${PROJECT_NAME} PRIVATE ${output_path})
set_source_files_properties(${PROJECT_NAME} ${output_path}
PROPERTIES GENERATED TRUE
)
add_custom_command(OUTPUT ${output_path}
COMMAND ${CMAKE_COMMAND} -E make_directory ${output_dir}
COMMAND $<TARGET_FILE:bin-convert> ${input_path} ${output_path}
)
endforeach()
source_group(rsrcs REGULAR_EXPRESSION "/resources/.*.cpp$")
source_group(game REGULAR_EXPRESSION "/game/")