From e756777c92adaed20998355b9008b57b8e70ff08 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B6rn=20Esser?= Date: Fri, 10 Apr 2020 14:42:03 +0200 Subject: [PATCH] CMake: Check whether BSYMBOLIC is supported by the linker. Linking with '-Bsymbolic-functions' is supported for ELF-binaries, only. --- .travis.yml | 6 +----- CMakeLists.txt | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3b533e8d..2d10f92a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -128,11 +128,7 @@ before_script: - set +e - mkdir -p build || echo "Failed to mkdir build" - cd build || echo "Failed to cd build" - - if [ "$TRAVIS_OS_NAME" = "osx" ]; then - cmake -DDISABLE_BSYMBOLIC=ON .. ; - else - cmake .. ; - fi || echo "Failed to run cmake" + - cmake .. || echo "Failed to run cmake" script: - make diff --git a/CMakeLists.txt b/CMakeLists.txt index a0f226c4..936331e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -270,7 +270,20 @@ if (NOT ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")) add_compile_options("-D_REENTRANT") endif() - if (DISABLE_BSYMBOLIC STREQUAL "OFF") + # OSX Mach-O doesn't support linking with '-Bsymbolic-functions'. + # Others may not support it, too. + list(APPEND CMAKE_REQUIRED_LIBRARIES "-Wl,-Bsymbolic-functions") + check_c_source_compiles( + [=[ + int main () + { + return 0; + } + ]=] + BSYMBOLIC_WORKS + ) + list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "-Wl,-Bsymbolic-functions") + if (DISABLE_BSYMBOLIC STREQUAL "OFF" AND BSYMBOLIC_WORKS) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-Bsymbolic-functions") # XXX need cmake>=3.13 for this: #add_link_options("-Wl,-Bsymbolic-functions") -- 2.39.5