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 committed Sep 17, 2015
1 parent 46e3acc commit 434d133
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.18)

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

10 comments on commit 434d133

@evil-at-wow
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For anyone wondering: even though I've managed to build them all on my Linux machine so I could test this commit, not all the tools in the contrib folder (extractor, vmap_extractor, mmap, etc) actually build nicely out of the box on *nix systems yet. But we're working on that, so stay tuned!

@cala
Copy link
Contributor

@cala cala commented on 434d133 Sep 18, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An humble note of mine: I will probably need help to backport all the recent commits to Classic core when time comes because most of them are beyond my knowledge in C++.

@BeerfishWoW
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into a few problems trying to install the clean WotLK master branch on my Unbuntu system last night. Here's a summary of what happend:

  • cmake went fine
  • make error:
    Making install in .
    /bin/bash ../libtool --mode=install /usr/bin/install -c libACE.la '/usr/local/lib'
    libtool: install: /usr/bin/install -c .libs/libACE-5.8.3.so /usr/local/lib/libACE-5.8.3.so
    /usr/bin/install: cannot create regular file '/usr/local/lib/libACE-5.8.3.so': Permission denied
    make[7]: *** [install-libLTLIBRARIES] Error 1
    make[6]: *** [install-am] Error 2
    make[5]: *** [install-recursive] Error 1
    make[4]: *** [install] Error 2
    make[3]: *** [install-recursive] Error 1
    make[2]: *** [dep/ACE_wrappers/ACE_Project-prefix/src/ACE_Project-stamp/ACE_Project-install] Error 2
    make[1]: *** [dep/ACE_wrappers/CMakeFiles/ACE_Project.dir/all] Error 2
    make: *** [all] Error 2
  • make install error:
    CMake Error at src/scriptdev2/cmake_install.cmake:72 (FILE):
    file INSTALL cannot find
    "/home/mangos/mangos/src/scriptdev2/scriptdev2.conf.dist.in".
    Call Stack (most recent call first):
    src/cmake_install.cmake:42 (INCLUDE)
    cmake_install.cmake:62 (INCLUDE)
  • Running make as sudo solved the error above.
  • The make install error has been solved in 62915db.
  • After cmake, make and make install I am indeed missing a couple of things, among which the entire run directory.

Created a post about this on the cmangos forums, too: http://cmangos.net/thread-7223.html

@evil-at-wow
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BeerfishWoW The make error is normal, to say so. On a typical Linux system, a normal user can't make changes to system folders like /usr/lib, /usr/bin, etc. Sadly, as part of the core build, ACE gets build and installed, and the ACE installation part is a problem if you're running the make step as a normal user and you install to a system folder (that's why running make as sudo fixed the problem). But this has been a problem for ages now. I don't think it's worth the effort to investigate this at this point, because we're slowly replacing ACE anyway.

Also, I'm not sure what run directory you mean? I don't think I've ever had a run directory in my (C)MaNGOS installation? Can you provide some details about what you're missing?

[edit]
@cala No worries, @Stfx is backporting anyway these days 😀

@BeerfishWoW
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The run directory described, for example, in the CMaNGOS guide: https://github.com/cmangos/issues/wiki/Installation-Instructions. It contains the files to start the server, /home/mangos/mangos/run/bin/mangosd -c /home/mangos/mangos/run/etc/mangosd.conf. Where are the executables and conf files for *unix?

@BeerfishWoW
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, it appears the executables are in /usr/local/bin and the conf files in /mangos/src/mangosd and realmd. It's not where they were prior to this commit, I think.

@evil-at-wow
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. I didn't know that the guide suggested to make a directory called run.

The executables and everything else should be installed in subfolders of the directory you pass on the command line with CMAKE_INSTALL_PREFIX (the run directory, as you say) when you run CMake. The executables end up in the bin subfolder, the configuration files should be in the etc subfolder, some libraries in a lib subfolder, etc. At least that's where they've always been on my Linux system. I haven't installed a core yet after the last few commits though.

@BeerfishWoW
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And that's where I made a mistake. I forgot to include the CMAKE_INSTALL_PREFIX because it was so attached to ScriptDev2 in my mind. Obviously, you still need to run it to create the /run dir. My bad!

@BeerfishWoW
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything works as it should right now. Thank you for a job well done guys!

@BeerfishWoW
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evil-at-wow I'm getting the following error when trying to install the latest version of WotLK CMaNGOS:
mangos@SNOWFALL:~/Build$ make
Scanning dependencies of target genrev
[ 0%] Building CXX object CMakeFiles/genrev.dir/src/tools/genrevision/genrevision.cpp.o
Linking CXX executable genrev
[ 0%] Built target genrev
Scanning dependencies of target revision.h
make[2]: *** [CMakeFiles/revision.h] Segmentation fault (core dumped)
make[1]: *** [CMakeFiles/revision.h.dir/all] Error 2
make: *** [all] Error 2

Any clue how I can fix this?

I've compiled and installed version 1.59 of boost. This is my CMAKE command:
cmake ../mangos -DCMAKE_INSTALL_PREFIX=../mangos/run -DPCH=1 -DDEBUG=0 -DBOOST_ROOT=/usr/local/boost_1_59_0/

Please sign in to comment.