aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNaios <naios-dev@live.de>2016-03-20 00:50:21 +0100
committerNaios <naios-dev@live.de>2016-03-24 02:38:54 +0100
commit2613413608337d61994503df0e2d9ed05d3c4ee4 (patch)
treec560bb1832b8a9aa13837dd662bfb9fa514475f4
parentf37682b7edd0d711e1120cbdd9d627fb5b9dbde1 (diff)
Core/Build: Add the possibility to link libraries dynamically.
* makes it possible to access exported singletons from other shared lib's. * reduces binary size (cherry picked from commit f4e0945b13a70225684e7421d9542efae6a47c89)
-rw-r--r--.travis.yml7
-rw-r--r--CMakeLists.txt3
-rw-r--r--cmake/compiler/clang/settings.cmake13
-rw-r--r--cmake/compiler/gcc/settings.cmake12
-rw-r--r--cmake/compiler/msvc/settings.cmake7
-rw-r--r--cmake/options.cmake1
-rw-r--r--cmake/showoptions.cmake12
-rw-r--r--src/common/Define.h39
8 files changed, 88 insertions, 6 deletions
diff --git a/.travis.yml b/.travis.yml
index 7ed50ef0ec4..894fedf4da6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -21,7 +21,7 @@ install:
- mysql -uroot -e 'create database test_mysql;'
- mkdir bin
- cd bin
- - cmake ../ -DWITH_WARNINGS=1 -DWITH_COREDEBUG=0 -DUSE_COREPCH=1 -DUSE_SCRIPTPCH=1 -DTOOLS=1 -DSCRIPTS=1 -DSERVERS=1 -DNOJEM=1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror"
+ - cmake ../ -DWITH_WARNINGS=1 -DWITH_COREDEBUG=0 -DUSE_COREPCH=1 -DUSE_SCRIPTPCH=1 -DTOOLS=1 -DSCRIPTS=1 -DSERVERS=1 -DNOJEM=1 -DWITH_DYNAMIC_LINKING=1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror" -DCMAKE_INSTALL_PREFIX=check_install
- cd ..
- sudo chmod +x contrib/check_updates.sh
@@ -36,4 +36,7 @@ script:
- cat sql/updates/world/*.sql | mysql -utrinity -ptrinity world
- mysql -uroot < sql/create/drop_mysql.sql
- cd bin
- - make -j 10 -k
+ - make -j 8 -k && make install
+ - cd check_install/bin
+ - ./authserver --version
+ - ./worldserver --version
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 17d4e1f051d..dda8f242feb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,9 +24,6 @@ endif(POLICY CMP0043)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
-# build static libraries
-set(BUILD_SHARED_LIBS OFF)
-
# Set RPATH-handing (CMake parameters)
set(CMAKE_SKIP_BUILD_RPATH 0)
set(CMAKE_BUILD_WITH_INSTALL_RPATH 0)
diff --git a/cmake/compiler/clang/settings.cmake b/cmake/compiler/clang/settings.cmake
index 261a55b285f..9a8cb85275e 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 (WITH_DYNAMIC_LINKING)
+ # -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..d9eda767b8e 100644
--- a/cmake/compiler/gcc/settings.cmake
+++ b/cmake/compiler/gcc/settings.cmake
@@ -34,3 +34,15 @@ if( WITH_COREDEBUG )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
message(STATUS "GCC: Debug-flags set (-g3)")
endif()
+
+if (WITH_DYNAMIC_LINKING)
+ 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..994a5318ea4 100644
--- a/cmake/compiler/msvc/settings.cmake
+++ b/cmake/compiler/msvc/settings.cmake
@@ -74,6 +74,13 @@ if(NOT WITH_WARNINGS)
message(STATUS "MSVC: Disabled generic compiletime warnings")
endif()
+if (WITH_DYNAMIC_LINKING)
+ # 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/options.cmake b/cmake/options.cmake
index d49393ed745..62810b2d3f2 100644
--- a/cmake/options.cmake
+++ b/cmake/options.cmake
@@ -13,6 +13,7 @@ option(SCRIPTS "Build core with scripts included"
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)
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 537544ba10e..e6d709207b3 100644
--- a/cmake/showoptions.cmake
+++ b/cmake/showoptions.cmake
@@ -113,5 +113,15 @@ if ( HELGRIND )
add_definitions(-DHELGRIND)
endif()
-message("")
+if (WITH_DYNAMIC_LINKING)
+ message("")
+ message(" *** WITH_DYNAMIC_LINKING - INFO!")
+ message(" *** Will link against shared libraries!")
+ message(" *** Please note that this is an experimental feature!")
+ add_definitions(-DTRINITY_API_USE_DYNAMIC_LINKING)
+ set(BUILD_SHARED_LIBS ON)
+else()
+ set(BUILD_SHARED_LIBS OFF)
+endif()
+message("")
diff --git a/src/common/Define.h b/src/common/Define.h
index b34edb6a549..d03d26ad780 100644
--- a/src/common/Define.h
+++ b/src/common/Define.h
@@ -95,6 +95,45 @@
#endif
#endif //COMPILER == COMPILER_GNU
+#ifdef TRINITY_API_USE_DYNAMIC_LINKING
+# if COMPILER == COMPILER_MICROSOFT
+# define TC_API_EXPORT __declspec(dllexport)
+# define TC_API_IMPORT __declspec(dllimport)
+# elif COMPILER == COMPILER_GNU
+# define TC_API_EXPORT __attribute__((visibility("default")))
+# define TC_API_IMPORT
+# else
+# error compiler not supported!
+# endif
+#else
+# define TC_API_EXPORT
+# define TC_API_IMPORT
+#endif
+
+#ifdef TRINITY_API_EXPORT_COMMON
+# define TC_COMMON_API TC_API_EXPORT
+#else
+# define TC_COMMON_API TC_API_IMPORT
+#endif
+
+#ifdef TRINITY_API_EXPORT_DATABASE
+# define TC_DATABASE_API TC_API_EXPORT
+#else
+# define TC_DATABASE_API TC_API_IMPORT
+#endif
+
+#ifdef TRINITY_API_EXPORT_SHARED
+# define TC_SHARED_API TC_API_EXPORT
+#else
+# define TC_SHARED_API TC_API_IMPORT
+#endif
+
+#ifdef TRINITY_API_EXPORT_GAME
+# define TC_GAME_API TC_API_EXPORT
+#else
+# define TC_GAME_API TC_API_IMPORT
+#endif
+
#define UI64FMTD "%" PRIu64
#define UI64LIT(N) UINT64_C(N)