-
Notifications
You must be signed in to change notification settings - Fork 18
/
CMakeLists.txt
351 lines (297 loc) · 10.6 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
cmake_minimum_required (VERSION 2.8)
project(savagewheels)
### Defaults
set(APP_ARCH "")
set(APP_VER_MAJ "1")
set(APP_VER_MIN "6")
set(APP_VER_PATCH "1")
### check for required libs
find_package(SDL REQUIRED)
### Install targets
if (UNIX)
include (GNUInstallDirs)
else()
if (NOT INSTALL_DIR)
set(INSTALL_DIR "./")
endif()
set(CMAKE_INSTALL_BINDIR "${INSTALL_DIR}")
set(CMAKE_INSTALL_SBINDIR "${INSTALL_DIR}")
set(CMAKE_INSTALL_LIBEXECDIR "${INSTALL_DIR}")
set(CMAKE_INSTALL_SYSCONFDIR "${INSTALL_DIR}")
set(CMAKE_INSTALL_SHAREDSTATEDIR "${INSTALL_DIR}")
set(CMAKE_INSTALL_LOCALSTATEDIR "${INSTALL_DIR}")
set(CMAKE_INSTALL_LIBDIR "${INSTALL_DIR}")
set(CMAKE_INSTALL_INCLUDEDIR "${INSTALL_DIR}")
set(CMAKE_INSTALL_OLDINCLUDEDIR "${INSTALL_DIR}")
set(CMAKE_INSTALL_DATAROOTDIR "${INSTALL_DIR}")
set(CMAKE_INSTALL_DATADIR "${INSTALL_DIR}")
set(CMAKE_INSTALL_INFODIR "${INSTALL_DIR}")
set(CMAKE_INSTALL_LOCALEDIR "${INSTALL_DIR}")
set(CMAKE_INSTALL_MANDIR "${INSTALL_DIR}")
set(CMAKE_INSTALL_DOCDIR "${INSTALL_DIR}")
endif()
### sources
include_directories(src/)
include_directories(tinyxml/)
set(
SOURCES
src/CBufferedReader.cpp
src/Bindings.cpp
src/CDeadToy.cpp
src/CKdf.cpp
src/CSdl.cpp
src/CSwv_module.cpp
src/CVehicle.cpp
src/Utils.cpp
src/CAnimation.cpp
src/CGame.cpp
src/CMainMenu.cpp
src/CSounds.cpp
src/CTimer.cpp
src/Main.cpp
tinyxml/tinystr.cpp
tinyxml/tinyxml.cpp
tinyxml/tinyxmlerror.cpp
tinyxml/tinyxmlparser.cpp
)
### specify executable
set(RES_FILES "")
if(MINGW)
# include a Windows resource file
set(RES_FILES "src/res.rc")
set(CMAKE_RC_COMPILER_INIT windres)
ENABLE_LANGUAGE(RC)
SET(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
add_executable(savagewheels ${SOURCES} ${RES_FILES})
else()
add_executable(savagewheels ${SOURCES})
endif()
### add required libarires
## libstdc runtime on Windows
if (WIN32)
# Static linkage of the gcc libs
#add_definitions(-static-libgcc)
#add_definitions(-static-libstdc++)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
endif()
## SDL
if (UNIX AND NOT WIN32)
# Linux
# set(SDL_LIB_NAME "libSDL.so")
# find_library(
# SDL_LIBRARY_SO
# NAMES ${SDL_LIB_NAME}
# PATHS "/usr/lib" "/usr/local/lib/"
# HINTS $ENV{SDLDIR} ${SDL_LIBRARY} "${CMAKE_CURRENT_SOURCE_DIR}/libs")
add_definitions(`sdl-config --cflags`)
add_definitions(`sdl-config --libs`)
else()
# Windows
set(SDL_LIB_NAME "SDL.dll")
add_definitions(-lpthread)
include_directories(${SDL_INCLUDE_DIR})
link_directories($ENV{SDLDIR}\\lib)
set(SDL_LIBRARY_SO $ENV{SDLDIR}\\bin\\SDL.dll)
message(STATUS "Found libSDL.so/DLL at ${SDL_LIBRARY}")
# copy the SDL DLL file to the install dir
add_custom_command(TARGET savagewheels POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${SDL_LIBRARY_SO}
$<TARGET_FILE_DIR:savagewheels>)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/SDL.dll" DESTINATION ${INSTALL_DIR})
endif()
## SOUND libraries
if (SOUND STREQUAL "NO")
message(STATUS "Found SOUND=NO option. Compiling without sound support!")
elseif(SOUND STREQUAL "FMOD")
# FModEx API
# check if path to FMod is defined
if(NOT DEFINED FMOD_PATH)
set(FMOD_PATH "${CMAKE_CURRENT_SOURCE_DIR}/libs/fmod/api")
endif()
add_definitions(-I${FMOD_PATH}/inc)
link_directories(${FMOD_PATH}/lib)
if (UNIX AND NOT WIN32)
# Linux
if (CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT M32)
set(FMOD_LIB_NAME "libfmodex64.so")
set(FMOD_SO_NAME "libfmodex64.so")
else()
set(FMOD_LIB_NAME "libfmodex.so")
set(FMOD_SO_NAME "libfmodex.so")
endif()
# just in case check also in the system folders
add_definitions(-I/usr/include/fmodex)
else()
# Windows
set(FMOD_LIB_NAME "libfmodex.a")
if (CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT M32)
set(FMOD_SO_NAME "fmodex64.dll")
else()
set(FMOD_SO_NAME "fmodex.dll")
endif()
endif()
# add FMod Ex (if present)
find_library(
FMOD_LIBRARY
NAMES ${FMOD_LIB_NAME}
PATHS "/usr/lib" "/usr/local/lib/"
HINTS "${FMOD_PATH}/lib")
find_library(
FMOD_LIBRARY_SO_PATH
NAMES ${FMOD_SO_NAME}
PATHS "/usr/lib" "/usr/local/lib/"
HINTS "${FMOD_PATH}" "${FMOD_PATH}/lib")
if (NOT FMOD_LIBRARY)
message(STATUS "FModEx lib - ${FMOD_LIB_NAME} not found! Will compile without sound support.")
else()
message(STATUS "Found FModEx lib at ${FMOD_LIBRARY}. Found FModEx DLL at ${FMOD_LIBRARY_SO_PATH}.")
add_definitions(-DWITH_FMOD)
if (WIN32)
add_custom_command(TARGET savagewheels POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${FMOD_LIBRARY_SO_PATH}"
"$<TARGET_FILE_DIR:savagewheels>")
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${FMOD_SO_NAME}"
DESTINATION "${INSTALL_DIR}")
endif()
endif()
else()
# SDL_mixer API
find_package(SDL_mixer REQUIRED)
add_definitions(-DWITH_SDLMIXER)
set(SOUND "SDL_MIXER")
# Copy SDL_mixer.dll and libmikmod-2.dll to installation directory
if (WIN32)
INSTALL(FILES "${SDL_MIXER_LIBRARIES}" DESTINATION ${INSTALL_DIR})
# Find mikmod DLL for playing music
find_library(SDL_MIXER_MIKMOD_LIBRARY
NAMES libmikmod-2
HINTS
ENV SDLMIXERDIR
ENV SDLDIR
PATH_SUFFIXES lib)
if (NOT SDL_MIXER_MIKMOD_LIBRARY)
message(STATUS "SDL_mixer libmikmod-2 dependency was NOT FOUND! Game will run WITHOUT music.")
endif()
INSTALL(FILES "${SDL_MIXER_MIKMOD_LIBRARY}" DESTINATION ${INSTALL_DIR})
endif()
endif()
### link required libraries
target_link_libraries(savagewheels ${SDL_LIBRARY} ${FMOD_LIBRARY} ${SDLMIXER_LIBRARY})
### additional defines
if (UNIX AND NOT WIN32)
add_definitions(-DLINUX_BUILD)
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-g -D_DEBUG -DDEBUG) # -Wextra -Wall
else()
add_definitions(-O3 -DNDEBUG)
endif()
message(STATUS "Build type is ${CMAKE_BUILD_TYPE}")
### set architecture
if (CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT M32)
add_definitions(-DARCH_X64)
set(APP_ARCH "x64")
set(DEB_ARCH "amd64")
else()
add_definitions(-DARCH_X86)
set(APP_ARCH "x86")
set(DEB_ARCH "i386")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
endif()
### Configure compile time header file
configure_file (
"${PROJECT_SOURCE_DIR}/Config.h.in"
"${PROJECT_SOURCE_DIR}/src/Config.h")
if (UNIX AND NOT WIN32)
# address Arch Linux packaging by explicitly specifying data dirs
if (NOT INSTALL_DATADIR)
set(INSTALL_DATADIR "${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}")
endif()
if (NOT INSTALL_LIBEXECDIR)
set(INSTALL_LIBEXECDIR "${CMAKE_INSTALL_FULL_LIBEXECDIR}/${PROJECT_NAME}")
endif()
configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/savagewheels.in"
"${CMAKE_CURRENT_BINARY_DIR}/savagewheels.sh"
@ONLY)
INSTALL(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/savagewheels.sh"
DESTINATION "${CMAKE_INSTALL_BINDIR}" RENAME savagewheels)
# add run.sh if building a static distro
if (CMAKE_BUILD_STATIC)
INSTALL(PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/run.sh"
DESTINATION "./")
endif()
endif()
INSTALL(TARGETS savagewheels RUNTIME DESTINATION "${INSTALL_LIBEXECDIR}")
INSTALL(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/README.md"
"${CMAKE_CURRENT_SOURCE_DIR}/HISTORY"
"${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
"${CMAKE_CURRENT_SOURCE_DIR}/bin/LICENSE.mikmod.txt"
"${CMAKE_CURRENT_SOURCE_DIR}/bin/Readme.html"
"${CMAKE_CURRENT_SOURCE_DIR}/bin/README-SDL_mixer.txt"
"${CMAKE_CURRENT_SOURCE_DIR}/bin/README-SDL.txt"
DESTINATION "${CMAKE_INSTALL_DOCDIR}")
INSTALL(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/bin/bindings.xml"
DESTINATION "${INSTALL_DATADIR}")
INSTALL(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/help"
DESTINATION "${CMAKE_INSTALL_DOCDIR}"
PATTERN "debug.html" EXCLUDE
PATTERN "pref" EXCLUDE)
# add data folders only if they are already present
if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/autos")
INSTALL(DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}/bin/autos"
DESTINATION "${INSTALL_DATADIR}")
endif()
if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/sound")
INSTALL(DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}/bin/sound"
DESTINATION "${INSTALL_DATADIR}")
endif()
if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/graphics")
INSTALL(DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}/bin/graphics"
DESTINATION "${INSTALL_DATADIR}")
endif()
### build a CPack driven installer package
include (InstallRequiredSystemLibraries)
if (NOT CPACK_GENERATOR AND (UNIX AND NOT WIN32))
set(CPACK_GENERATOR "STGZ")
else()
set(CPACK_GENERATOR "ZIP")
endif()
set(CPACK_PACKAGE_NAME "SavageWheels")
set(CPACK_PACKAGE_VENDOR "Petar Petrov")
set(CPACK_PACKAGE_CONTACT "petar.petrov.georgiev(at-)gmail[dot)com")
set(CPACK_PACKAGE_VERSION_MAJOR "${APP_VER_MAJ}")
set(CPACK_PACKAGE_VERSION_MINOR "${APP_VER_MIN}")
set(CPACK_PACKAGE_VERSION_PATCH "${APP_VER_PATCH}")
set(PCKVER "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}" )
set(CPACK_PACKAGE_VERSION ${PCKVER})
set(CPACK_PACKAGE_FILE_NAME "savagewheels-${PCKVER}-${CMAKE_SYSTEM_NAME}-${APP_ARCH}")
#set(CPACK_PACKAGE_INSTALL_DIRECTORY "savagewheels-${PCKVER}")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
# Debian DEB package stuff
if (${CPACK_GENERATOR} STREQUAL "DEB")
set(CPACK_PACKAGING_INSTALL_PREFIX "/opt")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DEB_ARCH})
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libstdc++6, libsdl1.2debian (>= 1.2.11)")
# require SDL_mixer if support is enabled
if(SOUND STREQUAL "SDL_MIXER")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libsdl-mixer1.2 (>= 1.2.12)")
endif()
endif()
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
#set(CPACK_INSTALLED_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/bin;/.")
#set(CPACK_IGNORE_FILES
#"~$"
#"^.*/.git/"
#"^${PROJECT_SOURCE_DIR}/bin/pref"
#"^${PROJECT_SOURCE_DIR}/bin/debug.html"
#)
set(CPACK_PACKAGE_EXECUTABLES "savagewheels" "Savage Wheels Game")
include (CPack)