diff options
author | Naios <naios-dev@live.de> | 2016-03-24 18:19:56 +0100 |
---|---|---|
committer | Naios <naios-dev@live.de> | 2016-04-11 21:41:58 +0200 |
commit | 8660f90bdfaeb33afd9bf63988b30d7783a527cc (patch) | |
tree | bd1fc4c09ecf2eeac7667c8018f9c9dfc5d1b8b4 /cmake | |
parent | c5c922da9f73e51bfbbb9a1450ed492741aae0a5 (diff) |
Core/Scripts: Split script subdirectories into independent modules
* Makes it possible to define the linkage for every module
* Move the ScriptPCH into the root directory
* Changes the SCRIPTS cmake variable to a string type:
-> -DSCRIPTS=0 is -DSCRIPTS="minimal-static" now
(builds commands and spells statically)
-> -DSCRIPTS=1 is -DSCRIPTS="static" now
(builds all modules statically)
-> -DSCRIPTS="dynamic"
(builds all modules dynamically)
-> Also the default value which is provided by the SCRIPTS
variable is overwriteable through the SCRIPTS_COMMANDS,
SCRIPTS_SPELLS... variable.
(cherry picked from commit 848b8a4136a4b395bfab74899520c74812d7f08e)
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/compiler/clang/settings.cmake | 2 | ||||
-rw-r--r-- | cmake/compiler/gcc/settings.cmake | 2 | ||||
-rw-r--r-- | cmake/compiler/msvc/settings.cmake | 4 | ||||
-rw-r--r-- | cmake/macros/ConfigureScripts.cmake | 83 | ||||
-rw-r--r-- | cmake/options.cmake | 21 | ||||
-rw-r--r-- | cmake/showoptions.cmake | 18 |
6 files changed, 116 insertions, 14 deletions
diff --git a/cmake/compiler/clang/settings.cmake b/cmake/compiler/clang/settings.cmake index 9a8cb85275e..1cd95bbf703 100644 --- a/cmake/compiler/clang/settings.cmake +++ b/cmake/compiler/clang/settings.cmake @@ -19,7 +19,7 @@ endif() 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 (WITH_DYNAMIC_LINKING) +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") diff --git a/cmake/compiler/gcc/settings.cmake b/cmake/compiler/gcc/settings.cmake index d9eda767b8e..c4f97f4ffd4 100644 --- a/cmake/compiler/gcc/settings.cmake +++ b/cmake/compiler/gcc/settings.cmake @@ -35,7 +35,7 @@ if( WITH_COREDEBUG ) message(STATUS "GCC: Debug-flags set (-g3)") endif() -if (WITH_DYNAMIC_LINKING) +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") diff --git a/cmake/compiler/msvc/settings.cmake b/cmake/compiler/msvc/settings.cmake index 336ed84c8ed..afde70b0f79 100644 --- a/cmake/compiler/msvc/settings.cmake +++ b/cmake/compiler/msvc/settings.cmake @@ -42,7 +42,7 @@ 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 WITH_DYNAMIC_LINKING) +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") @@ -80,7 +80,7 @@ if(NOT WITH_WARNINGS) message(STATUS "MSVC: Disabled generic compiletime warnings") endif() -if (WITH_DYNAMIC_LINKING) +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") diff --git a/cmake/macros/ConfigureScripts.cmake b/cmake/macros/ConfigureScripts.cmake new file mode 100644 index 00000000000..c783cc98ab7 --- /dev/null +++ b/cmake/macros/ConfigureScripts.cmake @@ -0,0 +1,83 @@ +# 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. + +# 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) + GetPathToScriptModule("" 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 absolut path of the given module in the variable +function(GetPathToScriptModule module variable) + set(${variable} "${CMAKE_SOURCE_DIR}/src/server/scripts/${module}" 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/options.cmake b/cmake/options.cmake index 62810b2d3f2..085a45fa03f 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -9,11 +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/showoptions.cmake b/cmake/showoptions.cmake index e6d709207b3..0739e74ac6a 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,15 +112,16 @@ if ( HELGRIND ) add_definitions(-DHELGRIND) endif() -if (WITH_DYNAMIC_LINKING) +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) - set(BUILD_SHARED_LIBS ON) -else() - set(BUILD_SHARED_LIBS OFF) endif() message("") |