This repository has been archived by the owner on Dec 14, 2023. It is now read-only.
forked from yvt/openspades
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
405 lines (340 loc) · 15 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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
cmake_minimum_required(VERSION 2.8...3.22.2)
project(OpenSpades)
set(OpenSpades_VERSION_MAJOR 0)
set(OpenSpades_VERSION_MINOR 1)
set(OpenSpades_VERSION_REVISION 5)
set(OPENSPADES_FULL_VERSION "${OpenSpades_VERSION_MAJOR}.${OpenSpades_VERSION_MINOR}.${OpenSpades_VERSION_REVISION}")
set(OS_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
if(VCPKG_TARGET_TRIPLET)
set(USE_VCPKG ON)
else()
set(USE_VCPKG OFF)
endif()
# Prefer GLVND OpenGL
if(POLICY CMP0072)
cmake_policy(SET CMP0072 NEW)
endif()
if(USE_VCPKG)
find_package(Ogg CONFIG REQUIRED)
find_package(Opus CONFIG REQUIRED)
find_package(sdl2-image CONFIG REQUIRED)
find_package(SDL2 CONFIG REQUIRED)
find_package(freetype CONFIG REQUIRED)
if(NOT APPLE)
find_package(GLEW REQUIRED)
set(GLEW_LIBRARY GLEW::GLEW)
find_package(CURL REQUIRED)
set(CURL_LIBRARY CURL::libcurl)
endif()
set(SDL2_LIBRARY SDL2::SDL2main SDL2::SDL2-static)
set(SDL2_IMAGE_LIBRARY SDL2::SDL2_image)
set(FREETYPE_LIBRARIES freetype)
if(APPLE)
# Use system libraries
include(FindOpenGL)
include(FindCURL)
endif()
FIND_LIBRARY(OpusFile_LIBRARY
NAMES opusfile
PATH_SUFFIXES lib64 lib
PATHS ${CMAKE_PREFIX_PATH}
)
else()
include(cmake/FindSDL2.cmake)
if(NOT SDL2_FOUND)
message(FATAL_ERROR "SDL 2.0 not found, set ENV{SDL2DIR} to point to SDL 2.0, and optionally set the cmake var SDL2_LIBRARY_TEMP to the lib dir")
endif()
include(cmake/FindSDL2_image.cmake)
if(NOT SDL2_IMAGE_FOUND)
message(FATAL_ERROR "SDL_image 2.0 not found, set ENV{SDL2DIR} to point to SDL 2.0, and optionally set the cmake var SDL2_LIBRARY_TEMP to the lib dir")
endif()
include(FindOpenGL)
if(NOT OPENGL_FOUND AND NOT OPENGL_XMESA_FOUND AND NOT OPENGL_GLU_FOUND)
message(FATAL_ERROR "OpenGL not found, please install it")
endif()
if(NOT APPLE)
include(cmake/FindGLEW2.cmake)
if(NOT GLEW_FOUND)
message(FATAL_ERROR "GLEW not found, please install it and make sure CMake can find it (add it to the PATH)")
endif()
endif()
include(FindZLIB)
if(NOT ZLIB_FOUND)
message(FATAL_ERROR "ZLIB not found, manually set ZLIB_ROOT in CMake")
endif()
include(FindCURL)
if(NOT CURL_FOUND)
message(FATAL_ERROR "cURL not found, please install it (and make sure it's in your path)")
endif()
include(FindFreetype)
if(NOT FREETYPE_FOUND)
message(FATAL_ERROR "FreeType not found, please install it (and make sure it's in your path)")
endif()
include(cmake/FindOpus.cmake)
if(NOT OpusFile_FOUND)
message(FATAL_ERROR "libopus/libopusfile not found, please install it (and make sure it's in your path)")
endif()
include(cmake/FindXext.cmake)
if(NOT XEXT_FOUND)
message(FATAL_ERROR "libXext, please install it (and make sure it's in your path)")
endif()
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
# GCC C++11 support
# from http://stackoverflow.com/questions/10984442/how-to-detect-c11-support-of-a-compiler-with-cmake
#
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7)
message(STATUS "C++11 activated.")
add_definitions("-std=gnu++11")
elseif(GCC_VERSION VERSION_GREATER 4.3 OR GCC_VERSION VERSION_EQUAL 4.3)
message(WARNING "C++0x activated. If you get any errors update to a compiler which fully supports C++11")
add_definitions("-std=gnu++0x")
else ()
message(FATAL_ERROR "C++11 needed. Therefore a gcc compiler with a version higher than 4.3 is needed.")
endif()
add_definitions(
-Wall
-Wextra
-Wno-unknown-pragmas #learn_more: output is spammed like shit by all those #pragma mark items
)
if(CMAKE_BUILD_TYPE MATCHES "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
set(CMAKE_EXE_LINKER_FLAGS "-s")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# Clang C++11 support
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
add_definitions(
-Wall
-Wextra
-Wno-unused-parameter
)
if(CMAKE_BUILD_TYPE MATCHES "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
set(CMAKE_EXE_LINKER_FLAGS "-s")
endif()
elseif(MSVC)
add_definitions(
/D_CRT_SECURE_NO_WARNINGS
/wd4068
/DNOMINMAX
/D_USE_MATH_DEFINES
)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") #static link to msv runtime (MSVCR(P)xxx.dll)
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON) #msvc / xcode: group files in project
#mainly for ENet...
include(CheckFunctionExists)
include(CheckStructHasMember)
include(CheckTypeSize)
check_function_exists("fcntl" HAS_FCNTL)
check_function_exists("poll" HAS_POLL)
check_function_exists("gethostbyname_r" HAS_GETHOSTBYNAME_R)
check_function_exists("gethostbyaddr_r" HAS_GETHOSTBYADDR_R)
check_function_exists("inet_pton" HAS_INET_PTON)
check_function_exists("inet_ntop" HAS_INET_NTOP)
check_struct_has_member("struct msghdr" "msg_flags" "sys/types.h;sys/socket.h" HAS_MSGHDR_FLAGS)
set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h" "sys/socket.h")
check_type_size("socklen_t" HAS_SOCKLEN_T BUILTIN_TYPES_ONLY)
unset(CMAKE_EXTRA_INCLUDE_FILES)
if(HAS_FCNTL)
add_definitions(-DHAS_FCNTL=1)
endif()
if(HAS_POLL)
add_definitions(-DHAS_POLL=1)
endif()
if(HAS_GETHOSTBYNAME_R)
add_definitions(-DHAS_GETHOSTBYNAME_R=1)
endif()
if(HAS_GETHOSTBYADDR_R)
add_definitions(-DHAS_GETHOSTBYADDR_R=1)
endif()
if(HAS_INET_PTON)
add_definitions(-DHAS_INET_PTON=1)
endif()
if(HAS_INET_NTOP)
add_definitions(-DHAS_INET_NTOP=1)
endif()
if(HAS_MSGHDR_FLAGS)
add_definitions(-DHAS_MSGHDR_FLAGS=1)
endif()
if(HAS_SOCKLEN_T)
add_definitions(-DHAS_SOCKLEN_T=1)
endif()
option(OPENSPADES_RESOURCES "Build game assets" ON)
option(OPENSPADES_NONFREE_RESOURCES "Download non-GPL game assets" ON)
option(OPENSPADES_YSR "Download YSRSpades (closed-source audio backend; macOS only)" ON)
# note that all paths are without trailing slash
set(OPENSPADES_INSTALL_DOC "share/doc/openspades" CACHE STRING "Directory for installing documentation. ")
set(OPENSPADES_INSTALL_MENU "share/menu" CACHE STRING "Directory for installing menu file. " )
set(OPENSPADES_INSTALL_MAN "share/man/man6" CACHE STRING "Directory for installing man file. " )
set(OPENSPADES_INSTALL_RESOURCES "share/games/openspadesplus/Resources" CACHE STRING "Directory for installing Resources. ")
set(OPENSPADES_INSTALL_ICONS "share/icons/hicolor" CACHE STRING "Directory for installing icons. ")
set(OPENSPADES_INSTALL_PIXMAP "share/pixmaps" CACHE STRING "Directory for installing .xpm icon. ")
set(OPENSPADES_INSTALL_BINARY "games" CACHE STRING "Directory for installing result binary executable. ")
set(OPENSPADES_INSTALL_DESKTOP "share/applications" CACHE STRING "Directory for installing .desktop file. ")
set(OPENSPADES_INSTALL_LIBS "lib/openspades" CACHE STRING "Directory for installing various non-media stuff. Currently not used")
set(OPENSPADES_RESDIR "" CACHE STRING "Resource dir to use while developing")
set(OPENSPADES_EXTRATITLE "" CACHE STRING "Extra info to add to the package name")
if(OPENSPADES_RESDIR)
set(RESDIR ${OPENSPADES_RESDIR})
set(RESDIR_DEFINED TRUE)
mark_as_advanced(RESDIR)
mark_as_advanced(RESDIR_DEFINED)
endif()
if(UNIX)
EXECUTE_PROCESS(COMMAND "date" "+%Y" OUTPUT_VARIABLE CMAKE_CURRENT_YEAR)
mark_as_advanced(CMAKE_CURRENT_YEAR)
endif(UNIX)
if(CMAKE_CXX_COMPILER_ID)
if(CMAKE_CXX_COMPILER_VERSION)
set(_version " ${CMAKE_CXX_COMPILER_VERSION}")
else()
set(_version "")
endif()
set(OPENSPADES_COMPILER ${CMAKE_CXX_COMPILER_ID}${_version})
endif()
configure_file("${PROJECT_SOURCE_DIR}/OpenSpades.h.in" "${PROJECT_BINARY_DIR}/OpenSpades.h")
configure_file("${PROJECT_SOURCE_DIR}/OpenSpades.rc.in" "${PROJECT_BINARY_DIR}/OpenSpades.rc")
include_directories(BEFORE "${PROJECT_BINARY_DIR}")
if(USE_VCPKG)
include_directories("${PROJECT_SOURCE_DIR}/vcpkg/installed/${VCPKG_TARGET_TRIPLET}/include")
else()
include_directories("${SDL2_INCLUDE_DIR}")
include_directories("${SDL2_IMAGE_INCLUDE_DIR}")
if(OPENGL_INCLUDE_DIR)
include_directories("${OPENGL_INCLUDE_DIR}")
endif()
if(NOT APPLE)
include_directories("${GLEW_INCLUDE_DIR}")
endif()
include_directories("${ZLIB_INCLUDE_DIR}")
include_directories(${CURL_INCLUDE_DIRS})
include_directories(${FREETYPE_INCLUDE_DIRS})
include_directories(${OpusFile_INCLUDE_DIR})
include_directories(${Opus_INCLUDE_DIR})
include_directories(${Ogg_INCLUDE_DIR})
endif()
add_subdirectory(Resources)
add_subdirectory(Sources)
if(UNIX AND NOT APPLE)
# various texts
INSTALL(FILES AUTHORS LICENSE README.md DESTINATION ${OPENSPADES_INSTALL_DOC}/)
# menu file
INSTALL(FILES Resources/Unix/Menu/openspades DESTINATION ${OPENSPADES_INSTALL_MENU}/)
# man file
INSTALL(FILES ${CMAKE_BINARY_DIR}/Resources/Unix/Man/openspades.6.gz DESTINATION ${OPENSPADES_INSTALL_MAN}/)
# changelog file
INSTALL(FILES ${CMAKE_BINARY_DIR}/Resources/Unix/Debian/changelog.gz DESTINATION ${OPENSPADES_INSTALL_DOC}/)
# copyright file
INSTALL(FILES ${CMAKE_BINARY_DIR}/Resources/Unix/Debian/copyright DESTINATION ${OPENSPADES_INSTALL_DOC}/)
if(OPENSPADES_RESOURCES)
# install asset paks (including non-GPL one)
install(FILES ${PAK_FILES} DESTINATION ${OPENSPADES_INSTALL_RESOURCES})
endif(OPENSPADES_RESOURCES)
# Package info (used for automatic update check)
INSTALL(FILES Resources/PackageInfo.json DESTINATION ${OPENSPADES_INSTALL_RESOURCES})
# install icons
INSTALL(
DIRECTORY ${CMAKE_BINARY_DIR}/Resources/Icons/hicolor/
DESTINATION ${OPENSPADES_INSTALL_ICONS}
FILES_MATCHING PATTERN "*.png")
INSTALL(FILES Resources/Icons/openspades.xpm DESTINATION ${OPENSPADES_INSTALL_PIXMAP}/)
# binary file
INSTALL(PROGRAMS ${CMAKE_BINARY_DIR}/bin/openspadesplus DESTINATION ${OPENSPADES_INSTALL_BINARY})
# desktop file
INSTALL(FILES Resources/Unix/Desktop/openspadesplus.desktop DESTINATION ${OPENSPADES_INSTALL_DESKTOP}/)
# Currently there is no files in lib/openspades. But if you reading this message in future and want to
# place somewhere libs, binaries or other non-media stuff, place them in lib/openspades. Thank you.
endif(UNIX AND NOT APPLE)
if(APPLE)
# Create a macOS application bundle
set_target_properties(OpenSpades PROPERTIES
MACOSX_BUNDLE ON
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/XSpades/XSpades-Info.plist
MACOSX_BUNDLE_BUNDLE_VERSION ${OPENSPADES_FULL_VERSION}
MACOSX_BUNDLE_LONG_VERSION_STRING ${OPENSPADES_FULL_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${OPENSPADES_FULL_VERSION}
MACOSX_BUNDLE_GUI_IDENTIFIER pf.non.openspadesplus
MACOSX_BUNDLE_BUNDLE_NAME OpenSpadesPlus)
set(BUNDLE_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Resources/Icons/OpenSpades.icns)
list(APPEND BUNDLE_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
if(OPENSPADES_RESOURCES)
list(APPEND BUNDLE_RESOURCES ${PAK_FILES})
set_source_files_properties(${PAK_FILES}
PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
add_dependencies(OpenSpades OpenSpades_Resources_DevPaks OpenSpades_Resources)
endif(OPENSPADES_RESOURCES)
list(APPEND BUNDLE_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Resources/PackageInfo.json)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/Resources/PackageInfo.json
PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
if (OPENSPADES_YSR)
list(APPEND BUNDLE_RESOURCES ${CMAKE_CURRENT_BINARY_DIR}/libysrspades.dylib)
# Download `libysrspades.dylib` automatically
add_dependencies(OpenSpades OpenSpades_YSRSpades_Prebuilt)
add_custom_target(OpenSpades_YSRSpades_Prebuilt ALL COMMENT "Downloading libysrspades.dylib"
DEPENDS ${PROJECT_BINARY_DIR}/libysrspades.dylib)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/libysrspades.dylib
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMAND
wget -c
https://openspadesmedia.yvt.jp/development-packages/YSRSpades/libysrspades.dylib
)
endif (OPENSPADES_YSR)
set_target_properties(OpenSpades PROPERTIES RESOURCE "${BUNDLE_RESOURCES}")
target_sources(OpenSpades PRIVATE "${BUNDLE_RESOURCES}")
endif(APPLE)
#see http://www.cmake.org/cmake/help/v2.8.11/cpack.html
set(CPACK_PACKAGE_NAME "OpenSpades+")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Basically competitive OpenSpades")
set(CPACK_PACKAGE_DESCRIPTION "Basically competitive OpenSpades, I guess")
set(CPACK_PACKAGE_VENDOR "yvt, non_performing, assorted")
set(CPACK_PACKAGE_CONTACT "nonperforming on GitHub")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
SET(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "openspadesplus-${OPENSPADES_FULL_VERSION}")
SET(CPACK_PACKAGE_FILE_NAME "openspadesplus-${OPENSPADES_FULL_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "OpenSpades+ ${OPENSPADES_FULL_VERSION}")
set(CPACK_PACKAGE_VERSION_MAJOR ${OpenSpades_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${OpenSpades_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${OpenSpades_VERSION_REVISION})
SET(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
SET(CPACK_TOPLEVEL_TAG "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
if(WIN32 AND NOT UNIX)
set(CPACK_NSIS_DISPLAY_NAME "OpenSpades+ ${OPENSPADES_FULL_VERSION}")
# There is a bug in NSIS that does not handle full unix paths properly. Make
# sure there is at least one set of four (4) backlasshes.
set(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\openspadesplus.exe")
# TODO: set(CPACK_PACKAGE_ICON "")
set(CPACK_NSIS_HELP_LINK "https://github.com/nonperforming/openspadesplus/issues")
set(CPACK_NSIS_URL_INFO_ABOUT "https://github.com/nonperforming/openspadesplus")
SET(CPACK_NSIS_CONTACT "[email protected]")
# TODO: SET(CPACK_NSIS_CREATE_ICONS_EXTRA "")
# TODO: SET(CPACK_NSIS_DELETE_ICONS_EXTRA "")
# TODO: SET(CPACK_NSIS_MUI_FINISHPAGE_RUN "openspades.exe")
set(CPACK_NSIS_MODIFY_PATH ON)
elseif(UNIX AND NOT APPLE)
# usage: `cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release .. ; make package`
INCLUDE(InstallRequiredSystemLibraries)
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Basically competitive OpenSpades, I guess")
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_CURRENT_SOURCE_DIR}/Resources/Unix/Control/postinst)
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr")
SET(CPACK_STRIP_FILES "bin/openspades")
SET(CPACK_SET_DESTDIR "on")
SET(CPACK_GENERATOR "DEB;TGZ")
SET(CPACK_DEBIAN_PACKAGE_DEPENDS
"libc6 (>= 2.19), libgcc1 (>= 1:4.9), libstdc++6 (>= 4.8.2), zlib1g (>= 1:1.2.8), libcurl3 (>= 7.35.0), libglew1.10 (>= 1.10.0), libsdl2-2.0-0 (>= 2.0.2), libsdl2-image-2.0-0 (>= 2.0.0), libfreetype6 (>= 2.4.0)") # TODO: add libopus/libopusfile
SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
SET(CPACK_DEBIAN_PACKAGE_SECTION "games")
SET(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "")
set(CPACK_DEBIAN_PACKAGE_SUGGESTS "")
SET(CPACK_COMPONENTS_ALL ALL)
endif(WIN32 AND NOT UNIX)
set(CPACK_PACKAGE_EXECUTABLES "openspadesplus" "Launch OpenSpades+")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY FALSE) #everyone hates a dir inside a zip named exactly like the zip
include(CPack)