Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 433 lines (385 sloc) 13.152 kb
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
1 #
2 # Copyright (C) 2005-2011 MaNGOS project <http://getmangos.com/>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 #
18
19 project(MaNGOS)
20 set(MANGOS_VERSION 0.17.0)
21
22 # CMake policies
23 cmake_minimum_required(VERSION 2.8)
24
25 set(CMAKE_MODULE_PATH
26 ${CMAKE_MODULE_PATH}
27 ${CMAKE_SOURCE_DIR}/cmake
28 )
29
30 # Force out-of-source build
31 string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" BUILDING_IN_SOURCE)
32 if(BUILDING_IN_SOURCE)
33 message(FATAL_ERROR
34 "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."
35 )
36 endif()
37
38 if(WIN32 AND NOT MSVC)
39 message(FATAL_ERROR
40 "Under Windows other compiler than Microsoft Visual Studio are not supported."
41 )
42 endif()
43
44 find_package(Platform REQUIRED)
45 find_package(Git)
46
47 # VS100 uses MSBuild.exe instead of devenv.com, so force it to use devenv.com
48 if(WIN32 AND MSVC_VERSION MATCHES 1600)
49 find_package(VisualStudio2010)
50 endif()
51
52 # if(NOT PLATFORM MATCHES X86 AND NOT PLATFORM MATCHES X64)
53 # message(FATAL_ERROR
54 # "An unknown Architecture was selected. Only the values X86 and X64 for PLATFORM are supported."
55 # )
56 # endif()
57
58 # Output description of this script
59 message(
60 "\nThis script builds the MaNGOS server.
61 Options that can be used in order to configure the process:
62 PREFIX: Path where the server should be installed to
63 PCH: Use precompiled headers
64 DEBUG: Debug mode
65 To set an option simply type -D<OPTION>=<VALUE> after 'cmake <srcs>'.
66 For example: cmake .. -DDEBUG=1 -DPREFIX=/opt/mangos\n"
67 ) # TODO: PLATFORM: Sets the architecture for compile (X86,X64)
68
69 # Override configuration-types - we don't use anything else than debug and release
70 if(CMAKE_CONFIGURATION_TYPES)
71 set(CMAKE_CONFIGURATION_TYPES Release Debug)
72 set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
73 "Reset the configurations to what we need"
74 FORCE)
75 endif()
76
77 # Find out what system we use to include the needed libs
78 if(WIN32)
79 if(PLATFORM MATCHES X86) # 32-bit
80 set(DEP_ARCH win32)
81 else() # 64-bit
82 set(DEP_ARCH x64)
83 endif()
84 endif()
85
86 # if(WIN32)
87 # if(PLATFORM MATCHES X86)
88 # set(ARCH_FLAGS "/MACHINE:X86")
89 # else()
90 # set(ARCH_FLAGS "/MACHINE:X64")
91 # endif()
92 # elseif(UNIX)
93 # if(PLATFORM MATCHES X86)
94 # set(ARCH_FLAGS "-m32")
95 # else()
96 # set(ARCH_FLAGS "-m64")
97 # endif()
98 # endif()
99
100 option(DEBUG "Debug mode" 0)
101 # option(CLI "With CLI" 1) # Not used by MaNGOS so far
102 # option(RA "With Remote Access" 0) # TODO: support remote access
103 option(TBB_USE_EXTERNAL "Use external TBB" 0)
c37c8d2 @cipherCOM [11197] Allow of std malloc use instead of TBB
cipherCOM authored
104 option(USE_STD_MALLOC "Use standard malloc instead of TBB" 0)
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
105 option(ACE_USE_EXTERNAL "Use external ACE" 0)
106
107 find_package(PCHSupport)
108
109 # Add options for compile of mangos
110 if(PCHSupport_FOUND)
111 if(WIN32)
112 option(PCH "Use precompiled headers" 1)
113 else()
114 option(PCH "Use precompiled headers" 0)
115 endif()
116 endif()
117
118 # FIXME: options that should be checked
119 # option(SQL "Copy SQL files" 0)
120 # option(TOOLS "Build tools" 0)
121
122 # Set up the install-prefix
9af5be7 @cipherCOM [11196] Some cmake PREFIX related fixes:
cipherCOM authored
123 if(CMAKE_INSTALL_PREFIX STREQUAL "/usr/local")
124 get_filename_component(PREFIX_ABSOLUTE "../mangos-server" ABSOLUTE)
125 set(CMAKE_INSTALL_PREFIX ${PREFIX_ABSOLUTE} CACHE PATH "Install path prefix." FORCE)
126 endif()
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
127 if(PREFIX)
128 string(REGEX REPLACE "^~" "$ENV{HOME}" PREFIX ${PREFIX})
9af5be7 @cipherCOM [11196] Some cmake PREFIX related fixes:
cipherCOM authored
129 get_filename_component(PREFIX_ABSOLUTE ${PREFIX} ABSOLUTE)
130 set(CMAKE_INSTALL_PREFIX ${PREFIX} CACHE PATH "Install path prefix." FORCE)
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
131 else()
9af5be7 @cipherCOM [11196] Some cmake PREFIX related fixes:
cipherCOM authored
132 set(PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Install path prefix.")
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
133 endif()
134
135 set(BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin)
136 set(CONF_DIR ${CMAKE_INSTALL_PREFIX}/etc)
137 # If win32 put it in the bin dir not lib
138 if(WIN32)
139 set(LIBS_DIR ${CMAKE_INSTALL_PREFIX}/bin)
140 else()
141 set(LIBS_DIR ${CMAKE_INSTALL_PREFIX}/lib)
142 endif()
143
144 # For Unix systems set the rpath so that libraries are found
145 set(CMAKE_INSTALL_RPATH ${LIBS_DIR})
146 set(CMAKE_INSTALL_NAME_DIR ${LIBS_DIR})
147 # Run out of build tree
148 set(CMAKE_BUILD_WITH_INSTALL_RPATH OFF)
149
150 # Find needed packages and if necessery abort if something important is missing
151 unset(ACE_INCLUDE_DIR CACHE)
152 unset(ACE_LIBRARIES CACHE)
153 unset(ACE_LIBRARIES_DIR CACHE)
154 unset(ACE_INCLUDE_DIR)
155 unset(ACE_LIBRARIES)
156 unset(ACE_LIBRARIES_DIR)
157 if(ACE_USE_EXTERNAL)
158 find_package(ACE)
159 if(NOT ACE_FOUND)
160 message(FATAL_ERROR
161 "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."
162 )
163 endif()
164 if(EXISTS ${ACE_INCLUDE_DIR}/ace/Stack_Trace.h)
165 set(HAVE_ACE_STACK_TRACE_H ON) # config.h.cmake
166 endif()
167 else()
168 include(cmake/ImportACE.cmake)
169 endif()
170
c37c8d2 @cipherCOM [11197] Allow of std malloc use instead of TBB
cipherCOM authored
171 if(NOT USE_STD_MALLOC)
172 unset(TBB_INCLUDE_DIR CACHE)
173 unset(TBB_LIBRARIES CACHE)
174 unset(TBB_LIBRARIES_DIR CACHE)
175 unset(TBB_INCLUDE_DIR)
176 unset(TBB_LIBRARIES)
177 unset(TBB_LIBRARIES_DIR)
178 if(TBB_USE_EXTERNAL)
179 find_package(TBB)
180 if(NOT TBB_FOUND)
181 message(FATAL_ERROR
182 "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."
183 )
184 endif()
185 else()
186 include(cmake/ImportTBB.cmake)
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
187 endif()
188 endif()
189
190 # Win32 delifered packages
191 if(WIN32)
192 set(MYSQL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/dep/include/mysql)
193 set(MYSQL_LIBRARY ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_release/libmySQL.lib)
194 set(MYSQL_DEBUG_LIBRARY ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_debug/libmySQL.lib)
195 set(OPENSSL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/dep/include/openssl)
196 set(OPENSSL_LIBRARIES ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_release/libeay32.lib)
197 set(OPENSSL_DEBUG_LIBRARIES ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_debug/libeay32.lib)
198 # zlib is build
199 endif()
200
201 # *nix-specific packages
202 if(UNIX)
203 find_package(MySQL REQUIRED)
204 find_package(OpenSSL REQUIRED)
205 find_package(ZLIB REQUIRED)
206 endif()
207
208 # Add uninstall script and target
209 configure_file(
210 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
211 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
212 IMMEDIATE @ONLY
213 )
214
215 add_custom_target(uninstall
216 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
217 )
218
219 # Find core revision
220 if(GIT_EXECUTABLE)
221 execute_process(
e2ea5ac [11184] Allow build mangos without git repo
blueboy authored
222 COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
223 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
224 OUTPUT_VARIABLE GIT_REVISION
e2ea5ac [11184] Allow build mangos without git repo
blueboy authored
225 RESULT_VARIABLE GIT_RESULT
226 ERROR_QUIET
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
227 )
e2ea5ac [11184] Allow build mangos without git repo
blueboy authored
228 if(GIT_RESULT)
229 set(GIT_REVISION "Git repository not found")
230 endif()
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
231 else()
232 set(GIT_REVISION "Git not found")
233 endif()
234
235 message("")
236 message("MaNGOS-Core revision : ${GIT_REVISION}")
237 message("Install server to : ${CMAKE_INSTALL_PREFIX}")
238 message("")
239
240 # if(CLI)
241 # message("Build with CLI : Yes (default)")
242 # add_definitions(-DENABLE_CLI)
243 # else()
244 # message("Build with CLI : No")
245 # endif()
246
247 # if(RA)
248 # message("* Build with RA : Yes")
249 # add_definitions(-DENABLE_RA)
250 # else(RA)
251 # message("* Build with RA : No (default)")
252 # endif(RA)
253
254 if(PCH AND NOT PCHSupport_FOUND)
255 set(PCH 0 CACHE BOOL
256 "Use precompiled headers"
257 FORCE)
258 message(
259 "No PCH for your system possible but PCH was set to 1. Resetting it."
260 )
261 endif()
262 if(PCH)
263 message("Use PCH : Yes")
264 else()
265 message("Use PCH : No")
266 endif()
267
268 if(DEBUG)
269 message("Build in debug-mode : Yes")
270 set(CMAKE_BUILD_TYPE Debug)
271 else()
272 set(CMAKE_BUILD_TYPE Release)
273 message("Build in debug-mode : No (default)")
274 endif()
275 # Handle debugmode compiles (this will require further work for proper WIN32-setups)
276 if(UNIX)
277 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
278 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
279 endif()
280
281 # Set warning levels for different builds
282 if(UNIX)
283 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} --no-warnings")
284 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} --no-warnings")
285 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wfatal-errors -Wextra")
286 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wfatal-errors -Wextra")
287 elseif(WIN32)
288 # Disable warnings in Visual Studio 8 and above
289 if(MSVC AND NOT CMAKE_GENERATOR MATCHES "Visual Studio 7")
290 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /wd4996 /wd4355 /wd4244 /wd4985 /wd4267")
291 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /wd4996 /wd4355 /wd4244 /wd4267")
292 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /wd4996 /wd4355 /wd4244 /wd4985 /wd4267")
293 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd4996 /wd4355 /wd4244 /wd4985 /wd4267")
294 endif()
295 endif()
296
297 # if(SQL)
298 # message("Install SQL-files : Yes")
299 # else()
300 # message("Install SQL-files : No (default)")
301 # endif()
302
303 # if(TOOLS)
304 # message("Build map/vmap tools : Yes")
305 # else()
306 # message("Build map/vmap tools : No (default)")
307 # endif()
308
309 message("")
310
311 # Some small tweaks for Visual Studio 7 and above.
312 if(MSVC)
313 # Mark 32 bit executables large address aware so they can use > 2GB address space
314 if(PLATFORM MATCHES X86)
315 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
316 endif()
317 endif()
318
319 set(CMAKE_SKIP_BUILD_RPATH FALSE)
320 set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
321 set(CMAKE_INSTALL_RPATH ${LIBS_DIR})
322 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
323
324 # Generate revision-extractor
325 set(GENREV_SRC
326 src/tools/genrevision/genrevision.cpp
327 )
328
329 add_executable(genrev
330 ${GENREV_SRC}
331 )
332
333 # if(WIN32)
334 # set_target_properties(genrev PROPERTIES
335 # COMPILE_FLAGS "/MACHINE:X86"
336 # )
337 # elseif(UNIX)
338 # set_target_properties(genrev PROPERTIES
339 # COMPILE_FLAGS "-m32"
340 # LINK_FLAGS "-m32"
341 # )
342 # endif()
343 # if(XCODE)
344 # set_target_properties(genrev PROPERTIES
345 # XCODE_ATTRIBUTE_ARCHS "i386"
346 # )
347 # endif()
348
349 get_target_property(GENERATE_EXE genrev LOCATION)
350 add_custom_target("revision.h" ALL
351 COMMAND ${GENERATE_EXE} ${CMAKE_SOURCE_DIR}
352 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
353 DEPENDS genrev
354 )
355
356 if(WIN32)
357 install(
358 FILES
359 ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_release/libeay32.dll
360 ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_release/libmySQL.dll
361 DESTINATION ${LIBS_DIR}
362 CONFIGURATIONS Release
363 )
364 install(
365 FILES
366 ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_debug/libeay32.dll
367 ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_debug/libmySQL.dll
368 DESTINATION ${LIBS_DIR}
369 CONFIGURATIONS Debug
370 )
371 if(PLATFORM MATCHES X86)
372 # Special thing for debug and 32-bit
373 set(WIN_DEBUGLIBS
374 ${CMAKE_SOURCE_DIR}/dep/lib/win32_debug/vld.lib
375 )
376 # Copy dll's Windows needs
377 install(
378 FILES
379 ${CMAKE_SOURCE_DIR}/dep/lib/win32_release/dbghelp.dll
380 DESTINATION ${LIBS_DIR}
381 CONFIGURATIONS Release
382 )
383 install(
384 FILES
385 ${CMAKE_SOURCE_DIR}/dep/lib/win32_debug/vld.dll
386 ${CMAKE_SOURCE_DIR}/dep/lib/win32_debug/dbghelp.dll
387 DESTINATION ${LIBS_DIR}
388 CONFIGURATIONS Debug
389 )
390 endif()
391 endif()
392
393 # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARCH_FLAGS}")
394 # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_FLAGS}")
395 # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ARCH_FLAGS}")
396 if(XCODE)
397 if(PLATFORM MATCHES X86)
398 set(CMAKE_OSX_ARCHITECTURES i386)
399 else()
400 set(CMAKE_OSX_ARCHITECTURES x86_64)
401 endif()
402 endif()
403
404 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
405
406 add_subdirectory(dep) # TODO: add vmap extractor build support
407
408 # Add definitions for all build types
409 # Don't place this above 'dep' subdirectory! Because of defines build will crash.
410 set(DEFINITIONS
411 DO_MYSQL
412 HAVE_CONFIG_H
413 VERSION="${MANGOS_VERSION}"
414 SYSCONFDIR="${CONF_DIR}/"
415 )
416 set(DEFINITIONS_RELEASE NDEBUG)
417 set(DEFINITIONS_DEBUG _DEBUG MANGOS_DEBUG)
418 if(WIN32)
419 set(DEFINITIONS ${DEFINITIONS} WIN32 _WIN32)
420 set(DEFINITIONS_RELEASE ${DEFINITIONS_RELEASE} _CRT_SECURE_NO_WARNINGS)
421 endif()
c37c8d2 @cipherCOM [11197] Allow of std malloc use instead of TBB
cipherCOM authored
422 if(USE_STD_MALLOC)
423 set(DEFINITIONS ${DEFINITIONS} USE_STANDARD_MALLOC)
424 endif()
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
425
426 set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "${DEFINITIONS}")
427 set_directory_properties(PROPERTIES COMPILE_DEFINITIONS_RELEASE "${DEFINITIONS_RELEASE}")
428 set_directory_properties(PROPERTIES COMPILE_DEFINITIONS_DEBUG "${DEFINITIONS_DEBUG}")
429
430 add_subdirectory(src)
431 # if(SQL)
432 # add_subdirectory(sql)
433 # endif()
Something went wrong with that request. Please try again.