-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
CMakeLists.txt
401 lines (320 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
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
390
391
392
393
394
395
396
397
398
399
400
401
set(CXX_FLAGS_PROJECT "${CXX_FLAGS_PROJECT} -include boost-patched/bind/arg.hpp")
# store the specified sources list in the specified variable
function(GetSources source_list store_in_var)
file(STRINGS "../source_lists/${source_list}" sources)
set(${store_in_var} ${sources} PARENT_SCOPE)
endfunction()
if(ENABLE_MYSQL)
execute_process(COMMAND mysql_config --cflags OUTPUT_VARIABLE MYSQL_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX REPLACE "-I" "" MYSQL_CFLAGS "${MYSQL_CFLAGS}")
string(REGEX REPLACE "-DNDEBUG" "" MYSQL_CFLAGS "${MYSQL_CFLAGS}")
execute_process(COMMAND mysql_config --libs OUTPUT_VARIABLE MYSQL_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
endif(ENABLE_MYSQL)
## some includes ##
include_directories(SYSTEM ${FONTCONFIG_INCLUDE_DIRS} )
include_directories(SYSTEM ${PANGOCAIRO_INCLUDE_DIRS} )
include_directories(SYSTEM ${GETTEXT_INCLUDE_DIR} )
include_directories(SYSTEM ${LIBDBUS_INCLUDE_DIRS} )
include_directories(SYSTEM ${VORBISFILE_INCLUDE_DIR} )
include_directories(SYSTEM ${SDL2_INCLUDE_DIR} )
set(sdl-lib ${SDL2_LIBRARY})
#optional dependencies
if(SDL2IMAGE_INCLUDE_DIR)
include_directories(SYSTEM ${SDL2IMAGE_INCLUDE_DIR} )
set(sdl_image-lib ${SDL2_IMAGE_LIBRARY})
endif()
if(SDL2MIXER_INCLUDE_DIR)
include_directories(SYSTEM ${SDL2MIXER_INCLUDE_DIR} )
set(sdl_mixer-lib ${SDL2_MIXER_LIBRARY})
endif()
if(SDL2TTF_INCLUDE_DIR)
include_directories(SYSTEM ${SDL2TTF_INCLUDE_DIR} )
set(sdl_ttf-lib ${SDL2_TTF_LIBRARY})
endif()
if(ZLIB_INCLUDE_DIR)
include_directories(SYSTEM ${ZLIB_INCLUDE_DIR} )
endif()
# needed to get include paths in the subfolders correct
include_directories( ${CMAKE_SOURCE_DIR}/src/ )
# needed to have the generated config.h used, too
include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
link_directories(
${Boost_LIBRARY_DIRS}
${PANGOCAIRO_LIBRARY_DIRS}
${FONTCONFIG_LIBRARY_DIRS}
${LIBDBUS_LIBRARY_DIRS}
)
set(common-external-libs
${sdl-lib}
${Boost_IOSTREAMS_LIBRARY}
${Boost_REGEX_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
${Boost_LOCALE_LIBRARY}
)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(common-external-libs
${common-external-libs}
"-licudata -licui18n -licuuc"
)
endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(game-external-libs
${common-external-libs}
${CRYPTO_LIBRARY}
${Boost_SYSTEM_LIBRARIES}
${Boost_RANDOM_LIBRARY}
${Boost_THREAD_LIBRARY}
${sdl_image-lib}
${sdl_mixer-lib}
${sdl_ttf-lib}
${PANGOCAIRO_LIBRARIES}
${FONTCONFIG_LIBRARIES}
${LIBDBUS_LIBRARIES}
${VORBISFILE_LIBRARIES}
)
if(ENABLE_HISTORY AND HISTORY_FOUND)
set(game-external-libs
${game-external-libs}
${HISTORY_LIBRARY}
)
endif(ENABLE_HISTORY AND HISTORY_FOUND)
set(server-external-libs
${common-external-libs}
${Boost_SYSTEM_LIBRARIES}
-lpthread
)
set(tools-external-libs
${common-external-libs}
${sdl_image-lib}
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARIES}
${Boost_RANDOM_LIBRARY}
)
if(ENABLE_FRIBIDI AND FRIBIDI_FOUND)
set(game-external-libs ${game-external-libs} ${FRIBIDI_LIBRARIES})
include_directories(SYSTEM ${FRIBIDI_INCLUDE_DIRS} )
endif(ENABLE_FRIBIDI AND FRIBIDI_FOUND)
if(X11_FOUND)
include_directories(SYSTEM ${X11_INCLUDE_DIR} )
set(game-external-libs ${game-external-libs} ${X11_LIBRARIES})
endif(X11_FOUND)
if(APPLE)
set(game-external-libs ${game-external-libs} "-framework IOKit")
endif(APPLE)
########### Set Library mode ###############
if(ENABLE_SHARED_LIBRARIES)
set(LIBRARY_TYPE SHARED)
else(ENABLE_SHARED_LIBRARIES)
set(LIBRARY_TYPE STATIC)
endif(ENABLE_SHARED_LIBRARIES)
########### libwesnoth-core ###############
GetSources("libwesnoth_core" libwesnoth-core_STAT_SRC)
if(WIN32)
set(libwesnoth-core_STAT_SRC
${libwesnoth-core_STAT_SRC}
log_windows.cpp
)
endif()
# a 'lib' is automatically set in front when creating the library (as in the filename)
# internal reference is the name given here
add_library(wesnoth-core ${LIBRARY_TYPE} EXCLUDE_FROM_ALL ${libwesnoth-core_STAT_SRC})
target_link_libraries(wesnoth-core ${Boost_FILESYSTEM_LIBRARY})
# Depending on the flag create a real file or an empty dummy.
#
# Since the code is executed every build run of Wesnoth we need to make sure
# that no modifications don't turn into a rebuild. Therefore a the dummy is
# created and the second target only copies the file if modified.
if(ENABLE_DISPLAY_REVISION)
add_custom_target(wesnoth-revision_dummy
COMMAND
${CMAKE_SOURCE_DIR}/utils/autorevision.sh
-t h
> ${CMAKE_CURRENT_BINARY_DIR}/revision.dummy
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
)
add_custom_target(wesnoth-revision
COMMAND
${CMAKE_COMMAND} -E
copy_if_different
${CMAKE_CURRENT_BINARY_DIR}/revision.dummy
${CMAKE_CURRENT_BINARY_DIR}/revision.h
)
add_dependencies(wesnoth-revision wesnoth-revision_dummy)
add_dependencies(wesnoth-core wesnoth-revision)
set_source_files_properties(
game_config.cpp
PROPERTIES
COMPILE_DEFINITIONS "LOAD_REVISION"
)
endif()
########### lua ###############
GetSources("lua" lua_STAT_SRC)
# We explicitly want lua compiled as C++ version, so this line is required:
set_source_files_properties(${lua_STAT_SRC} PROPERTIES LANGUAGE CXX)
# Inject a header into the Lua sources for Wesnoth-specific changes
# makedepend won't see it so we have to specifically add it as a dependency.
file(GLOB wesnoth_lua_config wesnoth_lua_config.h)
set_source_files_properties(${lua_STAT_SRC} PROPERTIES COMPILE_FLAGS "-include \"${wesnoth_lua_config}\"")
set_source_files_properties(${lua_STAT_SRC} PROPERTIES OBJECT_DEPENDS ${wesnoth_lua_config})
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# silence a Clang specific warning due to extra parenthesis in if statements when comparing instead
set_property(SOURCE
SOURCE ${lua_STAT_SRC}
APPEND_STRING PROPERTY COMPILE_FLAGS
" -Wno-parentheses-equality"
)
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# a 'lib' is automatically set in front when creating the library (as in the filename)
# internal reference is the name given here
add_library(lua ${LIBRARY_TYPE} EXCLUDE_FROM_ALL ${lua_STAT_SRC})
########### Old style cast flags ###############
# Disable the setting of -Wold-style-cast and Wuseless-cast on some targets.
# old style casts are not wanted by our coding style but some C based code
# uses it. Force the flag off for these files.
set_target_properties(lua
PROPERTIES
COMPILE_FLAGS
"-Wno-old-style-cast -Wno-useless-cast -Wno-stringop-overflow"
)
########### Helper libraries ###############
GetSources("libwesnoth_sdl" wesnoth-sdl_SRC)
add_library(wesnoth-sdl
${LIBRARY_TYPE}
EXCLUDE_FROM_ALL
${wesnoth-sdl_SRC}
)
target_link_libraries(wesnoth-sdl
${sdl-lib}
${sdl_image-lib}
)
GetSources("libwesnoth_widgets" wesnoth-widgets_SRC)
add_library(wesnoth-widgets
${LIBRARY_TYPE}
EXCLUDE_FROM_ALL
${wesnoth-widgets_SRC}
)
if (APPLE)
set(WIDGETS_LIB -Wl,-force_load wesnoth-widgets)
else()
set(WIDGETS_LIB -Wl,--whole-archive wesnoth-widgets -Wl,--no-whole-archive)
endif()
########### Wesnoth main source files ###############
# create libwesnoth-client.a if building the client or the boost unit tests
if(ENABLE_GAME OR ENABLE_TESTS)
GetSources("wesnoth" wesnoth-main_SRC)
add_library(wesnoth-client ${LIBRARY_TYPE} EXCLUDE_FROM_ALL ${wesnoth-main_SRC})
endif(ENABLE_GAME OR ENABLE_TESTS)
########### libwesnoth-game ###############
GetSources("libwesnoth" libwesnoth-game_STAT_SRC)
# On windows only, these files need to be linked, as their headers are included #ifdef win32.
if(WIN32)
set(libwesnoth-game_STAT_SRC
${libwesnoth-game_STAT_SRC}
desktop/windows_tray_notification.cpp
desktop/windows_battery_info.cpp
)
endif(WIN32)
# On apple only
if(APPLE)
set(libwesnoth-game_STAT_SRC
${libwesnoth-game_STAT_SRC}
desktop/apple_battery_info.mm
desktop/apple_notification.mm
desktop/apple_version.mm
)
endif(APPLE)
# For libdbus (essentially just for linux), this file needs to be linked, as its header is included #ifdef HAVE_LIBDBUS
if(LIBDBUS_FOUND)
set(libwesnoth-game_STAT_SRC
${libwesnoth-game_STAT_SRC}
desktop/dbus_features.cpp
)
endif(LIBDBUS_FOUND)
# a 'lib' is automatically set in front when creating the library (as in the filename)
# internal reference is the name given here
add_library(wesnoth-game ${LIBRARY_TYPE} EXCLUDE_FROM_ALL ${libwesnoth-game_STAT_SRC})
########### Wesnoth ###############
if(ENABLE_GAME)
if(NOT APPLE)
add_executable(wesnoth WIN32 wesnoth.cpp)
else()
add_executable(wesnoth WIN32 wesnoth.cpp macosx/SDLMain.mm)
endif(NOT APPLE)
target_link_libraries(wesnoth
wesnoth-client
lua
wesnoth-core
wesnoth-game
wesnoth-sdl
${WIDGETS_LIB}
wesnoth-client
${game-external-libs}
)
set_target_properties(wesnoth
PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}wesnoth${BINARY_SUFFIX}
)
install(TARGETS wesnoth DESTINATION ${CMAKE_INSTALL_BINDIR})
endif(ENABLE_GAME)
########### Wesnothd Server ###############
if(ENABLE_SERVER)
GetSources("wesnothd" wesnothd_SRC)
add_executable(wesnothd WIN32 ${wesnothd_SRC})
if(ENABLE_MYSQL)
target_include_directories(wesnothd SYSTEM PRIVATE ${MYSQL_CFLAGS})
target_compile_definitions(wesnothd PRIVATE HAVE_MYSQLPP)
endif(ENABLE_MYSQL)
target_link_libraries(wesnothd
wesnoth-core
${server-external-libs}
${Boost_RANDOM_LIBRARY}
${CRYPTO_LIBRARY}
${MYSQL_LIBS}
)
set_target_properties(wesnothd PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}wesnothd${BINARY_SUFFIX})
install(TARGETS wesnothd DESTINATION ${CMAKE_INSTALL_BINDIR})
endif(ENABLE_SERVER)
########### Campaign Server ###############
if(ENABLE_CAMPAIGN_SERVER)
GetSources("campaignd" campaignd_SRC)
add_executable(campaignd ${campaignd_SRC})
if(ENABLE_MYSQL)
target_include_directories(campaignd SYSTEM PRIVATE ${MYSQL_CFLAGS})
target_compile_definitions(campaignd PRIVATE HAVE_MYSQLPP)
endif(ENABLE_MYSQL)
target_link_libraries(campaignd
wesnoth-core
${server-external-libs}
${CRYPTO_LIBRARY}
${Boost_RANDOM_LIBRARY}
${MYSQL_LIBS}
)
set_target_properties(campaignd PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}campaignd${BINARY_SUFFIX})
install(TARGETS campaignd DESTINATION ${CMAKE_INSTALL_BINDIR})
endif(ENABLE_CAMPAIGN_SERVER)
########### Unit tests ###############
if(ENABLE_TESTS)
add_definitions(-DBOOST_TEST_DYN_LINK)
GetSources("boost_unit_tests" test_SRC)
set_source_files_properties(
tests/test_util.cpp
PROPERTIES
COMPILE_FLAGS
"${CXX_FLAG_NO_USELESS_CAST}"
)
add_executable(boost_unit_tests ${test_SRC})
target_link_libraries(boost_unit_tests
wesnoth-client
lua
wesnoth-core
wesnoth-game
wesnoth-sdl
${WIDGETS_LIB}
wesnoth-client
${game-external-libs}
boost_unit_test_framework
)
set_target_properties(boost_unit_tests
PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}boost_unit_tests${BINARY_SUFFIX}
)
endif(ENABLE_TESTS)