Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 430 lines (382 sloc) 13.026 kB
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
1 #
1e35033 @Schmoozerd [11875] Update Copyright notice to year 2012
Schmoozerd authored
2 # Copyright (C) 2005-2012 MaNGOS project <http://getmangos.com/>
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
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)
d4b156b @Neo2003 [11399] Make CMake a bit more usefull for Win/MSVC
Neo2003 authored
128 if(!WIN32)
129 string(REGEX REPLACE "^~" "$ENV{HOME}" PREFIX ${PREFIX})
130 endif()
9af5be7 @cipherCOM [11196] Some cmake PREFIX related fixes:
cipherCOM authored
131 get_filename_component(PREFIX_ABSOLUTE ${PREFIX} ABSOLUTE)
132 set(CMAKE_INSTALL_PREFIX ${PREFIX} CACHE PATH "Install path prefix." FORCE)
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
133 else()
9af5be7 @cipherCOM [11196] Some cmake PREFIX related fixes:
cipherCOM authored
134 set(PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Install path prefix.")
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
135 endif()
136
137 set(BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin)
138 set(CONF_DIR ${CMAKE_INSTALL_PREFIX}/etc)
139 # If win32 put it in the bin dir not lib
140 if(WIN32)
141 set(LIBS_DIR ${CMAKE_INSTALL_PREFIX}/bin)
142 else()
143 set(LIBS_DIR ${CMAKE_INSTALL_PREFIX}/lib)
144 endif()
145
146 # For Unix systems set the rpath so that libraries are found
147 set(CMAKE_INSTALL_RPATH ${LIBS_DIR})
148 set(CMAKE_INSTALL_NAME_DIR ${LIBS_DIR})
149 # Run out of build tree
150 set(CMAKE_BUILD_WITH_INSTALL_RPATH OFF)
151
152 # Find needed packages and if necessery abort if something important is missing
153 unset(ACE_INCLUDE_DIR CACHE)
154 unset(ACE_LIBRARIES CACHE)
155 unset(ACE_LIBRARIES_DIR CACHE)
156 unset(ACE_INCLUDE_DIR)
157 unset(ACE_LIBRARIES)
158 unset(ACE_LIBRARIES_DIR)
159 if(ACE_USE_EXTERNAL)
160 find_package(ACE)
161 if(NOT ACE_FOUND)
162 message(FATAL_ERROR
163 "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."
164 )
165 endif()
166 if(EXISTS ${ACE_INCLUDE_DIR}/ace/Stack_Trace.h)
167 set(HAVE_ACE_STACK_TRACE_H ON) # config.h.cmake
168 endif()
169 else()
170 include(cmake/ImportACE.cmake)
171 endif()
172
c37c8d2 @cipherCOM [11197] Allow of std malloc use instead of TBB
cipherCOM authored
173 if(NOT USE_STD_MALLOC)
174 unset(TBB_INCLUDE_DIR CACHE)
175 unset(TBB_LIBRARIES CACHE)
176 unset(TBB_LIBRARIES_DIR CACHE)
177 unset(TBB_INCLUDE_DIR)
178 unset(TBB_LIBRARIES)
179 unset(TBB_LIBRARIES_DIR)
180 if(TBB_USE_EXTERNAL)
181 find_package(TBB)
182 if(NOT TBB_FOUND)
183 message(FATAL_ERROR
184 "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."
185 )
186 endif()
187 else()
188 include(cmake/ImportTBB.cmake)
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
189 endif()
190 endif()
191
192 # Win32 delifered packages
193 if(WIN32)
194 set(MYSQL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/dep/include/mysql)
195 set(MYSQL_LIBRARY ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_release/libmySQL.lib)
196 set(MYSQL_DEBUG_LIBRARY ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_debug/libmySQL.lib)
197 set(OPENSSL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/dep/include/openssl)
198 set(OPENSSL_LIBRARIES ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_release/libeay32.lib)
199 set(OPENSSL_DEBUG_LIBRARIES ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_debug/libeay32.lib)
200 # zlib is build
201 endif()
202
203 # *nix-specific packages
204 if(UNIX)
205 find_package(MySQL REQUIRED)
206 find_package(OpenSSL REQUIRED)
207 find_package(ZLIB REQUIRED)
208 endif()
209
210 # Add uninstall script and target
211 configure_file(
212 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
213 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
214 IMMEDIATE @ONLY
215 )
216
217 add_custom_target(uninstall
218 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
219 )
220
221 # Find core revision
222 if(GIT_EXECUTABLE)
223 execute_process(
e2ea5ac [11184] Allow build mangos without git repo
blueboy authored
224 COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
225 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
226 OUTPUT_VARIABLE GIT_REVISION
e2ea5ac [11184] Allow build mangos without git repo
blueboy authored
227 RESULT_VARIABLE GIT_RESULT
228 ERROR_QUIET
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
229 )
e2ea5ac [11184] Allow build mangos without git repo
blueboy authored
230 if(GIT_RESULT)
231 set(GIT_REVISION "Git repository not found")
232 endif()
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
233 else()
234 set(GIT_REVISION "Git not found")
235 endif()
236
237 message("")
238 message("MaNGOS-Core revision : ${GIT_REVISION}")
239 message("Install server to : ${CMAKE_INSTALL_PREFIX}")
240 message("")
241
242 # if(CLI)
243 # message("Build with CLI : Yes (default)")
244 # add_definitions(-DENABLE_CLI)
245 # else()
246 # message("Build with CLI : No")
247 # endif()
248
249 # if(RA)
250 # message("* Build with RA : Yes")
251 # add_definitions(-DENABLE_RA)
252 # else(RA)
253 # message("* Build with RA : No (default)")
254 # endif(RA)
255
256 if(PCH AND NOT PCHSupport_FOUND)
257 set(PCH 0 CACHE BOOL
258 "Use precompiled headers"
259 FORCE)
260 message(
261 "No PCH for your system possible but PCH was set to 1. Resetting it."
262 )
263 endif()
264 if(PCH)
265 message("Use PCH : Yes")
266 else()
267 message("Use PCH : No")
268 endif()
269
270 if(DEBUG)
271 message("Build in debug-mode : Yes")
272 set(CMAKE_BUILD_TYPE Debug)
273 else()
274 set(CMAKE_BUILD_TYPE Release)
275 message("Build in debug-mode : No (default)")
276 endif()
277 # Handle debugmode compiles (this will require further work for proper WIN32-setups)
278 if(UNIX)
279 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
280 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
281 endif()
282
283 # Set warning levels for different builds
284 if(UNIX)
285 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} --no-warnings")
286 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} --no-warnings")
287 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wfatal-errors -Wextra")
288 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wfatal-errors -Wextra")
289 elseif(WIN32)
d4b156b @Neo2003 [11399] Make CMake a bit more usefull for Win/MSVC
Neo2003 authored
290 # Disable warnings in Visual Studio 8 and above and add /MP
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
291 if(MSVC AND NOT CMAKE_GENERATOR MATCHES "Visual Studio 7")
d4b156b @Neo2003 [11399] Make CMake a bit more usefull for Win/MSVC
Neo2003 authored
292 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /wd4996 /wd4355 /wd4244 /wd4985 /wd4267 /MP")
293 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /wd4996 /wd4355 /wd4244 /wd4267 /MP")
294 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /wd4996 /wd4355 /wd4244 /wd4985 /wd4267 /MP")
295 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd4996 /wd4355 /wd4244 /wd4985 /wd4267 /MP")
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
296 endif()
297 endif()
298
299 # if(SQL)
300 # message("Install SQL-files : Yes")
301 # else()
302 # message("Install SQL-files : No (default)")
303 # endif()
304
305 # if(TOOLS)
306 # message("Build map/vmap tools : Yes")
307 # else()
308 # message("Build map/vmap tools : No (default)")
309 # endif()
310
311 message("")
312
313 # Some small tweaks for Visual Studio 7 and above.
314 if(MSVC)
315 # Mark 32 bit executables large address aware so they can use > 2GB address space
316 if(PLATFORM MATCHES X86)
317 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
318 endif()
319 endif()
320
321 set(CMAKE_SKIP_BUILD_RPATH FALSE)
322 set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
323 set(CMAKE_INSTALL_RPATH ${LIBS_DIR})
324 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
325
326 # Generate revision-extractor
327 set(GENREV_SRC
328 src/tools/genrevision/genrevision.cpp
329 )
330
331 add_executable(genrev
332 ${GENREV_SRC}
333 )
334
335 # if(WIN32)
336 # set_target_properties(genrev PROPERTIES
337 # COMPILE_FLAGS "/MACHINE:X86"
338 # )
339 # elseif(UNIX)
340 # set_target_properties(genrev PROPERTIES
341 # COMPILE_FLAGS "-m32"
342 # LINK_FLAGS "-m32"
343 # )
344 # endif()
345 # if(XCODE)
346 # set_target_properties(genrev PROPERTIES
347 # XCODE_ATTRIBUTE_ARCHS "i386"
348 # )
349 # endif()
350
351 get_target_property(GENERATE_EXE genrev LOCATION)
352 add_custom_target("revision.h" ALL
353 COMMAND ${GENERATE_EXE} ${CMAKE_SOURCE_DIR}
354 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
355 DEPENDS genrev
356 )
357
358 if(WIN32)
359 install(
360 FILES
361 ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_release/libeay32.dll
362 ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_release/libmySQL.dll
363 DESTINATION ${LIBS_DIR}
364 CONFIGURATIONS Release
365 )
366 install(
367 FILES
368 ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_debug/libeay32.dll
369 ${CMAKE_SOURCE_DIR}/dep/lib/${DEP_ARCH}_debug/libmySQL.dll
370 DESTINATION ${LIBS_DIR}
371 CONFIGURATIONS Debug
372 )
373 if(PLATFORM MATCHES X86)
374 # Copy dll's Windows needs
375 install(
376 FILES
377 ${CMAKE_SOURCE_DIR}/dep/lib/win32_release/dbghelp.dll
378 DESTINATION ${LIBS_DIR}
379 CONFIGURATIONS Release
380 )
381 install(
382 FILES
383 ${CMAKE_SOURCE_DIR}/dep/lib/win32_debug/dbghelp.dll
384 DESTINATION ${LIBS_DIR}
385 CONFIGURATIONS Debug
386 )
387 endif()
388 endif()
389
390 # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARCH_FLAGS}")
391 # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_FLAGS}")
392 # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ARCH_FLAGS}")
393 if(XCODE)
394 if(PLATFORM MATCHES X86)
395 set(CMAKE_OSX_ARCHITECTURES i386)
396 else()
397 set(CMAKE_OSX_ARCHITECTURES x86_64)
398 endif()
399 endif()
400
401 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
402
403 add_subdirectory(dep) # TODO: add vmap extractor build support
404
405 # Add definitions for all build types
406 # Don't place this above 'dep' subdirectory! Because of defines build will crash.
407 set(DEFINITIONS
408 DO_MYSQL
409 HAVE_CONFIG_H
410 VERSION="${MANGOS_VERSION}"
411 SYSCONFDIR="${CONF_DIR}/"
412 )
413 set(DEFINITIONS_RELEASE NDEBUG)
414 set(DEFINITIONS_DEBUG _DEBUG MANGOS_DEBUG)
415 if(WIN32)
416 set(DEFINITIONS ${DEFINITIONS} WIN32 _WIN32)
417 set(DEFINITIONS_RELEASE ${DEFINITIONS_RELEASE} _CRT_SECURE_NO_WARNINGS)
418 endif()
c37c8d2 @cipherCOM [11197] Allow of std malloc use instead of TBB
cipherCOM authored
419 if(USE_STD_MALLOC)
420 set(DEFINITIONS ${DEFINITIONS} USE_STANDARD_MALLOC)
421 endif()
33fd34a @cipherCOM [11167] Added CMake support
cipherCOM authored
422
423 set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "${DEFINITIONS}")
424 set_directory_properties(PROPERTIES COMPILE_DEFINITIONS_RELEASE "${DEFINITIONS_RELEASE}")
425 set_directory_properties(PROPERTIES COMPILE_DEFINITIONS_DEBUG "${DEFINITIONS_DEBUG}")
426
427 add_subdirectory(src)
428 # if(SQL)
429 # add_subdirectory(sql)
430 # endif()
Something went wrong with that request. Please try again.