forked from yvt/openspades
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
315 lines (258 loc) · 12.1 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
cmake_minimum_required(VERSION 2.8)
project(OpenSpades)
set(OpenSpades_VERSION_MAJOR 0)
set(OpenSpades_VERSION_MINOR 1)
set(OpenSpades_VERSION_REVISION 0)
set(OPENSPADES_FULL_VERSION "${OpenSpades_VERSION_MAJOR}.${OpenSpades_VERSION_MINOR}.${OpenSpades_VERSION_REVISION}")
set(OS_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_PREFIX_PATH Sources/Externals)
if(POLICY CMP0054)
# Escape variables in if
cmake_policy(SET CMP0054 OLD)
endif()
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()
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()
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()
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 "NO_OPENSPADES_RESOURCES" 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/openspades/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}")
include_directories("${SDL2_INCLUDE_DIR}")
include_directories("${SDL2_IMAGE_INCLUDE_DIR}")
if(OPENGL_INCLUDE_DIR)
include_directories("${OPENGL_INCLUDE_DIR}")
endif()
include_directories("${GLEW_INCLUDE_DIR}")
include_directories("${ZLIB_INCLUDE_DIR}")
include_directories(${CURL_INCLUDE_DIRS})
include_directories(${FREETYPE_INCLUDE_DIRS})
include_directories(${OpusFile_INCLUDE_DIR})
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}/)
# install asset paks (including non-GPL one)
install(FILES
${CMAKE_BINARY_DIR}/Resources/pak000-Nonfree.pak
${CMAKE_BINARY_DIR}/Resources/pak002-Base.pak
${CMAKE_BINARY_DIR}/Resources/pak005-Models.pak
${CMAKE_BINARY_DIR}/Resources/pak010-BaseSkin.pak
${CMAKE_BINARY_DIR}/Resources/pak050-Locales.pak
${CMAKE_BINARY_DIR}/Resources/pak999-References.pak
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/openspades DESTINATION ${OPENSPADES_INSTALL_BINARY})
# desktop file
INSTALL(FILES Resources/Unix/Desktop/openspades.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)
#see http://www.cmake.org/cmake/help/v2.8.11/cpack.html
set(CPACK_PACKAGE_NAME "OpenSpades")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Open-source clone of Ace of Spades")
set(CPACK_PACKAGE_DESCRIPTION "Open-source clone of Ace of Spades - free FPS sandbox game")
set(CPACK_PACKAGE_VENDOR "yvt, assorted")
set(CPACK_PACKAGE_CONTACT "yvt <i@yvt.jp>")
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 "openspades-${OPENSPADES_FULL_VERSION}")
SET(CPACK_PACKAGE_FILE_NAME "openspades-${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\\\\openspades.exe")
# TODO: set(CPACK_PACKAGE_ICON "")
set(CPACK_NSIS_HELP_LINK "https://sites.google.com/a/yvt.jp/openspades/")
set(CPACK_NSIS_URL_INFO_ABOUT "http://buildandshoot.com/viewforum.php?f=57")
SET(CPACK_NSIS_CONTACT "i@yvt.jp")
# 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 "Open-source clone of Ace of Spades - free FPS sandbox game\n OpenSpades is a clone of Voxlap Ace of Spades 0.75, which is a free \n multiplayer game created by Ben Aksoy.\n .\n Here are some features:\n .\n - Ability to connect to vanilla/pyspades server\n - Better performance on some modern computers/netbooks\n - Sophisticated graphics\n - Fully open source (GPLv3 compliant)\n - Cross-platform")
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 "openspades" "Launch OpenSpades")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY FALSE) #everyone hates a dir inside a zip named exactly like the zip
include(CPack)