diff options
author | Aleix Pol <aleixpol@kde.org> | 2021-06-29 18:59:09 +0200 |
---|---|---|
committer | Aleix Pol <aleixpol@kde.org> | 2021-07-12 02:07:39 +0200 |
commit | 730eb66eaf705eb6b0c2b31821f50bcd5b4a2a35 (patch) | |
tree | e5658fadef8165d143bb26ed52aaad136d384c3d | |
parent | 2cdf59e8ccb1fb11633324a4a2804503eec11de3 (diff) | |
download | extra-cmake-modules-730eb66eaf705eb6b0c2b31821f50bcd5b4a2a35.tar.gz extra-cmake-modules-730eb66eaf705eb6b0c2b31821f50bcd5b4a2a35.tar.bz2 |
Enable the usage of -Bsymbolic-functions
Checks if the compiler supports it and if so it enables it by default.
This is useful as it allows to perform internal linking operations at
build time that otherwise would have been delayed until process startup
time.
-rw-r--r-- | kde-modules/KDECompilerSettings.cmake | 26 | ||||
-rw-r--r-- | kde-modules/KDEFrameworkCompilerSettings.cmake | 1 |
2 files changed, 26 insertions, 1 deletions
diff --git a/kde-modules/KDECompilerSettings.cmake b/kde-modules/KDECompilerSettings.cmake index 1c3b3715..872edf18 100644 --- a/kde-modules/KDECompilerSettings.cmake +++ b/kde-modules/KDECompilerSettings.cmake @@ -135,7 +135,6 @@ on a target that has source files in a language other than C++. Enables exceptions for C++ source files compiled for the CMakeLists.txt file in the current directory and all subdirectories. - Example usages: .. code-block:: cmake @@ -184,6 +183,19 @@ Example usages: -DQT_NO_FOREACH ) +Inclusion of this module defines the following variables: + +``ENABLE_BSYMBOLICFUNCTIONS`` + indicates whether we make use of -Bsymbolic-functions for linking. + It ensures libraries bind global function references locally rather than + at runtime. + This option only has an effect on ELF-based systems. + + The option is disabled by default except when using + KDEFrameworkCompilerSettings.cmake where it's enabled. Projects can enable + it by calling set(ENABLE_BSYMBOLICFUNCTIONS ON) or passing -DENABLE + BSYMBOLICFUNCTIONS=ON when configuring the build directory. + Since pre-1.0.0. #]=======================================================================] @@ -584,6 +596,18 @@ if (MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4661") endif() +option(ENABLE_BSYMBOLICFUNCTIONS "Make use of -Bsymbolic-functions" OFF) +if (ENABLE_BSYMBOLICFUNCTIONS) + set(_SYMBOLIC_FUNCTIONS_COMPILER_OPTION "-Wl,-Bsymbolic-functions") + list(APPEND CMAKE_REQUIRED_LIBRARIES "${_SYMBOLIC_FUNCTIONS_COMPILER_OPTION}") + check_cxx_source_compiles( "int main () { return 0; }" BSYMBOLICFUNCTIONS_AVAILABLE ) + list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "${_SYMBOLIC_FUNCTIONS_COMPILER_OPTION}") + if (BSYMBOLICFUNCTIONS_AVAILABLE) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${_SYMBOLIC_FUNCTIONS_COMPILER_OPTION}") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${_SYMBOLIC_FUNCTIONS_COMPILER_OPTION}") + endif() +endif() + if (WIN32) # Disable deprecation warnings for some API # FIXME: do we really want this? diff --git a/kde-modules/KDEFrameworkCompilerSettings.cmake b/kde-modules/KDEFrameworkCompilerSettings.cmake index d7165f57..6b17fde9 100644 --- a/kde-modules/KDEFrameworkCompilerSettings.cmake +++ b/kde-modules/KDEFrameworkCompilerSettings.cmake @@ -38,6 +38,7 @@ if (NOT CMAKE_CXX_STANDARD) endif() set(KDE_COMPILERSETTINGS_LEVEL 5.84.0) +set(ENABLE_BSYMBOLICFUNCTIONS ON) include(KDECompilerSettings NO_POLICY_SCOPE) add_definitions(-DQT_NO_CAST_TO_ASCII |