-
Notifications
You must be signed in to change notification settings - Fork 55
/
CMakeLists.txt
389 lines (328 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
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
# _________ __ __
# / _____// |_____________ _/ |______ ____ __ __ ______
# \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
# / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
# /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
# \/ \/ \//_____/ \/
# ______________________ ______________________
# T H E W A R B E G I N S
# Stratagus - A free fantasy real time strategy game engine
#
# CMakeLists.txt
# Copyright (C) 2011-2016 Pali Rohár <[email protected]>
# cybermind <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
project(wargus)
cmake_minimum_required(VERSION 3.10)
cmake_policy(VERSION 3.10..3.20.2)
set(WARGUS_VERSION 2.4.1)
set(CMAKE_CXX_STANDARD 17)
if(EXISTS ${WIN32_CMAKE_PREFIX_PATH})
list(APPEND CMAKE_PREFIX_PATH "${WIN32_CMAKE_PREFIX_PATH}")
message("Using prefix path ${CMAKE_PREFIX_PATH}")
endif()
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/third-party/CMakeLists.txt")
add_subdirectory(third-party)
else()
message(WARNING "Third-party directory not populated, cannot vendor any dependencies.")
endif()
option(ENABLE_VENDORED_LIBS OFF)
# Wargus sources
set(pudconvert_SRCS
pud.cpp
pudconvert.cpp
)
set(pudconvert_HDRS
endian.h
pud.h
)
set(wartool_SRCS
pud.cpp
wartool.cpp
xmi2mid.cpp
)
set(wartool_HDRS
wartool.h
endian.h
pud.h
xmi2mid.h
)
set(wargus_SRCS
wargus.cpp
)
if(WIN32)
set(wargus_SRCS
${wargus_SRCS}
wargus.rc
)
set(wartool_SRCS
${wartool_SRCS}
rip_music_win32.cpp
)
else()
set(wartool_SRCS
${wartool_SRCS}
rip_music_unix.cpp
)
endif()
set(warextract_SRCS
warextract.c
)
# Find all libraries
option(ENABLE_STATIC "Compile Wargus binaries as static executable" OFF)
if(ENABLE_STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.a")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
find_package(Stratagus REQUIRED)
if(ENABLE_VENDORED_LIBS)
vendored_png()
vendored_zlib()
vendored_bzip2()
set(STORMLIB_FOUND false)
else()
find_package(PNG REQUIRED)
find_package(ZLIB REQUIRED)
find_package(StormLib)
endif()
if(WIN32)
find_package(MakeNSIS)
endif()
find_package(SelfPackers)
# Windows RC compiler definitions
if(WIN32)
enable_language(RC)
include(CMakeDetermineRCCompiler)
if(MINGW)
set(CMAKE_RC_COMPILER_INIT windres)
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
endif()
endif()
# Options for compiling
if(WIN32)
option(ENABLE_NSIS "Create Stratagus Window NSIS Installer" OFF)
endif()
option(ENABLE_UPX "Compress Stratagus executable binary with UPX packer" OFF)
option(ENABLE_STRIP "Strip all symbols from executables" OFF)
option(WITH_STORMLIB "Compile wartool with StormLib support" ON)
# Install paths
set(BINDIR "bin" CACHE PATH "Where to install user binaries")
if(NOT DEFINED GAMEDIR)
set(GAMEDIR "games" CACHE PATH "Where to install games binaries")
endif()
set(SHAREDIR "share/games/stratagus/wargus" CACHE PATH "Where to install data files")
set(DATAROOTDIR "${CMAKE_INSTALL_PREFIX}/share" CACHE PATH "Sets the root of data directories to a non-default location")
set(ICONDIR "${DATAROOTDIR}/pixmaps" CACHE PATH "Sets the icon directory for desktop entry to a non-default location.")
set(DESKTOPDIR "${DATAROOTDIR}/applications" CACHE PATH "Sets the desktop file directory for desktop entry to a non-default location.")
if(NOT DEFINED GAMEDIRABS)
if(NOT IS_ABSOLUTE "${GAMEDIR}")
set(GAMEDIRABS "${CMAKE_INSTALL_PREFIX}/${GAMEDIR}/")
else()
set(GAMEDIRABS "${GAMEDIR}/")
endif()
endif()
# Wargus definitions
add_definitions(${PNG_DEFINITIONS})
include_directories(${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS} ${STRATAGUS_INCLUDE_DIR})
set(pudconvert_LIBS ${pudconvert_LIBS} ${ZLIB_LIBRARIES})
set(wartool_LIBS ${pudconvert_LIBS} ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
# Platform definitions
if(WIN32 AND MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE=1)
endif()
include(CheckCXXSourceCompiles)
set(FS_SRC "
#include <filesystem>
namespace fs = std::filesystem;
int main() {
fs::path p = fs::path(\".\");
if (fs::absolute(p).is_absolute()) {
return 0;
} else {
return 1;
}
}
")
check_cxx_source_compiles("${FS_SRC}" HAS_17_FS)
if(NOT HAS_17_FS) # Tr
set(EXPERIMENTAL_FS_SRC "
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
int main() {
fs::path p = fs::path(\".\");
if (fs::absolute(p).is_absolute()) {
return 0;
} else {
return 1;
}
}
")
check_cxx_source_compiles("${EXPERIMENTAL_FS_SRC}" HAS_17_EXPERIMENTAL_FS)
if(NOT HAS_17_EXPERIMENTAL_FS)
set(CMAKE_REQUIRED_LIBRARIES stdc++fs)
check_cxx_source_compiles("${EXPERIMENTAL_FS_SRC}" HAS_EXP_17_FS_WITH_STDC)
if(HAS_EXP_17_FS_WITH_STDC)
set(wargus_LIBS ${wargus_LIBS} stdc++fs)
set(wartool_LIBS ${wartool_LIBS} stdc++fs)
else()
set(CMAKE_REQUIRED_LIBRARIES c++fs)
check_cxx_source_compiles("${EXPERIMENTAL_FS_SRC}" HAS_EXP_17_FS_WITH_CLIB)
if(HAS_EXP_17_FS_WITH_CLIB)
set(wargus_LIBS ${wargus_LIBS} c++fs)
set(wartool_LIBS ${wartool_LIBS} c++fs)
else()
message(FATAL_ERROR "I don't know how to compile with C++17 filesystem support on your system")
endif()
endif()
endif()
endif()
if(NOT WIN32)
include_directories(${X11_INCLUDE_DIR} ${GTK2_INCLUDE_DIRS})
set(wargus_LIBS ${wargus_LIBS} ${X11_X11_LIB} ${GTK2_LIBRARIES})
endif()
if (NOT WIN32)
if(NOT DEFINED DATA_PATH)
if(NOT IS_ABSOLUTE "${SHAREDIR}")
set(DATA_PATH "${CMAKE_INSTALL_PREFIX}/${SHAREDIR}")
else()
set(DATA_PATH "${SHAREDIR}")
endif()
endif()
add_definitions(-DDATA_PATH="${DATA_PATH}")
add_definitions(-DSCRIPTS_PATH="${DATA_PATH}")
add_definitions(-DSTRATAGUS_BIN="${STRATAGUS}")
endif()
if(ENABLE_STRIP)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s")
endif()
# For now, doesn't compile on OS X with StormLib
if (WITH_STORMLIB)
if (NOT STORMLIB_FOUND)
set(BUILD_STORMLIB true)
include(ExternalProject)
message(STATUS "Will build StormLib as part of compilation.")
if(ENABLE_VENDORED_LIBS)
set(
STORM_CMAKE_CACHE_ARGS
-DZLIB_FOUND:STRING=1 -DZLIB_INCLUDE_DIR:PATH=${ZLIB_INCLUDE_DIR} -DZLIB_LIBRARY:FILEPATH=${ZLIB_LIBRARIES}
-DBZIP2_FOUND:STRING=1 -DBZIP2_INCLUDE_DIR:PATH=${BZIP2_INCLUDE_DIR} -DBZIP2_LIBRARIES:FILEPATH=${BZIP2_LIBRARIES}
)
endif()
ExternalProject_Add(StormLib
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/StormLib/"
SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/StormLib/"
INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/StormLib/"
CMAKE_ARGS -DSTORM_SKIP_INSTALL=ON
CMAKE_CACHE_ARGS ${STORM_CMAKE_CACHE_ARGS}
INSTALL_COMMAND ""
)
set(STORMLIB_FOUND true)
set(STORMLIB_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/StormLib/src)
if(MSVC)
set(STORMLIB_LIBRARY "${CMAKE_CURRENT_BINARY_DIR}/StormLib/src/StormLib-build/$<CONFIGURATION>/storm.lib")
else()
set(STORMLIB_LIBRARY "${CMAKE_CURRENT_BINARY_DIR}/StormLib/src/StormLib-build/libstorm.a")
endif()
endif()
if (STORMLIB_FOUND)
add_definitions(-DUSE_STORMLIB -D__STORMLIB_SELF__)
include_directories(${STORMLIB_INCLUDE_DIR})
set(wartool_LIBS ${wartool_LIBS} ${STORMLIB_LIBRARY} ${BZIP2_LIBRARIES})
endif()
endif()
# Compile Wargus
add_executable(pudconvert ${pudconvert_SRCS} ${pudconvert_HDRS})
target_link_libraries(pudconvert ${pudconvert_LIBS})
add_executable(wargus WIN32 ${wargus_SRCS} ${wargus_HDRS})
target_link_libraries(wargus ${wargus_LIBS})
add_executable(wartool ${wartool_SRCS} ${wartool_HDRS})
target_link_libraries(wartool ${wartool_LIBS})
if(BUILD_STORMLIB)
add_dependencies(wargus StormLib)
add_dependencies(wartool StormLib)
add_dependencies(pudconvert StormLib)
endif()
if(ENABLE_VENDORED_LIBS)
add_dependencies(wargus png zlib)
add_dependencies(wartool png zlib)
add_dependencies(pudconvert png zlib)
endif()
if(WIN32 AND MINGW AND ENABLE_STATIC)
set_target_properties(pudconvert PROPERTIES LINK_FLAGS "${LINK_FLAGS} -static-libgcc -static-libstdc++")
set_target_properties(wargus PROPERTIES LINK_FLAGS "${LINK_FLAGS} -static-libgcc -static-libstdc++")
set_target_properties(wartool PROPERTIES LINK_FLAGS "${LINK_FLAGS} -static-libgcc -static-libstdc++")
endif()
########### next target ###############
macro(self_packer PACKER_TARGET)
get_target_property(PACKER_NAME ${PACKER_TARGET} OUTPUT_NAME)
if(NOT PACKER_NAME)
set(PACKER_NAME ${PACKER_TARGET})
endif()
add_custom_command(TARGET ${PACKER_TARGET} POST_BUILD
COMMAND ${SELF_PACKER_FOR_EXECUTABLE}
ARGS ${SELF_PACKER_FOR_EXECUTABLE_FLAGS} ${PACKER_NAME}${CMAKE_EXECUTABLE_SUFFIX}
)
endmacro()
if(ENABLE_UPX AND SELF_PACKER_FOR_EXECUTABLE)
self_packer(pudconvert)
self_packer(wargus)
self_packer(wartool)
endif()
########### next target ###############
if(WIN32 AND ENABLE_NSIS AND MAKENSIS_FOUND)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/COPYING DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/COPYING-3rd DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/wargus.ico DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
add_custom_command(OUTPUT Wargus-${WARGUS_VERSION}${MAKENSIS_SUFFIX}
COMMAND ${MAKENSIS} ${MAKENSIS_FLAGS} -DPORTABLE=1 -DCMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}" -DCMAKE_CURRENT_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}" ${CMAKE_CURRENT_SOURCE_DIR}/wargus.nsi
COMMAND ${MAKENSIS} ${MAKENSIS_FLAGS} -DCMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}" -DCMAKE_CURRENT_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}" ${CMAKE_CURRENT_SOURCE_DIR}/wargus.nsi
DEPENDS wargus.nsi pudconvert wargus wartool COPYING COPYING-3rd wargus.ico
COMMENT "Generating Wargus Windows NSIS Installers" VERBATIM
)
add_custom_target(nsis ALL DEPENDS Wargus-${WARGUS_VERSION}${MAKENSIS_SUFFIX})
endif()
if (WIN32 AND MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}")
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE=1)
set_target_properties(pudconvert PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
set_target_properties(wartool PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
endif()
########### next target ###############
configure_file (
"${PROJECT_SOURCE_DIR}/wargus.desktop.in"
"${PROJECT_BINARY_DIR}/wargus.desktop"
)
########### install files ###############
install(TARGETS wargus DESTINATION ${GAMEDIR})
install(TARGETS pudconvert wartool DESTINATION ${BINDIR})
install(FILES wargus.png DESTINATION ${ICONDIR})
install(FILES "${PROJECT_BINARY_DIR}/wargus.desktop" DESTINATION ${DESKTOPDIR})
install(DIRECTORY shaders contrib campaigns maps scripts DESTINATION ${SHAREDIR})
install(FILES contrib/red_cross.png DESTINATION ${SHAREDIR}/graphics/missiles)
install(FILES contrib/cross.png DESTINATION ${SHAREDIR}/graphics/ui/cursors)
install(FILES contrib/black_title.png contrib/food.png contrib/health.png contrib/health2.png contrib/mana.png contrib/mana2.png contrib/ore,stone,coal.png contrib/score.png DESTINATION ${SHAREDIR}/graphics/ui)
# uninstall target
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()