Skip to content

Commit

Permalink
Cleanup cmake a bit more. (vmangos#2817)
Browse files Browse the repository at this point in the history
  • Loading branch information
0blu authored Oct 31, 2024
1 parent fbbc4ae commit 2d0db2a
Show file tree
Hide file tree
Showing 20 changed files with 212 additions and 190 deletions.
9 changes: 8 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ root = true

[*]
indent_style = space
indent_size = 4
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{*.cmake,CMakeLists.txt}]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
173 changes: 7 additions & 166 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,10 @@ if(${CMAKE_VERSION} VERSION_GREATER "3.11")
cmake_policy(SET CMP0074 NEW)
endif()

set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${CMAKE_SOURCE_DIR}/cmake
)

set(SUPPORTED_CLIENT_BUILD "CLIENT_BUILD_1_12_1" CACHE STRING "Client version the core will support")
option(USE_STD_MALLOC "Use standard malloc instead of TBB" OFF)
option(BUILD_FOR_HOST_CPU "Build specifically for the host CPU via `-march=native` (might not run on different machines)" ON)
option(TBB_DEBUG "Use TBB debug librairies" OFF)
option(USE_SCRIPTS "Compile scripts" ON)
option(USE_EXTRACTORS "Compile extractors" OFF)
option(USE_LIBCURL "Compile with libcurl for email support" OFF)
option(USE_REALMMERGE "Compile helper tool for merging character databases" OFF)

if(UNIX)
option(DEBUG_SYMBOLS "Include Debug Symbols" ON)
endif()

find_package(PCHSupport)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16")
option(USE_PCH "Use precompiled headers" ON)
endif()
include(cmake/common.cmake)
include(cmake/options.cmake)

if(PCHSupport_FOUND AND (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16"))
if(MSVC)
option(USE_PCH_OLD "Use old precompiled headers implementation" ON)
else()
option(USE_PCH_OLD "Use old precompiled headers implementation" OFF)
endif()
else()
unset(USE_PCH_OLD CACHE)
endif()
include(cmake/platform/detect_platform.cmake)

if(USE_LIBCURL)
find_package(CURL REQUIRED)
Expand All @@ -73,37 +45,8 @@ if(BUILDING_IN_SOURCE)
)
endif()

if(WIN32)
if(MSVC)
if(MSVC_VERSION LESS 1900)
message(FATAL_ERROR "Only Visual Studio 2015 or newer is supported")
endif()
endif()

# Added by Giperion, in WIN32 output all compiled files in one directory
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib )
# Allow creating folders in solution
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif()

find_package(Platform REQUIRED)
find_package(Git)

# Output description of this script
message(STATUS
"\nThis script builds the MaNGOS server.
Options that can be used in order to configure the process:
PREFIX: Path where the server should be installed to
USE_PCH: Use precompiled headers
To set an option simply type -D<OPTION>=<VALUE> after 'cmake <srcs>'.
For example: cmake .. -DPREFIX=/opt/mangos\n"
) # TODO: PLATFORM: Sets the architecture for compile (X86,X64)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()

# Find out what system we use to include the needed libs
if(WIN32)
if(PLATFORM MATCHES X86) # 32-bit
Expand All @@ -113,19 +56,6 @@ if(WIN32)
endif()
endif()

# Add options for compile of mangos
if((${CMAKE_VERSION} VERSION_LESS "3.16") OR USE_PCH_OLD)
if(PCHSupport_FOUND)
if(WIN32)
option(USE_PCH "Use precompiled headers" ON)
else()
option(USE_PCH "Use precompiled headers" OFF)
endif()
endif()
else()
option(USE_PCH "Use precompiled headers" ON)
endif()

# Set up the install-prefix
if(CMAKE_INSTALL_PREFIX STREQUAL "/usr/local")
get_filename_component(PREFIX_ABSOLUTE "../server" ABSOLUTE)
Expand Down Expand Up @@ -265,20 +195,14 @@ else()
set(rev_hash "unknown")
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/revision.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/src/shared/revision.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/generators/revision.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/shared/revision.h)
endif()

set(supported_build ${SUPPORTED_CLIENT_BUILD})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Progression.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/src/shared/Progression.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/generators/Progression.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/shared/Progression.h)

# Generate migrations list
include(cmake/migrations.cmake)

message(STATUS "")
message(STATUS "Core revision: ${rev_hash} ${rev_date} ")
message(STATUS "Supported version: ${supported_build}")
message(STATUS "Install server to: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "")
include(cmake/generators/migrations_list.h.cmake)

if(${CMAKE_VERSION} VERSION_LESS "3.16")
if(USE_PCH AND NOT PCHSupport_FOUND)
Expand All @@ -291,20 +215,6 @@ if(${CMAKE_VERSION} VERSION_LESS "3.16")
endif()
endif()

if(USE_PCH)
message(STATUS "Use PCH : Yes")
else()
message(STATUS "Use PCH : No")
endif()

if(PROFILE_GENERATE)
message(STATUS "PGO profile : Generate")
elseif(PROFILE_USE)
message(STATUS "PGO profile : ${GCC_PROFILE_USE}")
else()
message(STATUS "PGO profile : Disabled")
endif()

if(USE_STD_MALLOC)
set(ALLOC_LIB_INFO_STRING "std::malloc")
else()
Expand All @@ -314,77 +224,8 @@ else()
set(ALLOC_LIB_INFO_STRING "TBB/Release")
endif()
endif()
message(STATUS "Memory allocation : ${ALLOC_LIB_INFO_STRING} ${TBB_LIBRARIES}")
message(STATUS "Detected compiler : ${CMAKE_CXX_COMPILER_ID}")

if(BUILD_FOR_HOST_CPU)
message(STATUS "Build for host CPU : Yes (default)")
else()
message(STATUS "Build for host CPU : No")
endif()

message(STATUS "Build type : ${CMAKE_BUILD_TYPE}")

if(USE_SCRIPTS)
message(STATUS "Build scripts : Yes (default)")
else()
message(STATUS "Build scripts : No")
endif()

if(UNIX)
if(DEBUG_SYMBOLS)
message(STATUS "Debug symbols : Included")
set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -g")
else()
message(STATUS "Debug symbols : Disabled")
endif()

if(GCC_SANITIZE)
set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -fno-omit-frame-pointer -fno-optimize-sibling-calls")
set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -fsanitize=address")
#set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -fsanitize=thread")
set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -fsanitize=return")
set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -fsanitize=shift")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -fsanitize=bounds")
set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -fsanitize=vptr")
set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -fno-sanitize-recover")
endif()
#set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -fsanitize=unsigned-integer-overflow")
endif()

set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} --no-warnings -fexceptions -fnon-call-exceptions -pipe")
if(BUILD_FOR_HOST_CPU)
set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -march=native")
endif()
set(CMAKE_CXX_STANDARD 14)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(PROFILE_GENERATE)
set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -fprofile-generate")
elseif(PROFILE_USE)
set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -fprofile-use -fprofile-correction -Wno-error=coverage-mismatch")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(PROFILE_GENERATE)
set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -fprofile-instr-generate")
elseif(PROFILE_USE)
set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -fprofile-instr-use")
endif()
endif()

set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${BUILD_ADDITIONAL_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${BUILD_ADDITIONAL_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${BUILD_ADDITIONAL_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${BUILD_ADDITIONAL_FLAGS}")
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()
include(cmake/showoptions.cmake)

set(DEFINITIONS_RELEASE ${DEFINITIONS_RELEASE} NDEBUG)
set(DEFINITIONS_DEBUG ${DEFINITIONS_DEBUG} _DEBUG MANGOS_DEBUG)
Expand Down
23 changes: 0 additions & 23 deletions cmake/FindPlatform.cmake

This file was deleted.

7 changes: 7 additions & 0 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
@@ -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 directory to find dependencies
list(APPEND CMAKE_MODULE_PATH ${ROOT_DIR}/cmake/find)
6 changes: 6 additions & 0 deletions cmake/compiler/msvc/settings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

# Disable warnings in Visual Studio and add /MP
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")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
75 changes: 75 additions & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

# Generic boolean options
option(USE_STD_MALLOC "Use standard malloc instead of TBB" OFF)
option(BUILD_FOR_HOST_CPU "Build specifically for the host CPU via `-march=native` (might not run on different machines)" ON)
option(TBB_DEBUG "Use TBB debug libraries" OFF)
option(USE_SCRIPTS "Compile scripts" ON)
option(USE_EXTRACTORS "Compile extractors" OFF)
option(USE_LIBCURL "Compile with libcurl for email support" OFF)
option(USE_REALMMERGE "Compile helper tool for merging character databases" OFF)

# Other options
set(SUPPORTED_CLIENT_BUILD "CLIENT_BUILD_1_12_1" CACHE STRING "Client version the core will support")

if(UNIX)
option(DEBUG_SYMBOLS "Include Debug Symbols" ON)
endif()

# Precompile headers stuff
find_package(PCHSupport)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16")
option(USE_PCH "Use precompiled headers" ON)
endif()

# TODO: I have no idea why `USE_PCH_OLD`, is needed if there is `USE_PCH`
if(PCHSupport_FOUND AND (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16"))
if(MSVC)
option(USE_PCH_OLD "Use old precompiled headers implementation" ON)
else()
option(USE_PCH_OLD "Use old precompiled headers implementation" OFF)
endif()
else()
unset(USE_PCH_OLD CACHE)
endif()

if((${CMAKE_VERSION} VERSION_LESS "3.16") OR USE_PCH_OLD)
if(PCHSupport_FOUND)
if(WIN32)
option(USE_PCH "Use precompiled headers" ON)
else()
option(USE_PCH "Use precompiled headers" OFF)
endif()
endif()
else()
option(USE_PCH "Use precompiled headers" ON)
endif()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()


message("")
message(STATUS
"This script builds the vMaNGOS server.
Options that can be used in order to configure the process:
PREFIX Path where the server should be installed to
CMAKE_INSTALL_PREFIX Path where the server should be installed to
USE_PCH Use precompiled headers
USE_PCH_OLD Use precompiled headers
USE_STD_MALLOC Use standard malloc instead of TBB
BUILD_FOR_HOST_CPU Build specifically for the host CPU via `-march=native` (might not run on different machines)
TBB_DEBUG Use TBB debug libraries
USE_SCRIPTS Compile scripts
USE_EXTRACTORS Compile extractors
USE_LIBCURL Compile with libcurl for email support
USE_REALMMERGE Compile helper tool for merging character databases
SUPPORTED_CLIENT_BUILD Client version the core will support
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:
Build server
cmake -DCMAKE_INSTALL_PREFIX=../opt/vmangos ..
")
File renamed without changes.
17 changes: 17 additions & 0 deletions cmake/platform/detect_platform.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# check what platform we're on 64-bit or 32-bit
if(CMAKE_SIZEOF_VOID_P MATCHES 8)
set(PLATFORM X64)
message(STATUS "Detected 64-bit platform")
IF(WIN32)
ADD_DEFINITIONS("-D_WIN64")
ENDIF()
else()
set(PLATFORM X86)
message(STATUS "Detected 32-bit platform")
endif()

if(WIN32)
include("${ROOT_DIR}/cmake/platform/win/settings.cmake")
elseif(UNIX)
include("${ROOT_DIR}/cmake/platform/unix/settings.cmake")
endif()
Loading

0 comments on commit 2d0db2a

Please sign in to comment.