forked from jamespetts/simutrans-extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
333 lines (270 loc) · 10.2 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
#
# This file is part of the Simutrans-Extended project under the Artistic License.
# (see LICENSE.txt)
#
cmake_minimum_required(VERSION 3.8)
# 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-extended LANGUAGES C CXX)
include(SimutransCommitInfo)
# 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)
set(CMAKE_PREFIX_PATH "/usr/local/opt/readline")
link_directories(/usr/local/lib)
set(CMAKE_EXE_LINKER_FLAGS "-framework Cocoa")
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)
#
# sources
#
add_executable(simutrans-extended)
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set_target_properties(simutrans-extended PROPERTIES WIN32_EXECUTABLE 1)
endif ()
include(SimutransSourceList)
#
# output directory
#
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/simutrans)
set_target_properties( simutrans-extended PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/simutrans/$<0:> )
#
# Libraries
#
target_link_libraries(simutrans-extended PRIVATE PNG::PNG)
if (WIN32)
target_sources(simutrans-extended PRIVATE simres.rc)
target_sources(simutrans-extended PRIVATE sys/clipboard_w32.cc)
target_link_libraries(simutrans-extended PRIVATE ws2_32 winmm)
# Backup sound and music routines if the selected backend does not provide any routines
if (MINGW)
set(BACKUP_SOUND sound/win32_sound.cc)
else ()
set(BACKUP_SOUND sound/win32_sound_xa.cc)
endif ()
set(BACKUP_MUSIC music/w32_midi.cc)
else ()
if (SIMUTRANS_BACKEND STREQUAL "sdl2")
target_sources(simutrans-extended PRIVATE sys/clipboard_s2.cc)
else ()
target_sources(simutrans-extended PRIVATE sys/clipboard_internal.cc)
endif ()
if (APPLE)
#Darwin kernel version is used to identify macOS version (16->10.12/Sierra)
if (CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER_EQUAL 16) #AVF
set(BACKUP_SOUND sound/AVF_core-audio_sound.mm)
#AVF MIDI currently crash Simutrans
#set(BACKUP_MUSIC music/AVF_core-audio_midi.mm)
set(BACKUP_MUSIC music/no_midi.cc)
else () #QTKit
set(BACKUP_SOUND sound/core-audio_sound.mm)
set(BACKUP_MUSIC music/core-audio_midi.mm)
endif ()
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-extended PRIVATE MULTI_THREAD=1)
target_link_libraries(simutrans-extended PRIVATE Threads::Threads)
endif (SIMUTRANS_MULTI_THREAD)
if (SIMUTRANS_BACKEND STREQUAL "sdl2")
target_sources(simutrans-extended PRIVATE display/simgraph16.cc sys/simsys_s2.cc sound/sdl2_sound.cc)
target_include_directories(simutrans-extended PRIVATE ${SDL2_INCLUDE_DIRS})
if (MINGW)
target_link_libraries(simutrans-extended PRIVATE ${SDL2_STATIC_LIBRARIES})
elseif (APPLE)
target_link_libraries(simutrans-extended PRIVATE ${SDL2_LIBRARIES})
elseif (MSVC)
target_link_libraries(simutrans-extended PRIVATE SDL2::SDL2)
else ()
target_link_libraries(simutrans-extended PRIVATE PkgConfig::SDL2)
endif ()
target_compile_definitions(simutrans-extended PRIVATE COLOUR_DEPTH=16)
elseif (SIMUTRANS_BACKEND STREQUAL "gdi")
target_sources(simutrans-extended PRIVATE display/simgraph16.cc sys/simsys_w.cc ${BACKUP_SOUND} )
target_link_libraries(simutrans-extended PRIVATE imm32 xaudio2_8)
target_compile_definitions(simutrans-extended 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-extended PRIVATE display/simgraph0.cc sys/simsys_posix.cc sound/no_sound.cc music/no_midi.cc)
target_compile_definitions(simutrans-extended PRIVATE COLOUR_DEPTH=0)
endif ()
#
# Link dependencies
#
target_link_libraries(simutrans-extended PRIVATE ZLIB::ZLIB)
target_link_libraries(simutrans-extended PRIVATE BZip2::BZip2)
if (SIMUTRANS_USE_FREETYPE)
target_include_directories(simutrans-extended PRIVATE ${Freetype_INCLUDE_DIRS})
if (MINGW)
target_link_libraries(simutrans-extended PRIVATE ${Freetype_STATIC_LIBRARIES})
elseif (APPLE)
target_link_libraries(simutrans-extended PRIVATE ${Freetype_LIBRARIES})
elseif (MSVC)
target_link_libraries(simutrans-extended PRIVATE Freetype::Freetype)
else ()
target_link_libraries(simutrans-extended PRIVATE PkgConfig::Freetype)
endif ()
target_compile_definitions(simutrans-extended PRIVATE USE_FREETYPE=1)
endif (SIMUTRANS_USE_FREETYPE)
if (SIMUTRANS_USE_UPNP)
target_compile_definitions(simutrans-extended PRIVATE USE_UPNP=1)
target_link_libraries(simutrans-extended PRIVATE MiniUPNP::MiniUPNP)
endif (SIMUTRANS_USE_UPNP)
if (SIMUTRANS_USE_ZSTD)
target_sources(simutrans-extended PRIVATE io/rdwr/zstd_file_rdwr_stream.cc)
target_include_directories(simutrans-extended PRIVATE ${ZSTD_INCLUDE_DIRS})
target_compile_definitions(simutrans-extended PRIVATE USE_ZSTD=1)
if (MSVC)
target_link_libraries(simutrans-extended PRIVATE zstd::libzstd_static)
elseif (MINGW)
# only 64 bit cmake, 32 bit is broken
target_link_libraries(simutrans-extended PRIVATE -lzstd)
else()
target_link_libraries(simutrans-extended 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-extended PRIVATE music/fluidsynth.cc gui/loadsoundfont_frame.cc)
target_compile_definitions(simutrans-extended PRIVATE USE_FLUIDSYNTH_MIDI=1)
if (MINGW)
# not working because fluidsynth doesn't set static libraries for pkgconf
#target_link_libraries(simutrans-extended PRIVATE ${FluidSynth_STATIC_LIBRARIES})
# manually linking them instead, until it is fixed
target_link_libraries(simutrans-extended PRIVATE -lfluidsynth -lharfbuzz -lgraphite2 -lglib-2.0 -lintl -liconv -ldsound -lole32 -lws2_32 -lgomp -lksuser)
elseif (MSVC)
target_link_libraries(simutrans-extended PRIVATE ${FluidSynth_LIBRARIES})
else ()
target_link_libraries(simutrans-extended PRIVATE PkgConfig::FluidSynth)
endif (MINGW)
else ()
target_sources( simutrans-extended 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-extended PRIVATE /INCREMENTAL:NO /NODEFAULTLIB:LIBCMTD /MANIFEST:NO /LARGEADDRESSAWARE)
endif ()
if (SIMUTRANS_BIG_ENDIAN)
target_compile_definitions(simutrans-extended 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-extended PRIVATE ${SIMUTRANS_COMMON_COMPILE_OPTIONS})
target_compile_definitions(simutrans-extended PRIVATE $<IF:$<CONFIG:Debug>,DEBUG=1,>)
target_compile_definitions(simutrans-extended PRIVATE $<IF:$<CONFIG:Release>,NDEBUG=1,>)
target_compile_definitions(simutrans-extended PRIVATE MSG_LEVEL=${SIMUTRANS_MSG_LEVEL})
if (SIMUTRANS_WITH_REVISION)
target_compile_definitions(simutrans-extended PRIVATE REVISION=${SIMUTRANS_SHA_SHORT})
endif ()
if (SIMUTRANS_AUTOJOIN_PUBLIC)
target_compile_definitions(simutrans-extended PRIVATE AUTOJOIN_PUBLIC=1)
endif ()
if (SIMUTRANS_ENABLE_WATERWAY_SIGNS)
target_compile_definitions(simutrans-extended PRIVATE ENABLE_WATERWAY_SIGNS=1)
endif ()
if (SIMUTRANS_USE_SYSLOG)
target_compile_definitions(simutrans-extended PRIVATE SYSLOG=1)
endif ()
if (SIMUTRANS_DEBUG_FLUSH_BUFFER)
target_compile_definitions(simutrans-extended PRIVATE DEBUG_FLUSH_BUFFER=1)
endif ()
if (SIMUTRANS_USE_IP4_ONLY)
target_compile_definitions(simutrans-extended PRIVATE USE_IP4_ONLY=1)
endif ()
if (SIMUTRANS_STEAM_BUILT)
target_compile_definitions(simutrans-extended PRIVATE STEAM_BUILT=1)
endif ()
if (SIMUTRANS_DISABLE_RANDOMNESS)
target_compile_definitions(simutrans-extended PRIVATE DISABLE_RANDOMNESS=1)
endif ()
if (SIMUTRANS_DEBUG_SIMRAND)
target_compile_definitions(simutrans-extended PRIVATE DEBUG_SIMRAND_CALLS=1)
endif ()
if (SIMUTRANS_HEAVY_MODE)
target_compile_definitions(simutrans PRIVATE HEAVY_MODE=${SIMUTRANS_HEAVY_MODE})
target_sources(simutrans PRIVATE io/rdwr/adler32_stream.cc)
endif ()
if (APPLE)
target_compile_definitions(simutrans-extended PRIVATE ALT_SDL_DIR=1)
endif (APPLE)
#
# Installation
#
install(TARGETS simutrans-extended RUNTIME DESTINATION simutrans)
install(DIRECTORY "${CMAKE_SOURCE_DIR}/simutrans/" DESTINATION "simutrans")
install(FILES get_pak.sh DESTINATION "simutrans"
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
#
# Nettool/Makeobj
#
add_subdirectory(makeobj)
add_subdirectory(nettools)
#
# Packaging
#
include(SimutransPack)