diff options
Diffstat (limited to 'cmake/compiler')
-rw-r--r-- | cmake/compiler/clang/settings.cmake | 13 | ||||
-rw-r--r-- | cmake/compiler/gcc/settings.cmake | 12 | ||||
-rw-r--r-- | cmake/compiler/msvc/settings.cmake | 21 |
3 files changed, 39 insertions, 7 deletions
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 52c19b336cb..86470f327c5 100644 --- a/cmake/compiler/msvc/settings.cmake +++ b/cmake/compiler/msvc/settings.cmake @@ -18,11 +18,6 @@ if(PLATFORM EQUAL 64) add_definitions("-D_WIN64") message(STATUS "MSVC: 64-bit platform, enforced -D_WIN64 parameter") - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0.23026.0) - #Enable extended object support for debug compiles on X64 (not required on X86) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj") - message(STATUS "MSVC: Enabled increased number of sections in object files") - endif() else() # mark 32 bit executables large address aware so they can use > 2GB address space set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE") @@ -41,15 +36,20 @@ add_definitions(-D_BUILD_DIRECTIVE=\\"$(ConfigurationName)\\") # 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) + # Enable extended object support + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") + message(STATUS "MSVC: Enabled increased number of sections in object files") +endif() + # /Zc:throwingNew. # When you specify Zc:throwingNew on the command line, it instructs the compiler to assume # that the program will eventually be linked with a conforming operator new implementation, # and can omit all of these extra null checks from your program. # http://blogs.msdn.com/b/vcblog/archive/2015/08/06/new-in-vs-2015-zc-throwingnew.aspx if(NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0.23026.0)) - # also enable /bigobj for ALL builds under visual studio 2015, increased number of templates in standard library # makes this flag a requirement to build TC at all - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:throwingNew /bigobj") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:throwingNew") endif() # Define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES - eliminates the warning by changing the strcpy call to strcpy_s, which prevents buffer overruns @@ -75,6 +75,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*) |