forked from mangosR2/mangos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
489 lines (427 loc) · 15.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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
#
# Copyright (C) 2005-2012 MaNGOS project <http://getmangos.com/>
#
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
project(MaNGOS)
# CMake policies
cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${CMAKE_SOURCE_DIR}/cmake
)
# define all options here
option(DEBUG "Debug mode" OFF)
option(TBB_USE_EXTERNAL "Use external TBB" OFF)
#option(USE_STD_MALLOC "Use standard malloc instead of TBB" OFF)
#option(USE_TBB_MALLOC "Use included TBB malloc" OFF)
option(ACE_USE_EXTERNAL "Use external ACE" ON)
if(WIN32)
if(PLATFORM MATCHES X86) # 32-bit
option(USE_FASTMM_MALLOC "Use included FastMM malloc (default for win*)" 1)
option(USE_STD_MALLOC "Use standard malloc instead of TBB" 0)
else() # 64-bit
option(USE_STD_MALLOC "Use standard malloc instead of TBB" 0)
option(USE_FASTMM_MALLOC "Use included FastMM malloc (default for win*)" 1)
endif()
else()
#Unix and other platforms
option(USE_STD_MALLOC "Use standard malloc instead of TBB" 1)
endif()
option(POSTGRESQL "Use PostgreSQL" OFF)
if(PCHSupport_FOUND AND WIN32) # TODO: why only enable it on windows by default?
option(PCH "Use precompiled headers" ON)
else()
option(PCH "Use precompiled headers" OFF)
endif()
# TODO: options that should be checked/created:
#option(CLI "With CLI" ON)
#option(RA "With Remote Access" OFF)
#option(SQL "Copy SQL files" OFF)
#option(TOOLS "Build tools" OFF)
find_package(PCHSupport)
# Add options for compile of mangos
if(PCHSupport_FOUND)
if(WIN32)
option(PCH "Use precompiled headers" 1)
else()
option(PCH "Use precompiled headers" 0)
endif()
endif()
# FIXME: options that should be checked
# option(SQL "Copy SQL files" 0)
# option(TOOLS "Build tools" 0)
# Output description of this script
message("")
message(
"This script builds the MangosR2 server.
Options that can be used in order to configure the process:
CMAKE_INSTALL_PREFIX Path where the server should be installed to
PCH Use precompiled headers
DEBUG Debug mode
INCLUDE_BINDINGS_DIR Include a script library in src/bindings/ with the
defined name. the name must corespond to the name of
the folder and the folder must contain a valid
CMakeLists.txt
TBB_USE_EXTERNAL Use external TBB
USE_STD_MALLOC Use standard malloc (default for *NIX)
USE_TBB_MALLOC Use TBB malloc (not recommended)
USE_FASTMM_MALLOC Use included FastMM malloc (default for win*)
ACE_USE_EXTERNAL Use external ACE (default. usage included ACE not recommended, possible only for win*)
To set an option simply type -D<OPTION>=<VALUE> after 'cmake <srcs>'.
Also, you can specify the generator with -G. see 'cmake --help' for more details
For example: cmake .. -DDEBUG=1 -DCMAKE_INSTALL_PREFIX=/opt/mangos"
)
message("")
# Force out-of-source build
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" BUILDING_IN_SOURCE)
if(BUILDING_IN_SOURCE)
message(FATAL_ERROR
"This project requires an out of source build. Remove the file 'CMakeCache.txt' found in this directory before continuing, create a separate build directory and run 'cmake <srcs> [options]' from there."
)
endif()
if(WIN32 AND NOT MSVC)
message(FATAL_ERROR
"Under Windows other compiler than Microsoft Visual Studio are not supported."
)
endif()
find_package(Platform REQUIRED)
find_package(Git)
# VS100 uses MSBuild.exe instead of devenv.com, so force it to use devenv.com
if(WIN32 AND MSVC_VERSION MATCHES 1600)
find_package(VisualStudio2010)
endif()
# if(NOT PLATFORM MATCHES X86 AND NOT PLATFORM MATCHES X64)
# message(FATAL_ERROR
# "An unknown Architecture was selected. Only the values X86 and X64 for PLATFORM are supported."
# )
# endif()
# Output description of this script
message(
"\nThis script builds the MaNGOS server.
Options that can be used in order to configure the process:
CMAKE_INSTALL_PREFIX: Path where the server should be installed to
PCH: Use precompiled headers
DEBUG: Debug mode
To set an option simply type -D<OPTION>=<VALUE> after 'cmake <srcs>'.
For example: cmake .. -DDEBUG=1 -DCMAKE_INSTALL_PREFIX=/opt/mangos\n"
) # TODO: PLATFORM: Sets the architecture for compile (X86,X64)
# Override configuration-types - we don't use anything else than debug and release
if(CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES Release Debug)
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
"Reset the configurations to what we need"
FORCE)
endif()
# Find out what system we use to include the needed libs
if(WIN32)
if(PLATFORM MATCHES X86) # 32-bit
set(DEP_ARCH win32)
else() # 64-bit
set(DEP_ARCH x64)
endif()
endif()
# if(WIN32)
# if(PLATFORM MATCHES X86)
# set(ARCH_FLAGS "/MACHINE:X86")
# else()
# set(ARCH_FLAGS "/MACHINE:X64")
# endif()
# elseif(UNIX)
# if(PLATFORM MATCHES X86)
# set(ARCH_FLAGS "-m32")
# else()
# set(ARCH_FLAGS "-m64")
# endif()
# endif()
# TODO: remove this in the future! it has only been added to make the switch easier for end users
if(PREFIX)
message(FATAL_ERROR "The parameter PREFIX has been removed. Please re-run CMake and use CMAKE_INSTALL_PREFIX instead to define your installation location!")
endif()
set(BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin)
set(CONF_DIR ${CMAKE_INSTALL_PREFIX}/etc)
# If win32 put it in the bin dir not lib
if(WIN32)
set(LIBS_DIR ${CMAKE_INSTALL_PREFIX}/bin)
else()
set(LIBS_DIR ${CMAKE_INSTALL_PREFIX}/lib)
endif()
# For Unix systems set the rpath so that libraries are found
set(CMAKE_INSTALL_RPATH ${LIBS_DIR})
set(CMAKE_INSTALL_NAME_DIR ${LIBS_DIR})
# Run out of build tree
set(CMAKE_BUILD_WITH_INSTALL_RPATH OFF)
# Find needed packages and if necessery abort if something important is missing
unset(ACE_INCLUDE_DIR CACHE)
unset(ACE_LIBRARIES CACHE)
unset(ACE_LIBRARIES_DIR CACHE)
unset(ACE_INCLUDE_DIR)
unset(ACE_LIBRARIES)
unset(ACE_LIBRARIES_DIR)
if(ACE_USE_EXTERNAL)
find_package(ACE)
if(NOT ACE_FOUND)
message(FATAL_ERROR
"This project requires ACE installed when ACE_USE_EXTERNAL is set. Please download the ACE Micro Release Kit from http://download.dre.vanderbilt.edu/ and install it. If this script didn't find ACE and it was correctly installed please set ACE_ROOT to the correct path."
)
endif()
if(EXISTS ${ACE_INCLUDE_DIR}/ace/Stack_Trace.h)
set(HAVE_ACE_STACK_TRACE_H ON) # config.h.cmake
endif()
else()
include(cmake/ImportACE.cmake)
endif()
if(USE_TBB_MALLOC)
unset(TBB_INCLUDE_DIR CACHE)
unset(TBB_LIBRARIES CACHE)
unset(TBB_LIBRARIES_DIR CACHE)
unset(TBB_INCLUDE_DIR)
unset(TBB_LIBRARIES)
unset(TBB_LIBRARIES_DIR)
if(TBB_USE_EXTERNAL)
find_package(TBB)
if(NOT TBB_FOUND)
message(FATAL_ERROR
"This project requires TBB installed when TBB_USE_EXTERNAL is set. Please download the TBB Stable Release from http://www.threadingbuildingblocks.org/ and install it. If this script didn't find TBB and it was correctly installed please set TBB_ROOT to the correct path."
)
endif()
else()
include(cmake/ImportTBB.cmake)
endif()
endif()
# Win32 delifered packages
if(WIN32)
set(MYSQL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/dep/include/mysql)
set(MYSQL_LIBRARY ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_release/libmySQL.lib)
set(MYSQL_DEBUG_LIBRARY ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_debug/libmySQL.lib)
set(OPENSSL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/dep/include/openssl)
set(OPENSSL_LIBRARIES ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_release/libeay32.lib)
set(OPENSSL_DEBUG_LIBRARIES ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_debug/libeay32.lib)
# zlib is build
endif()
# *nix-specific packages
if(UNIX)
if(POSTGRESQL)
find_package(PostgreSQL REQUIRED)
if(POSTGRESQL_FOUND)
include_directories(${POSTGRESQL_INCLUDE_DIRS})
endif(POSTGRESQL_FOUND)
else()
find_package(MySQL REQUIRED)
endif()
find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)
endif()
# Add uninstall script and target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY
)
add_custom_target(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
)
# Find core revision
if(GIT_EXECUTABLE)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_REVISION
RESULT_VARIABLE GIT_RESULT
ERROR_QUIET
)
if(GIT_RESULT)
set(GIT_REVISION "Git repository not found")
endif()
else()
set(GIT_REVISION "Git not found")
endif()
message("")
message("MaNGOS-Core revision : ${GIT_REVISION}")
message("Install server to : ${CMAKE_INSTALL_PREFIX}")
message("")
# if(CLI)
# message("Build with CLI : Yes (default)")
# add_definitions(-DENABLE_CLI)
# else()
# message("Build with CLI : No")
# endif()
# if(RA)
# message("* Build with RA : Yes")
# add_definitions(-DENABLE_RA)
# else(RA)
# message("* Build with RA : No (default)")
# endif(RA)
if(PCH AND NOT PCHSupport_FOUND)
set(PCH 0 CACHE BOOL
"Use precompiled headers"
FORCE)
message(
"No PCH for your system possible but PCH was set to 1. Resetting it."
)
endif()
if(PCH)
message("Use PCH : Yes")
else()
message("Use PCH : No")
endif()
if(DEBUG)
message("Build in debug-mode : Yes")
set(CMAKE_BUILD_TYPE Debug)
else()
set(CMAKE_BUILD_TYPE Release)
message("Build in debug-mode : No (default)")
endif()
# Handle debugmode compiles (this will require further work for proper WIN32-setups)
if(UNIX)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
endif()
# Set warning levels for different builds
if(UNIX)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} --no-warnings")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} --no-warnings")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wfatal-errors")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wfatal-errors")
elseif(WIN32)
# Disable warnings in Visual Studio 8 and above and add /MP
if(MSVC AND NOT CMAKE_GENERATOR MATCHES "Visual Studio 7")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /wd4996 /wd4355 /wd4244 /wd4985 /wd4267 /MP")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /wd4996 /wd4355 /wd4244 /wd4267 /MP")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /wd4996 /wd4355 /wd4244 /wd4985 /wd4267 /MP")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd4996 /wd4355 /wd4244 /wd4985 /wd4267 /MP")
endif()
endif()
# if(SQL)
# message("Install SQL-files : Yes")
# else()
# message("Install SQL-files : No (default)")
# endif()
# if(TOOLS)
# message("Build map/vmap tools : Yes")
# else()
# message("Build map/vmap tools : No (default)")
# endif()
message("")
# Some small tweaks for Visual Studio 7 and above.
if(MSVC)
# Mark 32 bit executables large address aware so they can use > 2GB address space
if(PLATFORM MATCHES X86)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
endif()
endif()
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH ${LIBS_DIR})
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# Generate revision-extractor
set(GENREV_SRC
src/tools/genrevision/genrevision.cpp
)
add_executable(genrev
${GENREV_SRC}
)
# if(WIN32)
# set_target_properties(genrev PROPERTIES
# COMPILE_FLAGS "/MACHINE:X86"
# )
# elseif(UNIX)
# set_target_properties(genrev PROPERTIES
# COMPILE_FLAGS "-m32"
# LINK_FLAGS "-m32"
# )
# endif()
# if(XCODE)
# set_target_properties(genrev PROPERTIES
# XCODE_ATTRIBUTE_ARCHS "i386"
# )
# endif()
get_target_property(GENERATE_EXE genrev LOCATION)
add_custom_target("revision.h" ALL
COMMAND ${GENERATE_EXE} ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
DEPENDS genrev
)
if(WIN32)
install(
FILES
${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_release/libeay32.dll
${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_release/libmySQL.dll
DESTINATION ${LIBS_DIR}
CONFIGURATIONS Release
)
install(
FILES
${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_debug/libeay32.dll
${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_debug/libmySQL.dll
DESTINATION ${LIBS_DIR}
CONFIGURATIONS Debug
)
if(PLATFORM MATCHES X86)
# Copy dll's Windows needs
install(
FILES
${CMAKE_SOURCE_DIR}/dep/lib/win32_release/dbghelp.dll
DESTINATION ${LIBS_DIR}
CONFIGURATIONS Release
)
install(
FILES
${CMAKE_SOURCE_DIR}/dep/lib/win32_debug/dbghelp.dll
DESTINATION ${LIBS_DIR}
CONFIGURATIONS Debug
)
endif()
endif()
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARCH_FLAGS}")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_FLAGS}")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ARCH_FLAGS}")
if(XCODE)
if(PLATFORM MATCHES X86)
set(CMAKE_OSX_ARCHITECTURES i386)
else()
set(CMAKE_OSX_ARCHITECTURES x86_64)
endif()
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config.h)
add_subdirectory(dep) # TODO: add vmap extractor build support
# Add definitions for all build types
# Don't place this above 'dep' subdirectory! Because of defines build will crash.
if (UNIX)
set(DEFINITIONS DO_MYSQL SYSCONFDIR="${CONF_DIR}/")
else()
set(DEFINITIONS DO_MYSQL SYSCONFDIR="../etc/")
endif()
if(POSTGRESQL)
set(DEFINITIONS ${DEFINITIONS} DO_POSTGRESQL)
else()
set(DEFINITIONS ${DEFINITIONS} DO_MYSQL)
endif()
set(DEFINITIONS_RELEASE NDEBUG)
set(DEFINITIONS_DEBUG _DEBUG MANGOS_DEBUG)
if(WIN32)
set(DEFINITIONS ${DEFINITIONS} WIN32 _WIN32)
set(DEFINITIONS_RELEASE ${DEFINITIONS_RELEASE} _CRT_SECURE_NO_WARNINGS)
endif()
if(USE_STD_MALLOC)
set(DEFINITIONS ${DEFINITIONS} USE_STANDARD_MALLOC)
endif()
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "${DEFINITIONS}")
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS_RELEASE "${DEFINITIONS_RELEASE}")
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS_DEBUG "${DEFINITIONS_DEBUG}")
add_subdirectory(src)
# if(SQL)
# add_subdirectory(sql)
# endif()