mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-28 08:06:23 +00:00
feat(Core/Build): add the possibility to link libraries dynamically (#5348)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user