summaryrefslogtreecommitdiff
path: root/src/cmake/macros
diff options
context:
space:
mode:
authorKargatum <dowlandtop@yandex.com>2021-04-22 03:16:12 +0700
committerGitHub <noreply@github.com>2021-04-21 22:16:12 +0200
commit325dcfc9a6c9a83f9e107a06e11b8280feda2a5d (patch)
tree70c246b197294f920a632057c250cb77645ab14a /src/cmake/macros
parent2c5cb29ad49063b7b0e4085f8624ab32786d382d (diff)
feat(Core/Build): add the possibility to link libraries dynamically (#5348)
Diffstat (limited to 'src/cmake/macros')
-rw-r--r--src/cmake/macros/ConfigureScripts.cmake108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/cmake/macros/ConfigureScripts.cmake b/src/cmake/macros/ConfigureScripts.cmake
new file mode 100644
index 0000000000..cefaa88377
--- /dev/null
+++ b/src/cmake/macros/ConfigureScripts.cmake
@@ -0,0 +1,108 @@
+#
+# Copyright (C) 2008-2019 TrinityCore <https://www.trinitycore.org/>
+# Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
+#
+# 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)
+ elseif(APPLE)
+ set(${variable} "lib${module}.dylib" 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()