forked from Wargus/wargus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
337 lines (282 loc) · 10.9 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
# _________ __ __
# / _____// |_____________ _/ |______ ____ __ __ ______
# \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
# / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
# /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
# \/ \/ \//_____/ \/
# ______________________ ______________________
# 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()
# 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
)
# Additional platform checks
if(NOT (WIN32 AND MSVC))
find_package(PkgConfig QUIET REQUIRED)
endif()
# 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)
find_package(PNG REQUIRED)
find_package(ZLIB REQUIRED)
find_package(StormLib)
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")
set(GAMEDIR "games" CACHE PATH "Where to install games binaries")
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 IS_ABSOLUTE "${GAMEDIR}")
set(GAMEDIRABS "${CMAKE_INSTALL_PREFIX}/${GAMEDIR}")
else()
set(GAMEDIRABS "${GAMEDIR}")
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)
else()
include(CheckCXXSourceCompiles)
set(FS_SRC "
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
int main(int argc, char **argv) {
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)
set(CMAKE_REQUIRED_LIBRARIES stdc++fs)
check_cxx_source_compiles("${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("${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 IS_ABSOLUTE "${SHAREDIR}")
set(DATA_PATH "${CMAKE_INSTALL_PREFIX}/${SHAREDIR}")
else()
set(DATA_PATH "${SHAREDIR}")
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 AND UNIX)
find_program(MAKE make)
if (MAKE)
if (${CMAKE_SYSTEM_NAME} STREQUAL Linux)
message(STATUS "Attempting to build StormLib submodule")
execute_process(COMMAND ${MAKE} -f Makefile.linux WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/StormLib TIMEOUT 240 RESULT_VARIABLE STORM_LIB_MAKE_RESULT OUTPUT_QUIET)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
message(STATUS "Attempting to build StormLib submodule")
execute_process(COMMAND ${MAKE} -f Makefile.mac WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/StormLib TIMEOUT 240 RESULT_VARIABLE STORM_LIB_MAKE_RESULT OUTPUT_QUIET)
endif()
if (${STORM_LIB_MAKE_RESULT} EQUAL 0)
set(STORMLIB_FOUND true)
set(STORMLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/StormLib/src)
set(STORMLIB_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/StormLib/libStorm.a)
message(STATUS "StormLib locally built and included")
else()
message(STATUS "StormLib NOT built successfully")
endif()
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(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/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()