-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
243 lines (218 loc) · 7.69 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
cmake_minimum_required(VERSION 3.20)
project(OpenChickenInvaders)
option(USE_SFML "use SFML (otherwise SDL will be used" OFF)
option(USE_IWYU "enable include-what-you-use tool" OFF)
set(CMAKE_CXX_STANDARD 20)
file(GLOB_RECURSE headers "src/*.h")
set(sources
src/audio/controller_holder.cpp
src/audio/player.cpp
src/background/background.cpp
src/constants.cpp
src/context/context.cpp
src/context/manager.cpp
src/core/color.cpp
src/core/image.cpp
src/core/keyboard.cpp
src/core/mouse.cpp
src/core/rectangle_shape.cpp
src/core/sprite.cpp
src/core/texture.cpp
src/core/window.cpp
src/diagnostics/benchmark/benchmark.cpp
src/diagnostics/fps.cpp
src/egg.cpp
src/font/font.cpp
src/game/state.cpp
src/levels/factory.cpp
src/levels/game_level.cpp
src/levels/game_over.cpp
src/levels/interface/indicator.cpp
src/levels/interface/interface.cpp
src/levels/interface/lives_indicator.cpp
src/levels/interface/missiles_indicator.cpp
src/levels/intro_0.cpp
src/levels/intro_1.cpp
src/levels/intro_level.cpp
src/levels/level.cpp
src/levels/level_1_1.cpp
src/levels/level_1_10.cpp
src/levels/level_1_2.cpp
src/levels/level_1_4.cpp
src/levels/level_1_5.cpp
src/levels/level_1_8.cpp
src/levels/level_1_9.cpp
src/levels/level_x2_x3.cpp
src/levels/level_x4.cpp
src/levels/loader.cpp
src/levels/manager.cpp
src/levels/start_round.cpp
src/main.cpp
src/menu/background_controller.cpp
src/menu/cursor.cpp
src/menu/mainmenu.cpp
src/objects/base/animated.cpp
src/objects/base/animated_collision_object.cpp
src/objects/base/collision_object.cpp
src/objects/base/sprite.cpp
src/objects/bonus/bonus.cpp
src/objects/bonus/chicken_body.cpp
src/objects/bonus/chicken_leg.cpp
src/objects/bonus/chicken_part.cpp
src/objects/bonus/coin.cpp
src/objects/bonus/switch_gun.cpp
src/objects/bonus/upgrade_gun.cpp
src/objects/characters/asteroid.cpp
src/objects/characters/boss1.cpp
src/objects/characters/chicken.cpp
src/objects/characters/jumping_asteroid.cpp
src/objects/characters/paratrooper.cpp
src/objects/characters/player_ship.cpp
src/objects/characters/random_chicken.cpp
src/objects/characters/shield.cpp
src/objects/characters/ship.cpp
src/objects/characters/ufo.cpp
src/objects/effects/unshade_screen.cpp
src/objects/gun/bullet.cpp
src/objects/gun/green_gun.cpp
src/objects/gun/gun.cpp
src/objects/gun/missile.cpp
src/objects/gun/red_gun.cpp
src/objects/particles/bang.cpp
src/objects/particles/exhaust.cpp
src/objects/particles/particle.cpp
src/objects/particles/smoke.cpp
src/objects/particles/spark.cpp
src/objects/text/subtitle_text.cpp
src/objects/text/text.cpp
src/resources/loader.cpp
src/solar_system.cpp
src/utils/fast_trigonometry.cpp
)
macro(GroupSources curdir)
file(GLOB children RELATIVE ${PROJECT_SOURCE_DIR}/${curdir} ${PROJECT_SOURCE_DIR}/${curdir}/*)
foreach(child ${children})
if(IS_DIRECTORY ${PROJECT_SOURCE_DIR}/${curdir}/${child})
GroupSources(${curdir}/${child})
else()
string(REPLACE "/" "\\" groupname ${curdir})
source_group(${groupname} FILES ${PROJECT_SOURCE_DIR}/${curdir}/${child})
endif()
endforeach()
endmacro()
GroupSources(src)
add_executable(oci ${sources} ${headers})
#
# Build tinyxml2
#
option(tinyxml2_BUILD_TESTING "" OFF)
include(FetchContent)
FetchContent_Declare(tinyxml2
GIT_REPOSITORY https://github.com/leethomason/tinyxml2.git
GIT_TAG v10.0.0
GIT_SHALLOW ON)
FetchContent_MakeAvailable(tinyxml2)
target_link_libraries(oci PRIVATE tinyxml2)
target_include_directories(oci PRIVATE ${tinyxml2_SOURCE_DIR})
#
# Download the resource file of the original game
#
find_package(Python3 REQUIRED COMPONENTS Interpreter)
add_custom_command(
DEPENDS "${CMAKE_SOURCE_DIR}/utility/download_resources.py"
TARGET oci POST_BUILD
COMMAND ${Python3_EXECUTABLE}
"${CMAKE_SOURCE_DIR}/utility/download_resources.py"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
include(GNUInstallDirs)
if (EMSCRIPTEN)
if (${USE_SFML})
message(FATAL_ERROR "Only SDL build is supported for WASM target")
endif ()
target_compile_options(oci PRIVATE "-sUSE_SDL=2")
target_link_options(oci PRIVATE
"-sASYNCIFY"
"--use-port=sdl2"
"--use-port=sdl2_mixer"
"-sINVOKE_RUN=0"
"-sEXIT_RUNTIME=1"
"-sMODULARIZE=1"
"-sEXPORT_NAME=\"createModule\""
"-sEXPORTED_RUNTIME_METHODS=[\"callMain\",\"addOnExit\",\"JSEvents\"]"
)
target_link_options(oci PRIVATE "--embed-file=${CMAKE_CURRENT_SOURCE_DIR}/res/@/res/")
target_link_options(oci PRIVATE "--embed-file=${CMAKE_CURRENT_BINARY_DIR}/ChickenInvaders2.dat@/ChickenInvaders2.dat")
else()
if (${USE_SFML})
# https://github.com/SFML/cmake-sfml-project/blob/master/CMakeLists.txt
FetchContent_Declare(SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 2.6.x
GIT_SHALLOW ON
SYSTEM)
FetchContent_MakeAvailable(SFML)
target_link_libraries(oci PRIVATE sfml-graphics sfml-audio)
target_include_directories(oci PRIVATE ${sfml_SOURCE_DIR}/include)
target_compile_definitions(oci PRIVATE "USE_SFML")
else ()
find_package(SDL2 CONFIG REQUIRED)
target_link_libraries(oci PRIVATE SDL2::SDL2)
find_package(SDL2_mixer QUIET)
if (SDL2_mixer_FOUND)
target_link_libraries(oci PRIVATE SDL2_mixer::SDL2_mixer)
else ()
# cmake can't find the system SDL2-mixer package in Ubuntu 22.04
# try to use pkgconfig in this case
find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2_mixer REQUIRED SDL2_mixer)
target_link_libraries(oci PRIVATE ${SDL2_mixer_LIBRARIES})
target_include_directories(oci PRIVATE ${SDL2_mixer_INCLUDE_DIRS})
target_compile_options(oci PRIVATE ${SDL2_mixer_CFLAGS_OTHER})
endif()
endif()
install(TARGETS oci RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/ChickenInvaders2.dat
DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/res/
DESTINATION ${CMAKE_INSTALL_BINDIR}
)
add_custom_command(
TARGET oci
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/res/
$<TARGET_FILE_DIR:oci>/res/)
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
set(RUNTIME_DLL_SET $<BOOL:$<TARGET_RUNTIME_DLLS:oci>>)
set(COPY_COMMAND
${CMAKE_COMMAND} -E copy_if_different
$<TARGET_RUNTIME_DLLS:oci>
$<TARGET_FILE_DIR:oci>
)
add_custom_command(
TARGET oci
POST_BUILD
COMMAND "$<${RUNTIME_DLL_SET}:${COPY_COMMAND}>"
COMMAND_EXPAND_LISTS
COMMENT "Copying runtime dependencies (DLLs)"
)
endif()
endif()
if (MSVC)
target_compile_options(oci PRIVATE "/D_CRT_SECURE_NO_WARNINGS" "/GR-" "/EHsc" "/D_HAS_EXCEPTIONS=0")
else()
target_compile_options(oci PRIVATE "-fno-rtti" "-fno-exceptions" "-Wextra" "-Wall")
endif()
target_include_directories(oci PRIVATE ${CMAKE_SOURCE_DIR}/src)
if (${USE_IWYU})
find_program(iwyu_path NAMES include-what-you-use iwyu REQUIRED)
if (NOT iwyu_path)
message("WARNING: include-what-you-use tool was not found - will build without include validation")
else()
set_property(TARGET oci PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path};-Xiwyu;--cxx17ns)
endif()
endif ()