mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2025-11-29 17:38:24 +08:00
feat(Core/Build): add the possibility to link libraries dynamically (#5348)
This commit is contained in:
@@ -39,6 +39,7 @@ list(APPEND CMAKE_MODULE_PATH
|
||||
|
||||
include(CheckCXXSourceRuns)
|
||||
include(CheckIncludeFiles)
|
||||
include(ConfigureScripts)
|
||||
|
||||
# some utils for cmake
|
||||
include(deps/drassil/cmake-utils/utils.cmake)
|
||||
|
||||
13
conf/dist/config.cmake
vendored
13
conf/dist/config.cmake
vendored
@@ -12,6 +12,19 @@ option(WITHOUT_GIT "Disable the GIT testing routines"
|
||||
option(ENABLE_EXTRAS "Set to 0 to disable extra features optimizing performances" 1)
|
||||
option(ENABLE_VMAP_CHECKS "Enable Checks relative to DisableMgr system on vmap" 1)
|
||||
option(ENABLE_EXTRA_LOGS "Enable extra log functions that can be CPU intensive" 0)
|
||||
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()
|
||||
|
||||
# Source tree in IDE
|
||||
set(WITH_SOURCE_TREE "hierarchical" CACHE STRING "Build the source tree for IDE's.")
|
||||
|
||||
@@ -8,6 +8,14 @@ target_compile_definitions(acore-compile-option-interface
|
||||
INTERFACE
|
||||
-D_BUILD_DIRECTIVE="${CMAKE_BUILD_TYPE}")
|
||||
|
||||
set(CLANG_EXPECTED_VERSION 6.0.0)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS CLANG_EXPECTED_VERSION)
|
||||
message(FATAL_ERROR "Clang: AzerothCore requires version ${CLANG_EXPECTED_VERSION} to build but found ${CMAKE_CXX_COMPILER_VERSION}")
|
||||
else()
|
||||
message(STATUS "Clang: Minimum version required is ${CLANG_EXPECTED_VERSION}, found ${CMAKE_CXX_COMPILER_VERSION} - ok!")
|
||||
endif()
|
||||
|
||||
# This tests for a bug in clang-7 that causes linkage to fail for 64-bit from_chars (in some configurations)
|
||||
# If the clang requirement is bumped to >= clang-8, you can remove this check, as well as
|
||||
# the associated ifdef block in src/common/Utilities/StringConvert.h
|
||||
@@ -59,6 +67,20 @@ target_compile_options(acore-compile-option-interface
|
||||
-Wno-narrowing
|
||||
-Wno-deprecated-register)
|
||||
|
||||
target_compile_definitions(acore-compile-option-interface
|
||||
INTERFACE
|
||||
-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.
|
||||
target_compile_options(acore-compile-option-interface
|
||||
INTERFACE
|
||||
-fPIC)
|
||||
|
||||
target_compile_options(acore-hidden-symbols-interface
|
||||
INTERFACE
|
||||
-fvisibility=hidden)
|
||||
|
||||
# --no-undefined to throw errors when there are undefined symbols
|
||||
# (caused through missing WARHEAD_*_API macros).
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --no-undefined")
|
||||
|
||||
message(STATUS "Clang: Disallow undefined symbols")
|
||||
endif()
|
||||
|
||||
@@ -8,10 +8,12 @@ target_compile_definitions(acore-compile-option-interface
|
||||
INTERFACE
|
||||
-D_BUILD_DIRECTIVE="${CMAKE_BUILD_TYPE}")
|
||||
|
||||
set(GCC_EXPECTED_VERSION 4.8.2)
|
||||
set(GCC_EXPECTED_VERSION 7.0.0)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS GCC_EXPECTED_VERSION)
|
||||
message(FATAL_ERROR "GCC: This project requires version ${GCC_EXPECTED_VERSION} to build but found ${CMAKE_CXX_COMPILER_VERSION}")
|
||||
else()
|
||||
message(STATUS "GCC: Minimum version required is ${GCC_EXPECTED_VERSION}, found ${CMAKE_CXX_COMPILER_VERSION} - ok!")
|
||||
endif()
|
||||
|
||||
if(PLATFORM EQUAL 32)
|
||||
@@ -47,3 +49,21 @@ if( WITH_COREDEBUG )
|
||||
-g3)
|
||||
message(STATUS "GCC: Debug-flags set (-g3)")
|
||||
endif()
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
target_compile_options(acore-compile-option-interface
|
||||
INTERFACE
|
||||
-fPIC
|
||||
-Wno-attributes)
|
||||
|
||||
target_compile_options(acore-hidden-symbols-interface
|
||||
INTERFACE
|
||||
-fvisibility=hidden)
|
||||
|
||||
# Should break the build when there are WARHEAD_*_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()
|
||||
|
||||
@@ -6,9 +6,14 @@
|
||||
# set up output paths for executable binaries (.exe-files, and .dll-files on DLL-capable platforms)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
# set up output paths ofr static libraries etc (commented out - shown here as an example only)
|
||||
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
set(MSVC_EXPECTED_VERSION 19.24)
|
||||
set(MSVC_EXPECTED_VERSION_STRING "Microsoft Visual Studio 2019 16.4")
|
||||
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS MSVC_EXPECTED_VERSION)
|
||||
message(FATAL_ERROR "MSVC: AzerothCore requires version ${MSVC_EXPECTED_VERSION} (${MSVC_EXPECTED_VERSION_STRING}) to build but found ${CMAKE_CXX_COMPILER_VERSION}")
|
||||
else()
|
||||
message(STATUS "MSVC: Minimum version required is ${MSVC_EXPECTED_VERSION}, found ${CMAKE_CXX_COMPILER_VERSION} - ok!")
|
||||
endif()
|
||||
|
||||
# CMake sets warning flags by default, however we manage it manually
|
||||
# for different core and dependency targets
|
||||
@@ -106,6 +111,14 @@ if(NOT WITH_WARNINGS)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Ignore specific warnings
|
||||
# C4351: new behavior: elements of array 'x' will be default initialized
|
||||
# C4091: 'typedef ': ignored on left of '' when no variable is declared
|
||||
target_compile_options(acore-compile-option-interface
|
||||
INTERFACE
|
||||
/wd4351
|
||||
/wd4091)
|
||||
|
||||
# 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*)
|
||||
@@ -119,3 +132,26 @@ target_compile_options(acore-warning-interface
|
||||
INTERFACE
|
||||
/we4263
|
||||
/we4264)
|
||||
|
||||
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 '...'
|
||||
target_compile_options(acore-compile-option-interface
|
||||
INTERFACE
|
||||
/wd4251
|
||||
/wd4275)
|
||||
|
||||
message(STATUS "MSVC: Enabled shared linking")
|
||||
endif()
|
||||
|
||||
# Disable incremental linking in debug builds.
|
||||
# To prevent linking getting stuck (which might be fixed in a later VS version).
|
||||
macro(DisableIncrementalLinking variable)
|
||||
string(REGEX REPLACE "/INCREMENTAL *" "" ${variable} "${${variable}}")
|
||||
set(${variable} "${${variable}} /INCREMENTAL:NO")
|
||||
endmacro()
|
||||
|
||||
DisableIncrementalLinking(CMAKE_EXE_LINKER_FLAGS_DEBUG)
|
||||
DisableIncrementalLinking(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO)
|
||||
DisableIncrementalLinking(CMAKE_SHARED_LINKER_FLAGS_DEBUG)
|
||||
DisableIncrementalLinking(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO)
|
||||
|
||||
108
src/cmake/macros/ConfigureScripts.cmake
Normal file
108
src/cmake/macros/ConfigureScripts.cmake
Normal file
@@ -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()
|
||||
@@ -134,7 +134,7 @@ else()
|
||||
message("* Enable extra logging functions : No (default)")
|
||||
endif()
|
||||
|
||||
if(WIN32 AND NOT CMAKE_VERSION VERSION_LESS 2.8.12)
|
||||
if(WIN32)
|
||||
if(NOT WITH_SOURCE_TREE STREQUAL "no")
|
||||
message("* Show source tree : Yes - \"${WITH_SOURCE_TREE}\"")
|
||||
else()
|
||||
@@ -144,4 +144,18 @@ else()
|
||||
message("* Show source tree : No (For UNIX default)")
|
||||
endif()
|
||||
|
||||
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(-DACORE_API_USE_DYNAMIC_LINKING)
|
||||
|
||||
WarnAboutSpacesInBuildPath()
|
||||
endif()
|
||||
|
||||
message("")
|
||||
|
||||
@@ -64,6 +64,45 @@
|
||||
# define ATTR_DEPRECATED
|
||||
#endif //AC_COMPILER == AC_COMPILER_GNU
|
||||
|
||||
#ifdef ACORE_API_USE_DYNAMIC_LINKING
|
||||
# if AC_COMPILER == AC_COMPILER_MICROSOFT
|
||||
# define AC_API_EXPORT __declspec(dllexport)
|
||||
# define AC_API_IMPORT __declspec(dllimport)
|
||||
# elif AC_COMPILER == AC_COMPILER_GNU
|
||||
# define AC_API_EXPORT __attribute__((visibility("default")))
|
||||
# define AC_API_IMPORT
|
||||
# else
|
||||
# error compiler not supported!
|
||||
# endif
|
||||
#else
|
||||
# define AC_API_EXPORT
|
||||
# define AC_API_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef ACORE_API_EXPORT_COMMON
|
||||
# define AC_COMMON_API AC_API_EXPORT
|
||||
#else
|
||||
# define AC_COMMON_API AC_API_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef ACORE_API_EXPORT_DATABASE
|
||||
# define AC_DATABASE_API AC_API_EXPORT
|
||||
#else
|
||||
# define AC_DATABASE_API AC_API_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef ACORE_API_EXPORT_SHARED
|
||||
# define AC_SHARED_API AC_API_EXPORT
|
||||
#else
|
||||
# define AC_SHARED_API AC_API_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef ACORE_API_EXPORT_GAME
|
||||
# define AC_GAME_API AC_API_EXPORT
|
||||
#else
|
||||
# define AC_GAME_API AC_API_IMPORT
|
||||
#endif
|
||||
|
||||
#define UI64FMTD "%" PRIu64
|
||||
#define UI64LIT(N) UINT64_C(N)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user