diff options
Diffstat (limited to 'cmake')
| -rw-r--r-- | cmake/compiler/clang/settings.cmake | 13 | ||||
| -rw-r--r-- | cmake/compiler/gcc/settings.cmake | 14 | ||||
| -rw-r--r-- | cmake/compiler/msvc/settings.cmake | 29 | ||||
| -rw-r--r-- | cmake/genrev.cmake | 2 | ||||
| -rw-r--r-- | cmake/macros/ConfigureScripts.cmake | 104 | ||||
| -rw-r--r-- | cmake/macros/FindBoost.cmake | 1 | ||||
| -rw-r--r-- | cmake/macros/FindPCHSupport.cmake | 2 | ||||
| -rw-r--r-- | cmake/options.cmake | 22 | ||||
| -rw-r--r-- | cmake/platform/win/settings.cmake | 21 | ||||
| -rw-r--r-- | cmake/showoptions.cmake | 24 |
10 files changed, 198 insertions, 34 deletions
diff --git a/cmake/compiler/clang/settings.cmake b/cmake/compiler/clang/settings.cmake index 261a55b285f..1cd95bbf703 100644 --- a/cmake/compiler/clang/settings.cmake +++ b/cmake/compiler/clang/settings.cmake @@ -18,3 +18,16 @@ endif() # -Wno-deprecated-register is needed to suppress 185 gsoap warnings on Unix systems. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-narrowing -Wno-deprecated-register") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG=1") + +if (BUILD_SHARED_LIBS) + # -fPIC is needed to allow static linking in shared libs. + # -fvisibility=hidden sets the default visibility to hidden to prevent exporting of all symbols. + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -fvisibility=hidden") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -fvisibility=hidden") + + # --no-undefined to throw errors when there are undefined symbols + # (caused through missing TRINITY_*_API macros). + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --no-undefined") + + message(STATUS "Clang: Disallow undefined symbols") +endif() diff --git a/cmake/compiler/gcc/settings.cmake b/cmake/compiler/gcc/settings.cmake index acd71e82fd9..a0c2b737475 100644 --- a/cmake/compiler/gcc/settings.cmake +++ b/cmake/compiler/gcc/settings.cmake @@ -1,7 +1,7 @@ # Set build-directive (used in core to tell which buildtype we used) add_definitions(-D_BUILD_DIRECTIVE='"${CMAKE_BUILD_TYPE}"') -set(GCC_EXPECTED_VERSION 4.7.2) +set(GCC_EXPECTED_VERSION 4.9.0) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS GCC_EXPECTED_VERSION) message(FATAL_ERROR "GCC: TrinityCore requires version ${GCC_EXPECTED_VERSION} to build but found ${CMAKE_CXX_COMPILER_VERSION}") @@ -34,3 +34,15 @@ if( WITH_COREDEBUG ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3") message(STATUS "GCC: Debug-flags set (-g3)") endif() + +if (BUILD_SHARED_LIBS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -fvisibility=hidden -Wno-attributes") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -fvisibility=hidden -Wno-attributes") + + # Should break the build when there are TRINITY_*_API macros missing + # but it complains about missing references in precompiled headers. + # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--no-undefined") + # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--no-undefined") + + message(STATUS "GCC: Enabled shared linking") +endif() diff --git a/cmake/compiler/msvc/settings.cmake b/cmake/compiler/msvc/settings.cmake index 8af8033d809..afde70b0f79 100644 --- a/cmake/compiler/msvc/settings.cmake +++ b/cmake/compiler/msvc/settings.cmake @@ -18,11 +18,6 @@ if(PLATFORM EQUAL 64) add_definitions("-D_WIN64") message(STATUS "MSVC: 64-bit platform, enforced -D_WIN64 parameter") - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0.23026.0) - #Enable extended object support for debug compiles on X64 (not required on X86) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj") - message(STATUS "MSVC: Enabled increased number of sections in object files") - endif() else() # mark 32 bit executables large address aware so they can use > 2GB address space set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE") @@ -36,20 +31,31 @@ else() endif() # Set build-directive (used in core to tell which buildtype we used) -add_definitions(-D_BUILD_DIRECTIVE=\\"$(ConfigurationName)\\") +# msbuild/devenv don't set CMAKE_MAKE_PROGRAM, you can choose build type from a dropdown after generating projects +if("${CMAKE_MAKE_PROGRAM}" MATCHES "MSBuild") + add_definitions(-D_BUILD_DIRECTIVE=\\"$(ConfigurationName)\\") +else() + # while all make-like generators do (nmake, ninja) + add_definitions(-D_BUILD_DIRECTIVE=\\"${CMAKE_BUILD_TYPE}\\") +endif() # multithreaded compiling on VS set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") +if((PLATFORM EQUAL 64) OR (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0.23026.0) OR BUILD_SHARED_LIBS) + # Enable extended object support + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") + message(STATUS "MSVC: Enabled increased number of sections in object files") +endif() + # /Zc:throwingNew. # When you specify Zc:throwingNew on the command line, it instructs the compiler to assume # that the program will eventually be linked with a conforming operator new implementation, # and can omit all of these extra null checks from your program. # http://blogs.msdn.com/b/vcblog/archive/2015/08/06/new-in-vs-2015-zc-throwingnew.aspx if(NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0.23026.0)) - # also enable /bigobj for ALL builds under visual studio 2015, increased number of templates in standard library # makes this flag a requirement to build TC at all - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:throwingNew /bigobj") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:throwingNew") endif() # Define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES - eliminates the warning by changing the strcpy call to strcpy_s, which prevents buffer overruns @@ -74,6 +80,13 @@ if(NOT WITH_WARNINGS) message(STATUS "MSVC: Disabled generic compiletime warnings") endif() +if (BUILD_SHARED_LIBS) + # C4251: needs to have dll-interface to be used by clients of class '...' + # C4275: non dll-interface class ...' used as base for dll-interface class '...' + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251 /wd4275") + message(STATUS "MSVC: Enabled shared linking") +endif() + # Specify the maximum PreCompiled Header memory allocation limit # Fixes a compiler-problem when using PCH - the /Ym flag is adjusted by the compiler in MSVC2012, hence we need to set an upper limit with /Zm to avoid discrepancies) # (And yes, this is a verified , unresolved bug with MSVC... *sigh*) diff --git a/cmake/genrev.cmake b/cmake/genrev.cmake index 5c013756f09..d123153e975 100644 --- a/cmake/genrev.cmake +++ b/cmake/genrev.cmake @@ -24,7 +24,7 @@ else() if(GIT_EXECUTABLE) # Create a revision-string that we can use execute_process( - COMMAND "${GIT_EXECUTABLE}" describe --match init --dirty=+ --abbrev=12 + COMMAND "${GIT_EXECUTABLE}" describe --long --match init --dirty=+ --abbrev=12 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE rev_info OUTPUT_STRIP_TRAILING_WHITESPACE diff --git a/cmake/macros/ConfigureScripts.cmake b/cmake/macros/ConfigureScripts.cmake new file mode 100644 index 00000000000..5260d3a1afe --- /dev/null +++ b/cmake/macros/ConfigureScripts.cmake @@ -0,0 +1,104 @@ +# Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/> +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# Returns the base path to the script directory in the source directory +function(WarnAboutSpacesInBuildPath) + # Only check win32 since unix doesn't allow spaces in paths + if (WIN32) + string(FIND "${CMAKE_BINARY_DIR}" " " SPACE_INDEX_POS) + + if (SPACE_INDEX_POS GREATER -1) + message("") + message(WARNING " *** WARNING!\n" + " *** Your selected build directory contains spaces!\n" + " *** Please note that this will cause issues!") + endif() + endif() +endfunction() + +# Returns the base path to the script directory in the source directory +function(GetScriptsBasePath variable) + set(${variable} "${CMAKE_SOURCE_DIR}/src/server/scripts" PARENT_SCOPE) +endfunction() + +# Stores the absolut path of the given module in the variable +function(GetPathToScriptModule module variable) + GetScriptsBasePath(SCRIPTS_BASE_PATH) + set(${variable} "${SCRIPTS_BASE_PATH}/${module}" PARENT_SCOPE) +endfunction() + +# Stores the project name of the given module in the variable +function(GetProjectNameOfScriptModule module variable) + string(TOLOWER "scripts_${SCRIPT_MODULE}" GENERATED_NAME) + set(${variable} "${GENERATED_NAME}" PARENT_SCOPE) +endfunction() + +# Creates a list of all script modules +# and stores it in the given variable. +function(GetScriptModuleList variable) + GetScriptsBasePath(BASE_PATH) + file(GLOB LOCALE_SCRIPT_MODULE_LIST RELATIVE + ${BASE_PATH} + ${BASE_PATH}/*) + + set(${variable}) + foreach(SCRIPT_MODULE ${LOCALE_SCRIPT_MODULE_LIST}) + GetPathToScriptModule(${SCRIPT_MODULE} SCRIPT_MODULE_PATH) + if (IS_DIRECTORY ${SCRIPT_MODULE_PATH}) + list(APPEND ${variable} ${SCRIPT_MODULE}) + endif() + endforeach() + set(${variable} ${${variable}} PARENT_SCOPE) +endfunction() + +# Converts the given script module name into it's +# variable name which holds the linkage type. +function(ScriptModuleNameToVariable module variable) + string(TOUPPER ${module} ${variable}) + set(${variable} "SCRIPTS_${${variable}}") + set(${variable} ${${variable}} PARENT_SCOPE) +endfunction() + +# Stores in the given variable whether dynamic linking is required +function(IsDynamicLinkingRequired variable) + if(SCRIPTS MATCHES "dynamic") + set(IS_DEFAULT_VALUE_DYNAMIC ON) + endif() + + GetScriptModuleList(SCRIPT_MODULE_LIST) + set(IS_REQUIRED OFF) + foreach(SCRIPT_MODULE ${SCRIPT_MODULE_LIST}) + ScriptModuleNameToVariable(${SCRIPT_MODULE} SCRIPT_MODULE_VARIABLE) + if ((${SCRIPT_MODULE_VARIABLE} STREQUAL "dynamic") OR + (${SCRIPT_MODULE_VARIABLE} STREQUAL "default" AND IS_DEFAULT_VALUE_DYNAMIC)) + set(IS_REQUIRED ON) + break() + endif() + endforeach() + set(${variable} ${IS_REQUIRED} PARENT_SCOPE) +endfunction() + +# Stores the native variable name +function(GetNativeSharedLibraryName module variable) + if(WIN32) + set(${variable} "${module}.dll" PARENT_SCOPE) + else() + set(${variable} "lib${module}.so" PARENT_SCOPE) + endif() +endfunction() + +# Stores the native install path in the variable +function(GetInstallOffset variable) + if(WIN32) + set(${variable} "${CMAKE_INSTALL_PREFIX}/scripts" PARENT_SCOPE) + else() + set(${variable} "${CMAKE_INSTALL_PREFIX}/bin/scripts" PARENT_SCOPE) + endif() +endfunction() diff --git a/cmake/macros/FindBoost.cmake b/cmake/macros/FindBoost.cmake index 997336261d3..62da7fc4caf 100644 --- a/cmake/macros/FindBoost.cmake +++ b/cmake/macros/FindBoost.cmake @@ -478,6 +478,7 @@ else() # The user has not requested an exact version. Among known # versions, find those that are acceptable to the user request. set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS} + "1.61.0" "1.61" "1.60.0" "1.60" "1.59.0" "1.59" "1.58.0" "1.58" "1.57.0" "1.57" "1.56.0" "1.56" "1.55.0" "1.55" "1.54.0" "1.54" "1.53.0" "1.53" "1.52.0" "1.52" "1.51.0" "1.51" "1.50.0" "1.50" "1.49.0" "1.49" "1.48.0" "1.48" "1.47.0" "1.47" "1.46.1" diff --git a/cmake/macros/FindPCHSupport.cmake b/cmake/macros/FindPCHSupport.cmake index 6edc8e92890..9cc39a13b04 100644 --- a/cmake/macros/FindPCHSupport.cmake +++ b/cmake/macros/FindPCHSupport.cmake @@ -143,7 +143,7 @@ FUNCTION(ADD_CXX_PCH_XCODE TARGET_NAME_LIST PCH_HEADER PCH_SOURCE) ENDFUNCTION(ADD_CXX_PCH_XCODE) FUNCTION(ADD_CXX_PCH TARGET_NAME_LIST PCH_HEADER PCH_SOURCE) - IF (MSVC) + IF (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") ADD_CXX_PCH_MSVC("${TARGET_NAME_LIST}" ${PCH_HEADER} ${PCH_SOURCE}) ELSEIF ("${CMAKE_GENERATOR}" MATCHES "Xcode") ADD_CXX_PCH_XCODE("${TARGET_NAME_LIST}" ${PCH_HEADER} ${PCH_SOURCE}) diff --git a/cmake/options.cmake b/cmake/options.cmake index d49393ed745..085a45fa03f 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -9,10 +9,30 @@ # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. option(SERVERS "Build worldserver and authserver" 1) -option(SCRIPTS "Build core with scripts included" 1) +set(SCRIPTS "static" CACHE STRING "Build core with scripts") +set_property(CACHE SCRIPTS PROPERTY STRINGS none static dynamic minimal-static minimal-dynamic) + +# Build a list of all script modules when -DSCRIPT="custom" is selected +GetScriptModuleList(SCRIPT_MODULE_LIST) +foreach(SCRIPT_MODULE ${SCRIPT_MODULE_LIST}) + ScriptModuleNameToVariable(${SCRIPT_MODULE} SCRIPT_MODULE_VARIABLE) + set(${SCRIPT_MODULE_VARIABLE} "default" CACHE STRING "Build type of the ${SCRIPT_MODULE} module.") + set_property(CACHE ${SCRIPT_MODULE_VARIABLE} PROPERTY STRINGS default disabled static dynamic) +endforeach() + option(TOOLS "Build map/vmap/mmap extraction/assembler tools" 0) option(USE_SCRIPTPCH "Use precompiled headers when compiling scripts" 1) option(USE_COREPCH "Use precompiled headers when compiling servers" 1) +option(WITH_DYNAMIC_LINKING "Enable dynamic library linking." 0) +IsDynamicLinkingRequired(WITH_DYNAMIC_LINKING_FORCED) +if (WITH_DYNAMIC_LINKING AND WITH_DYNAMIC_LINKING_FORCED) + set(WITH_DYNAMIC_LINKING_FORCED OFF) +endif() +if (WITH_DYNAMIC_LINKING OR WITH_DYNAMIC_LINKING_FORCED) + set(BUILD_SHARED_LIBS ON) +else() + set(BUILD_SHARED_LIBS OFF) +endif() option(WITH_WARNINGS "Show all warnings during compile" 0) option(WITH_COREDEBUG "Include additional debug-code in core" 0) set(WITH_SOURCE_TREE "hierarchical" CACHE STRING "Build the source tree for IDE's.") diff --git a/cmake/platform/win/settings.cmake b/cmake/platform/win/settings.cmake index da66daf0832..0c1a103304a 100644 --- a/cmake/platform/win/settings.cmake +++ b/cmake/platform/win/settings.cmake @@ -1,20 +1,9 @@ -# check the CMake preload parameters (commented out by default) +add_definitions(-D_WIN32_WINNT=0x0601) -# overload CMAKE_INSTALL_PREFIX if not being set properly -#if( WIN32 ) -# if( NOT CYGWIN ) -# if( NOT CMAKE_INSTALL_PREFIX ) -# set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/bin") -# endif() -# endif() -#endif() - -if (WIN32) - add_definitions(-D_WIN32_WINNT=0x0601) -endif() - -if ( MSVC ) +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") include(${CMAKE_SOURCE_DIR}/cmake/compiler/msvc/settings.cmake) -elseif ( MINGW ) +elseif (CMAKE_CXX_PLATFORM_ID MATCHES "MinGW") include(${CMAKE_SOURCE_DIR}/cmake/compiler/mingw/settings.cmake) +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + include(${CMAKE_SOURCE_DIR}/cmake/compiler/clang/settings.cmake) endif() diff --git a/cmake/showoptions.cmake b/cmake/showoptions.cmake index 537544ba10e..9229590381a 100644 --- a/cmake/showoptions.cmake +++ b/cmake/showoptions.cmake @@ -23,9 +23,8 @@ else() message("* Build world/authserver : No") endif() -if( SCRIPTS ) - message("* Build with scripts : Yes (default)") - add_definitions(-DSCRIPTS) +if(SCRIPTS AND (NOT SCRIPTS STREQUAL "none")) + message("* Build with scripts : Yes (${SCRIPTS})") else() message("* Build with scripts : No") endif() @@ -70,7 +69,7 @@ else() endif() if( NOT WITH_SOURCE_TREE STREQUAL "no" ) - message("* Show source tree : Yes - \"${WITH_SOURCE_TREE}\"") + message("* Show source tree : Yes (${WITH_SOURCE_TREE})") else() message("* Show source tree : No") endif() @@ -87,7 +86,7 @@ if ( WITHOUT_GIT ) message(" *** version of git for the revision-hash to work, and be allowede to ask for") message(" *** support if needed.") else() - message("* Use GIT revision hash : Yes") + message("* Use GIT revision hash : Yes (default)") endif() if ( NOJEM ) @@ -113,5 +112,18 @@ if ( HELGRIND ) add_definitions(-DHELGRIND) endif() -message("") +if (BUILD_SHARED_LIBS) + message("") + message(" *** WITH_DYNAMIC_LINKING - INFO!") + message(" *** Will link against shared libraries!") + message(" *** Please note that this is an experimental feature!") + if (WITH_DYNAMIC_LINKING_FORCED) + message("") + message(" *** Dynamic linking was enforced through a dynamic script module!") + endif() + add_definitions(-DTRINITY_API_USE_DYNAMIC_LINKING) + + WarnAboutSpacesInBuildPath() +endif() +message("") |
