forked from teamhimeh/simutrans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
374 lines (311 loc) · 11.7 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
#
# This file is part of the Simutrans project under the Artistic License.
# (see LICENSE.txt)
#
cmake_minimum_required(VERSION 3.16)
# Disable in-source builds
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "Building Simutrans in-source is not supported. "
"Please delete ${CMAKE_SOURCE_DIR}/CMakeCache.txt and configure in a different "
"(preferrably empty) directory.")
endif (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
set(CMAKE_WARN_DEPRECATED ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/")
include(SimutransVcpkgTriplet)
project(simutrans LANGUAGES C CXX)
# Force C++11 everywhere
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS OFF)
include(TestBigEndian)
TEST_BIG_ENDIAN(SIMUTRANS_BIG_ENDIAN)
if (MINGW)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ON)
set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")
endif ()
if (APPLE)
link_directories(/usr/local/lib)
endif ()
#
# Dependencies
#
find_package(CCache)
find_package(ZLIB REQUIRED)
find_package(BZip2 REQUIRED)
find_package(PNG REQUIRED)
find_package(MiniUPNP)
if (MSVC)
find_package(ZSTD)
find_package(SDL2)
find_package(Freetype)
find_package(FluidSynth)
else ()
find_package(PkgConfig MODULE REQUIRED)
pkg_check_modules(ZSTD IMPORTED_TARGET libzstd)
pkg_check_modules(SDL2 IMPORTED_TARGET sdl2)
pkg_check_modules(Freetype IMPORTED_TARGET freetype2)
pkg_check_modules(FluidSynth IMPORTED_TARGET fluidsynth>=2.1.0)
endif ()
set(CMAKE_THREAD_PREFER_PTHREAD ON)
find_package(Threads)
#
# Configuration options
#
include(SimutransBackend) # Select backend (SDL2 / GDI)
include(SimutransCompileOptions)
# CMake does not fill in CMAKE_BUILD_TYPE automatically.
if (NOT MSVC)
if (CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Build type. Valid values are Debug Release MinSizeRel RelWithDebInfo" FORCE)
endif ()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release MinSizeRel RelWithDebInfo)
endif (NOT MSVC)
#
# output directory
#
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/simutrans)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/simutrans)
#
# sources
#
add_executable(simutrans MACOSX_BUNDLE)
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set_target_properties(simutrans PROPERTIES WIN32_EXECUTABLE 1)
endif ()
include(SimutransSourceList)
#
# Generate revision on compile time (so only if needed)
#
string(FIND ${CMAKE_GENERATOR} "Visual Studio" VS )
if (${VS} EQUAL 0)
# using a script for MSVC project files
file(WRITE ${CMAKE_SOURCE_DIR}/revision.h "#define REVISION \n")
add_custom_command(TARGET simutrans PRE_BUILD WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND cscript.exe /Nologo revision.jse COMMENT "Find SVN revision")
else ()
# using custom target svnhear that is always built to update the revision.h file using cmake script
add_custom_target(svnheader ALL DEPENDS svn_header)
add_custom_command(OUTPUT svn_header COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_SOURCE_DIR} -P ${CMAKE_MODULE_PATH}/SimutransRevision.cmake)
set_source_files_properties(${CMAKE_SOURCE_DIR}/revision.h PROPERTIES GENERATED TRUE HEADER_FILE_ONLY TRUE)
add_dependencies(simutrans svnheader)
endif ()
#
# Libraries
#
target_link_libraries(simutrans PRIVATE PNG::PNG)
if (WIN32)
target_sources(simutrans PRIVATE simres.rc)
target_sources(simutrans PRIVATE sys/clipboard_w32.cc)
target_link_libraries(simutrans PRIVATE ws2_32 winmm)
# Backup sound and music routines if the selected backend does not provide any routines
set(BACKUP_SOUND sound/win32_sound_xa.cc)
set(BACKUP_MUSIC music/w32_midi.cc)
else ()
if (SIMUTRANS_BACKEND STREQUAL "sdl2")
target_sources(simutrans PRIVATE sys/clipboard_s2.cc)
else ()
target_sources(simutrans PRIVATE sys/clipboard_internal.cc)
endif ()
if (APPLE)
set(BACKUP_SOUND sound/AVF_core-audio_sound.mm sound/core-audio_sound.mm)
set(BACKUP_MUSIC music/AVF_core-audio_midi.mm music/core-audio_midi.mm)
else ()
set(BACKUP_SOUND sound/no_sound.cc)
set(BACKUP_MUSIC music/no_midi.cc)
endif ()
endif ()
if (SIMUTRANS_MULTI_THREAD)
target_compile_definitions(simutrans PRIVATE MULTI_THREAD=1)
target_link_libraries(simutrans PRIVATE Threads::Threads)
endif (SIMUTRANS_MULTI_THREAD)
if (SIMUTRANS_BACKEND STREQUAL "sdl2")
target_sources(simutrans PRIVATE display/simgraph16.cc sys/simsys_s2.cc sound/sdl2_sound.cc)
target_include_directories(simutrans PRIVATE ${SDL2_INCLUDE_DIRS})
if (MINGW)
target_link_libraries(simutrans PRIVATE ${SDL2_STATIC_LIBRARIES})
elseif (APPLE)
target_link_libraries(simutrans PRIVATE ${SDL2_LIBRARIES})
elseif (MSVC)
target_link_libraries(simutrans PRIVATE SDL2::SDL2)
else ()
target_link_libraries(simutrans PRIVATE PkgConfig::SDL2)
endif ()
target_compile_definitions(simutrans PRIVATE COLOUR_DEPTH=16)
elseif (SIMUTRANS_BACKEND STREQUAL "gdi")
target_sources(simutrans PRIVATE display/simgraph16.cc sys/simsys_w.cc ${BACKUP_SOUND} )
target_link_libraries(simutrans PRIVATE imm32 xaudio2_8)
target_compile_definitions(simutrans PRIVATE COLOUR_DEPTH=16)
else ()
if (NOT SIMUTRANS_BACKEND STREQUAL "none")
message(WARNING "Unknown backend '${SIMUTRANS_BACKEND}', falling back to headless compilation")
endif ()
target_sources(simutrans PRIVATE display/simgraph0.cc sys/simsys_posix.cc sound/no_sound.cc music/no_midi.cc)
target_compile_definitions(simutrans PRIVATE COLOUR_DEPTH=0)
endif ()
#
# Link dependencies
#
target_link_libraries(simutrans PRIVATE ZLIB::ZLIB)
target_link_libraries(simutrans PRIVATE BZip2::BZip2)
if (SIMUTRANS_USE_FREETYPE)
target_include_directories(simutrans PRIVATE ${Freetype_INCLUDE_DIRS})
if (MINGW)
target_link_libraries(simutrans PRIVATE ${Freetype_STATIC_LIBRARIES})
elseif (APPLE)
target_link_libraries(simutrans PRIVATE ${Freetype_LIBRARIES})
elseif (MSVC)
target_link_libraries(simutrans PRIVATE Freetype::Freetype)
else ()
target_link_libraries(simutrans PRIVATE PkgConfig::Freetype)
endif ()
target_compile_definitions(simutrans PRIVATE USE_FREETYPE=1)
endif (SIMUTRANS_USE_FREETYPE)
if (SIMUTRANS_USE_UPNP)
target_compile_definitions(simutrans PRIVATE USE_UPNP=1)
target_link_libraries(simutrans PRIVATE MiniUPNP::MiniUPNP)
endif (SIMUTRANS_USE_UPNP)
if (SIMUTRANS_USE_ZSTD)
target_sources(simutrans PRIVATE io/rdwr/zstd_file_rdwr_stream.cc)
target_include_directories(simutrans PRIVATE ${ZSTD_INCLUDE_DIRS})
target_compile_definitions(simutrans PRIVATE USE_ZSTD=1)
if (MSVC)
target_link_libraries(simutrans PRIVATE zstd::libzstd_static)
elseif (MINGW)
# only 64 bit cmake, 32 bit is broken
target_link_libraries(simutrans PRIVATE -lzstd)
else()
target_link_libraries(simutrans PRIVATE PkgConfig::ZSTD)
endif ()
endif (SIMUTRANS_USE_ZSTD)
# only consider FluidSynth for SDL2 and GDI backends
if ((SIMUTRANS_BACKEND STREQUAL "sdl2") OR (SIMUTRANS_BACKEND STREQUAL "gdi"))
if (SIMUTRANS_USE_FLUIDSYNTH_MIDI)
target_sources(simutrans PRIVATE music/fluidsynth.cc gui/loadsoundfont_frame.cc)
target_compile_definitions(simutrans PRIVATE USE_FLUIDSYNTH_MIDI=1)
if (MINGW)
# not working because fluidsynth doesn't set static libraries for pkgconf
#target_link_libraries(simutrans PRIVATE ${FluidSynth_STATIC_LIBRARIES})
# manually linking them instead, until it is fixed
target_link_libraries(simutrans PRIVATE -lfluidsynth -lharfbuzz -lgraphite2 -lglib-2.0 -lintl -liconv -ldsound -lole32 -lws2_32 -lgomp -lksuser)
elseif (MSVC)
target_link_libraries(simutrans PRIVATE ${FluidSynth_LIBRARIES})
else ()
target_link_libraries(simutrans PRIVATE PkgConfig::FluidSynth)
endif (MINGW)
else ()
target_sources( simutrans PRIVATE ${BACKUP_MUSIC} )
endif (SIMUTRANS_USE_FLUIDSYNTH_MIDI)
endif ((SIMUTRANS_BACKEND STREQUAL "sdl2") OR (SIMUTRANS_BACKEND STREQUAL "gdi"))
#
# compile options
#
if (MSVC)
target_link_options(simutrans PRIVATE /INCREMENTAL:NO /NODEFAULTLIB:LIBCMTD /MANIFEST:NO /LARGEADDRESSAWARE)
endif ()
if (SIMUTRANS_BIG_ENDIAN)
target_compile_definitions(simutrans PRIVATE SIM_BIG_ENDIAN=1)
endif ()
if (SIMUTRANS_VALGRIND_SUPPORT)
add_definitions(-DUSE_VALGRIND_MEMCHECK=1)
endif ()
if (SIMUTRANS_ENABLE_PROFILING)
add_definitions(-DPROFILE=1)
endif ()
target_compile_options(simutrans PRIVATE ${SIMUTRANS_COMMON_COMPILE_OPTIONS})
target_compile_definitions(simutrans PRIVATE $<IF:$<CONFIG:Debug>,DEBUG=1,>)
target_compile_definitions(simutrans PRIVATE $<IF:$<CONFIG:Release>,NDEBUG=1,>)
target_compile_definitions(simutrans PRIVATE MSG_LEVEL=${SIMUTRANS_MSG_LEVEL})
if (SIMUTRANS_AUTOJOIN_PUBLIC)
target_compile_definitions(simutrans PRIVATE AUTOJOIN_PUBLIC=1)
endif ()
if (SIMUTRANS_ENABLE_WATERWAY_SIGNS)
target_compile_definitions(simutrans PRIVATE ENABLE_WATERWAY_SIGNS=1)
endif ()
if (SIMUTRANS_USE_SYSLOG)
target_compile_definitions(simutrans PRIVATE SYSLOG=1)
endif ()
if (SIMUTRANS_DEBUG_FLUSH_BUFFER)
target_compile_definitions(simutrans PRIVATE DEBUG_FLUSH_BUFFER=1)
endif ()
if (SIMUTRANS_USE_IP4_ONLY)
target_compile_definitions(simutrans PRIVATE USE_IP4_ONLY=1)
endif ()
if (SIMUTRANS_STEAM_BUILT)
target_compile_definitions(simutrans PRIVATE STEAM_BUILT=1)
endif ()
if (APPLE)
target_compile_definitions(simutrans PRIVATE ALT_SDL_DIR=1)
endif (APPLE)
#
# Package
#
if (APPLE)
include(MacBundle)
endif ()
#
# Tests
#
add_custom_target(test
$<TARGET_FILE:simutrans>
-set_workdir ${CMAKE_CURRENT_SOURCE_DIR}/simutrans
-objects pak
-scenario automated-tests
-debug 2
-lang en
-fps 100
DEPENDS simutrans
)
#
# Installation
#
install(TARGETS simutrans RUNTIME DESTINATION "${CMAKE_BINARY_DIR}/simutrans/" BUNDLE DESTINATION "${CMAKE_BINARY_DIR}/simutrans/")
install(DIRECTORY "${CMAKE_SOURCE_DIR}/simutrans" DESTINATION "${CMAKE_BINARY_DIR}")
# download language files
if (MSVC)
# MSVC has no variable on teh install target path at execution time, which is why we expand the directories at creation time!
install(CODE "execute_process(COMMAND powershell -ExecutionPolicy Bypass -File ${CMAKE_SOURCE_DIR}/get_lang_files.ps1 WORKING_DIRECTORY ${simutrans_BINARY_DIR})")
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
install(CODE "execute_process(COMMAND powershell -Command \"Remove-Item \'${simutrans_BINARY_DIR}/simutrans/simutrans.pdb\')")
endif ()
else ()
install(CODE "execute_process(COMMAND sh ../get_lang_files.sh WORKING_DIRECTORY \${CMAKE_BINARY_DIR})")
endif ()
# pak installer
if (NOT WIN32)
install(FILES get_pak.sh DESTINATION "${CMAKE_BINARY_DIR}/simutrans/"
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
else ()
# NSIS missing
install(CODE "execute_process(COMMAND NSIS WORKING_DIRECTORY \${CMAKE_SOURCE_DIR}/nsis)")
endif ()
# install pak if needed
if (SIMUTRANS_INSTALL_PAK64)
if (MSVC)
install(CODE
"if(NOT EXISTS ${simutrans_BINARY_DIR}/simutrans/pak)
execute_process(COMMAND powershell -Command \"Remove-Item \'${simutrans_BINARY_DIR}/simutrans/pak\' -Recurse\" WORKING_DIRECTORY ${simutrans_BINARY_DIR})
file(STRINGS ${CMAKE_SOURCE_DIR}/paksetinfo.h URLpak64 REGEX \"/pak64/\")
string( REGEX REPLACE \"^.[\\t ]*\\\"\" \"\" URLpak64 \${URLpak64})
string( REGEX REPLACE \"\\\", .*\$\" \"\" URLpak64 \${URLpak64})
message(\"install pak to \" ${simutrans_BINARY_DIR})
execute_process(COMMAND powershell -ExecutionPolicy Bypass -File ${CMAKE_SOURCE_DIR}/get_pak.ps1 \${URLpak64} WORKING_DIRECTORY ${simutrans_BINARY_DIR}/simutrans)
endif ()
")
else ()
# install pak64 with the bundle
install(CODE
"file(STRINGS ${CMAKE_SOURCE_DIR}/paksetinfo.h URLpak64 REGEX \"/pak64/\")
string( REGEX REPLACE \"^.[\\t ]*\\\"\" \"\" URLpak64 \${URLpak64})
string( REGEX REPLACE \"\\\", .*\$\" \"\" URLpak64 \${URLpak64})
execute_process(COMMAND sh ../../get_pak.sh \${URLpak64} WORKING_DIRECTORY \${CMAKE_BINARY_DIR}/simutrans)
")
endif ()
endif()
#
# Nettool/Makeobj
#
add_subdirectory(makeobj EXCLUDE_FROM_ALL)
add_subdirectory(nettools EXCLUDE_FROM_ALL)