-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
289 lines (258 loc) · 9.53 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
cmake_minimum_required(VERSION 3.12)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
message(FATAL_ERROR "Please create a build directory. Building inside the oceanpop directory directly would prevent the asset directory from being build correctly.")
endif()
project(oceanpop)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
file(GLOB_RECURSE SRC src/*.cpp)
if(WIN32)
add_executable(${CMAKE_PROJECT_NAME} WIN32 ${SRC} ${CMAKE_CURRENT_SOURCE_DIR}/platform/windows/appicon.rc)
else()
add_executable(${CMAKE_PROJECT_NAME} ${SRC})
endif()
set(BUILD_STATIC_DEFAULT OFF)
if(WIN32 OR VITA OR PSP)
set(BUILD_STATIC_DEFAULT ON)
endif()
option(BUILD_STATIC "Build a static binary" ${BUILD_STATIC_DEFAULT})
# Find libraries
include(FindPkgConfig)
pkg_search_module(SDL2 REQUIRED sdl2)
pkg_search_module(TINYGETTEXT QUIET tinygettext)
# Link libraries
if(BUILD_STATIC)
set(CMAKE_CXX_FLAGS "-static ${CMAKE_CXX_FLAGS}")
target_link_libraries(${PROJECT_NAME} PRIVATE
${SDL2_STATIC_LIBRARIES}
)
# Build libraries
set(BUILD_STATIC_LIBS ON)
set(BUILD_SHARED_LIBS OFF)
set(BUILD_OBJECT_LIBS OFF)
# jsoncpp
pkg_search_module(JSONCPP QUIET jsoncpp)
if (JSONCPP_FOUND)
target_link_libraries(${PROJECT_NAME} PRIVATE
${JSONCPP_STATIC_LIBRARIES}
)
include_directories(
${JSONCPP_INCLUDE_DIRS}
)
else()
set(JSONCPP_WITH_TESTS OFF)
set(JSONCPP_WITH_POST_BUILD_UNITTEST OFF)
set(JSONCPP_WITH_PKGCONFIG_SUPPORT OFF)
set(JSONCPP_WITH_CMAKE_PACKAGE OFF)
add_subdirectory(vendor/jsoncpp)
target_link_libraries(${PROJECT_NAME} PRIVATE
jsoncpp_static
)
include_directories(
vendor/jsoncpp/include/json
)
endif()
# SDL_image
set(SDL2IMAGE_SAMPLES OFF)
set(SDL2IMAGE_BACKEND_STB ON)
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
add_subdirectory(vendor/SDL_image)
target_link_libraries(${PROJECT_NAME} PRIVATE
SDL2_image
)
include_directories(
vendor/SDL_image/include/
)
#SDL_mixer
set(SDL2MIXER_DEPS_SHARED OFF)
set(SDL2MIXER_VENDORED OFF)
set(SDL2MIXER_SAMPLES OFF)
set(SDL2MIXER_CMD OFF)
set(SDL2MIXER_FLAC OFF)
set(SDL2MIXER_OPUS OFF)
set(SDL2MIXER_MOD OFF)
set(SDL2MIXER_WAVE ON)
set(SDL2MIXER_WAVPACK OFF)
set(SDL2MIXER_MIDI OFF)
set(SDL2MIXER_MP3 ON)
set(SDL2MIXER_MP3_MINIMP3 ON)
add_subdirectory(vendor/SDL_mixer)
target_link_libraries(${PROJECT_NAME} PRIVATE
SDL2_mixer
)
include_directories(
vendor/SDL_mixer/include/
)
# SDL_ttf
set(SDL2TTF_BUILD_SHARED_LIBS OFF)
set(SDL2TTF_VENDORED ON)
set(SDL2TTF_SAMPLES OFF)
set(SDL2TTF_FREETYPE ON)
set(SDL2TTF_FREETYPE_VENDORED ON)
set(SDL2TTF_HARFBUZZ OFF)
set(SDL2TTF_HARFBUZZ_VENDORED OFF)
set(SDL2TTF_SAMPLES OFF)
set(SDL2TTF_SAMPLES OFF)
set(SDL2TTF_SAMPLES OFF)
set(SDL2TTF_SAMPLES OFF)
set(SDL2TTF_SAMPLES OFF)
add_subdirectory(vendor/SDL_ttf)
target_link_libraries(${PROJECT_NAME} PRIVATE
SDL2_ttf
)
include_directories(
vendor/SDL_ttf/include/
)
# tinygettext
if (TINYGETTEXT_FOUND)
target_link_libraries(${PROJECT_NAME} PRIVATE
${TINYGETTEXT_STATIC_LIBRARIES}
)
else()
set(BUILD_TESTS OFF)
set(TINYGETTEXT_WITH_SDL ON)
add_subdirectory(vendor/tinygettext)
target_link_libraries(${PROJECT_NAME} PRIVATE
tinygettext
)
include_directories(
vendor/tinygettext/include/
)
endif()
else()
pkg_search_module(SDL2_IMAGE REQUIRED SDL2_image)
pkg_search_module(SDL2_MIXER REQUIRED SDL2_mixer)
pkg_search_module(SDL2_TTF REQUIRED SDL2_ttf)
pkg_search_module(JSONCPP REQUIRED jsoncpp)
target_link_libraries(${PROJECT_NAME} PRIVATE
${SDL2_LIBRARIES}
${SDL2_IMAGE_LIBRARIES}
${SDL2_MIXER_LIBRARIES}
${SDL2_TTF_LIBRARIES}
${JSONCPP_LIBRARIES}
)
include_directories(
${SDL2_IMAGE_INCLUDE_DIRS}
${SDL2_MIXER_INCLUDE_DIRS}
${SDL2_TTF_INCLUDE_DIRS}
${JSONCPP_INCLUDE_DIRS}
)
endif()
include_directories(
${PROJECT_SOURCE_DIR}/include
${SDL2_INCLUDE_DIRS}
)
if(TINYGETTEXT_FOUND OR BUILD_STATIC)
message("-- tinygettext library found, building with translation support")
if(NOT BUILD_STATIC)
target_link_libraries(${PROJECT_NAME} PRIVATE ${TINYGETTEXT_LIBRARIES})
endif()
set(TRANSLATION_SUPPORT ON)
add_compile_definitions(TRANSLATION_SUPPORT=1)
else()
message("-- tinygettext library not found, building without translation support")
set(TRANSLATION_SUPPORT OFF)
endif()
# Set asset paths
set(ASSETS_FONTS "${CMAKE_SOURCE_DIR}/assets/fonts")
set(ASSETS_IMAGES "${CMAKE_SOURCE_DIR}/assets/images")
set(ASSETS_LEVELS "${CMAKE_SOURCE_DIR}/assets/levels")
set(ASSETS_SOUNDS "${CMAKE_SOURCE_DIR}/assets/sounds")
set(ASSETS_MUSIC "${CMAKE_SOURCE_DIR}/assets/music")
set(ASSETS_BACKGROUNDS "${CMAKE_SOURCE_DIR}/assets/backgrounds")
if(TRANSLATION_SUPPORT)
set(ASSETS_LANGUAGES "${CMAKE_SOURCE_DIR}/assets/languages")
endif()
if(PSP)
set(ASSETS_BACKGROUNDS "${CMAKE_CURRENT_SOURCE_DIR}/platform/psp/assets/backgrounds")
elseif(VITA)
set(ASSETS_BACKGROUNDS "${CMAKE_SOURCE_DIR}/platform/vita/assets/backgrounds")
elseif(CMAKE_SYSTEM_NAME MATCHES "NintendoWii")
set(ASSETS_BACKGROUNDS "${CMAKE_SOURCE_DIR}/platform/wii/assets/backgrounds")
endif()
# Copy assets
if(NOT VITA)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/assets)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${ASSETS_BACKGROUNDS} ${CMAKE_CURRENT_BINARY_DIR}/assets/backgrounds)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${ASSETS_FONTS} ${CMAKE_CURRENT_BINARY_DIR}/assets/fonts)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${ASSETS_IMAGES} ${CMAKE_CURRENT_BINARY_DIR}/assets/images)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${ASSETS_LEVELS} ${CMAKE_CURRENT_BINARY_DIR}/assets/levels)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${ASSETS_MUSIC} ${CMAKE_CURRENT_BINARY_DIR}/assets/music)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${ASSETS_SOUNDS} ${CMAKE_CURRENT_BINARY_DIR}/assets/sounds)
if(TRANSLATION_SUPPORT)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${ASSETS_LANGUAGES} ${CMAKE_CURRENT_BINARY_DIR}/assets/languages)
endif()
endif()
# Generate credits file
set(CREDITS_FILE "${CMAKE_CURRENT_BINARY_DIR}/assets/CREDITS.md")
file(READ "${CMAKE_SOURCE_DIR}/assets/CREDITS_header.md" CONTENTS)
file(WRITE "${CREDITS_FILE}" "${CONTENTS}")
if(BUILD_STATIC)
file(READ "${CMAKE_SOURCE_DIR}/assets/CREDITS_static.md" CONTENTS)
file(APPEND "${CREDITS_FILE}" "${CONTENTS}")
endif()
if(PSP)
file(READ "${CMAKE_SOURCE_DIR}/assets/CREDITS_PSP.md" CONTENTS)
file(APPEND "${CREDITS_FILE}" "${CONTENTS}")
elseif(VITA)
file(READ "${CMAKE_SOURCE_DIR}/assets/CREDITS_Vita.md" CONTENTS)
file(APPEND "${CREDITS_FILE}" "${CONTENTS}")
elseif(CMAKE_SYSTEM_NAME MATCHES "NintendoWii")
file(READ "${CMAKE_SOURCE_DIR}/assets/CREDITS_Wii.md" CONTENTS)
file(APPEND "${CREDITS_FILE}" "${CONTENTS}")
endif()
file(READ "${CMAKE_SOURCE_DIR}/assets/CREDITS_footer.md" CONTENTS)
file(APPEND "${CREDITS_FILE}" "${CONTENTS}")
# Platform specific install
if (VITA)
include("$ENV{VITASDK}/share/vita.cmake" REQUIRED)
vita_create_self(${CMAKE_PROJECT_NAME}.self ${CMAKE_PROJECT_NAME})
vita_create_vpk(${CMAKE_PROJECT_NAME}.vpk "OPOP00001" ${CMAKE_PROJECT_NAME}.self
VERSION "01.00"
NAME OceanPop
FILE platform/vita/sce_sys sce_sys
FILE "${CREDITS_FILE}" assets/CREDITS.md
FILE "${ASSETS_BACKGROUNDS}" assets/backgrounds
FILE "${ASSETS_FONTS}" assets/fonts
FILE "${ASSETS_IMAGES}" assets/images
FILE "${ASSETS_LEVELS}" assets/levels
FILE "${ASSETS_MUSIC}" assets/music
FILE "${ASSETS_SOUNDS}" assets/sounds
FILE "${ASSETS_LANGUAGES}" assets/languages
)
elseif(PLATFORM_PSP)
create_pbp_file(
TARGET ${CMAKE_PROJECT_NAME}
ICON_PATH ${CMAKE_SOURCE_DIR}/platform/psp/icon.png
BACKGROUND_PATH NULL
PREVIEW_PATH NULL
TITLE OceanPop
)
elseif(CMAKE_SYSTEM_NAME MATCHES "NintendoWii")
ogc_create_dol(oceanpop)
elseif(win32)
# Nothing here yet
else()
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/assets DESTINATION share/${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/platform/unix/io.github.sharkwouter.oceanpop.desktop DESTINATION share/applications)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/platform/unix/io.github.sharkwouter.oceanpop.metainfo.xml DESTINATION share/metainfo)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/platform/unix/icons/128x128/io.github.sharkwouter.oceanpop.png DESTINATION share/icons/hicolor/128x128/apps)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/README.md DESTINATION share/doc/${PROJECT_NAME})
endif()