Skip to content

Commit

Permalink
Let CMake projects use the common CMake files. Enable C++11 mode (GCC…
Browse files Browse the repository at this point in the history
…/clang).
  • Loading branch information
evil-at-wow authored and Cyberium committed Oct 7, 2015
1 parent 97ccddd commit 42bb6e7
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 19 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Expand Up @@ -22,15 +22,14 @@ cmake_minimum_required(VERSION 2.8)

set(MANGOS_VERSION 0.12.3)

include(cmake/common.cmake)

# Set RPATH-handing (CMake parameters)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH ${LIBS_DIR})
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# set macro-directory
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/macros")

# set default buildoptions and print them
include(cmake/options.cmake)

Expand Down
7 changes: 7 additions & 0 deletions cmake/common.cmake
@@ -0,0 +1,7 @@

# First, get the root of the repository.
get_filename_component(ROOT_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(ROOT_DIR "${ROOT_DIR}/.." ABSOLUTE)

# Set the macro directory.
set(CMAKE_MODULE_PATH "${ROOT_DIR}/cmake/macros")
12 changes: 12 additions & 0 deletions cmake/compiler/clang/settings.cmake
@@ -1,6 +1,18 @@
# Set build-directive (used in core to tell which buildtype we used)
add_definitions(-D_BUILD_DIRECTIVE='"$(CONFIGURATION)"')

# Check C++11 compiler support
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(FATAL_ERROR "Error, CMaNGOS requires a compiler that supports C++11!")
endif()

if(WARNINGS)
set(WARNING_FLAGS "-W -Wall -Wextra -Winit-self -Wfatal-errors")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")
Expand Down
12 changes: 12 additions & 0 deletions cmake/compiler/gcc/settings.cmake
@@ -1,6 +1,18 @@
# Set build-directive (used in core to tell which buildtype we used)
add_definitions(-D_BUILD_DIRECTIVE='"${CMAKE_BUILD_TYPE}"')

# Check C++11 compiler support
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(FATAL_ERROR "Error, CMaNGOS requires a compiler that supports C++11!")
endif()

if(PLATFORM EQUAL X86)
# Required on 32-bit systems to enable SSE2 (standard on x64)
set(SSE_FLAGS "-msse2 -mfpmath=sse")
Expand Down
4 changes: 2 additions & 2 deletions cmake/macros/CheckPlatform.cmake
Expand Up @@ -8,7 +8,7 @@ else()
endif()

if(WIN32)
include("${CMAKE_SOURCE_DIR}/cmake/platform/win/settings.cmake")
include("${ROOT_DIR}/cmake/platform/win/settings.cmake")
elseif(UNIX)
include("${CMAKE_SOURCE_DIR}/cmake/platform/unix/settings.cmake")
include("${ROOT_DIR}/cmake/platform/unix/settings.cmake")
endif()
4 changes: 2 additions & 2 deletions cmake/macros/ImportACE.cmake
Expand Up @@ -23,8 +23,8 @@
# set_target_properties(ace PROPERTIES DEPENDS ACE_Project)

if(WIN32)
set(ACE_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/dep/ACE_wrappers)
set(ACE_LIBRARIES_DIR ${CMAKE_SOURCE_DIR}/dep/ACE_wrappers/lib)
set(ACE_INCLUDE_DIR ${ROOT_DIR}/dep/ACE_wrappers)
set(ACE_LIBRARIES_DIR ${ROOT_DIR}/dep/ACE_wrappers/lib)
set(ACE_LIBRARIES optimized ACE debug ACEd)
else()
set(ACE_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include)
Expand Down
10 changes: 5 additions & 5 deletions cmake/macros/ImportTBB.cmake
Expand Up @@ -44,8 +44,8 @@ if(WIN32)
# IMPORTED_IMPLIB_DEBUG ${CMAKE_SOURCE_DIR}/dep/tbb/build/${VSDIR}/${ARCHDIR}/Debug/tbbmalloc_debug.lib
# )
set(TBB_LIBRARIES_DIR
${CMAKE_SOURCE_DIR}/dep/tbb/build/${VSDIR}/${ARCHDIR}/Release
${CMAKE_SOURCE_DIR}/dep/tbb/build/${VSDIR}/${ARCHDIR}/Debug
${ROOT_DIR}/dep/tbb/build/${VSDIR}/${ARCHDIR}/Release
${ROOT_DIR}/dep/tbb/build/${VSDIR}/${ARCHDIR}/Debug
)
else()
if(APPLE)
Expand All @@ -62,8 +62,8 @@ else()
# IMPORTED_LOCATION_DEBUG ${CMAKE_SOURCE_DIR}/dep/tbb/build/libs_debug/libtbbmalloc_debug.${LIB_SUFFIX}
# )
set(TBB_LIBRARIES_DIR
${CMAKE_SOURCE_DIR}/dep/tbb/build/libs_release
${CMAKE_SOURCE_DIR}/dep/tbb/build/libs_debug
${ROOT_DIR}/dep/tbb/build/libs_release
${ROOT_DIR}/dep/tbb/build/libs_debug
)
endif()
# Sadly doesn't work in current version
Expand All @@ -72,7 +72,7 @@ endif()
# set_target_properties(tbb PROPERTIES DEPENDS TBB_Project)
# set_target_properties(tbbmalloc PROPERTIES DEPENDS TBB_Project)

set(TBB_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/dep/tbb/include)
set(TBB_INCLUDE_DIR ${ROOT_DIR}/dep/tbb/include)
set(TBB_LIBRARIES optimized tbb optimized tbbmalloc debug tbb_debug debug tbbmalloc_debug)

# Little Hack to remove the link warnings because of not found directories
Expand Down
6 changes: 3 additions & 3 deletions cmake/platform/unix/settings.cmake
@@ -1,6 +1,6 @@
# configure uninstaller
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/platform/cmake_uninstall.cmake.in"
"${ROOT_DIR}/cmake/platform/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY
)
Expand All @@ -14,9 +14,9 @@ message(STATUS "UNIX: Created uninstall target")

message(STATUS "UNIX: Detected compiler: ${CMAKE_C_COMPILER}")
if(CMAKE_C_COMPILER MATCHES "gcc" OR CMAKE_C_COMPILER_ID STREQUAL "GNU")
include(${CMAKE_SOURCE_DIR}/cmake/compiler/gcc/settings.cmake)
include("${ROOT_DIR}/cmake/compiler/gcc/settings.cmake")
elseif(CMAKE_C_COMPILER MATCHES "clang")
include(${CMAKE_SOURCE_DIR}/cmake/compiler/clang/settings.cmake)
include("${ROOT_DIR}/cmake/compiler/clang/settings.cmake")
else()
add_definitions(-D_BUILD_DIRECTIVE='"${CMAKE_BUILD_TYPE}"')
endif()
2 changes: 1 addition & 1 deletion cmake/platform/win/settings.cmake
@@ -1,3 +1,3 @@
if ( MSVC )
include(${CMAKE_SOURCE_DIR}/cmake/compiler/msvc/settings.cmake)
include("${ROOT_DIR}/cmake/compiler/msvc/settings.cmake")
endif()
3 changes: 3 additions & 0 deletions contrib/extractor/CMakeLists.txt
Expand Up @@ -11,6 +11,9 @@
cmake_minimum_required (VERSION 2.6)
project (MANGOS_MAP_EXTRACTOR)

include(../../cmake/common.cmake)
include(CheckPlatform)

add_subdirectory (libmpq)
add_subdirectory (loadlib)

Expand Down
9 changes: 6 additions & 3 deletions contrib/git_id/CMakeLists.txt
@@ -1,4 +1,7 @@
SET(CMAKE_VERBOSE_MAKEFILE ON)
cmake_minimum_required (VERSION 2.6)
ADD_EXECUTABLE (git_id git_id.cpp)

cmake_minimum_required(VERSION 2.8)

include(../../cmake/common.cmake)
include(CheckPlatform)

ADD_EXECUTABLE(git_id git_id.cpp)
3 changes: 3 additions & 0 deletions contrib/mmap/CMakeLists.txt
Expand Up @@ -12,6 +12,9 @@ cmake_minimum_required (VERSION 2.6)

project( MoveMapGen )

include(../../cmake/common.cmake)
include(CheckPlatform)

ADD_DEFINITIONS(-DMMAP_GENERATOR -DNO_CORE_FUNCS -DDEBUG)
ADD_DEFINITIONS(-DDT_POLYREF64)

Expand Down
3 changes: 3 additions & 0 deletions contrib/vmap_assembler/CMakeLists.txt
Expand Up @@ -11,6 +11,9 @@
cmake_minimum_required (VERSION 2.6)
project (MANGOS_VMAP_ASSEMB_IO)

include(../../cmake/common.cmake)
include(CheckPlatform)

set(CMAKE_VERBOSE_MAKEFILE true)

# uncomment next line to disable debug mode
Expand Down
2 changes: 2 additions & 0 deletions contrib/vmap_extractor/CMakeLists.txt
Expand Up @@ -11,6 +11,8 @@
cmake_minimum_required (VERSION 2.6)
project (MANGOS_VMAP_EXTRACT_IO)

include(../../cmake/common.cmake)
include(CheckPlatform)

# uncomment next line to disable debug mode
ADD_DEFINITIONS("-DIOMAP_DEBUG")
Expand Down

0 comments on commit 42bb6e7

Please sign in to comment.