From 1a1758beac0272c49bcfe8c7f404f3c945e6dd2a Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Sun, 1 Aug 2021 11:05:28 +0900 Subject: [PATCH] ARROW-13516: [C++] Detect --version-script flag availability Mingw-w64 + Clang (lld) doesn't support it. See also: https://github.com/msys2/MINGW-packages/pull/9255 --- cpp/CMakeLists.txt | 20 ++++++++++++++++++++ cpp/src/arrow/CMakeLists.txt | 5 +---- cpp/src/gandiva/CMakeLists.txt | 5 +---- cpp/src/gandiva/jni/CMakeLists.txt | 2 +- cpp/src/parquet/CMakeLists.txt | 5 +---- cpp/src/plasma/CMakeLists.txt | 5 +---- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 78b19ba59308..2bcdc0de1794 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -453,6 +453,26 @@ endif() include(SetupCxxFlags) +# +# Linker flags +# + +# Localize thirdparty symbols using a linker version script. This hides them +# from the client application. The OS X linker does not support the +# version-script option. +if(CMAKE_VERSION VERSION_LESS 3.18) + if(APPLE OR WIN32) + set(CXX_LINKER_SUPPORTS_VERSION_SCRIPT FALSE) + else() + set(CXX_LINKER_SUPPORTS_VERSION_SCRIPT TRUE) + endif() +else() + include(CheckLinkerFlag) + check_linker_flag(CXX + "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/arrow/symbols.map" + CXX_LINKER_SUPPORTS_VERSION_SCRIPT) +endif() + # # Build output directory # diff --git a/cpp/src/arrow/CMakeLists.txt b/cpp/src/arrow/CMakeLists.txt index cb6e91bd40e1..f13e5b1ef754 100644 --- a/cpp/src/arrow/CMakeLists.txt +++ b/cpp/src/arrow/CMakeLists.txt @@ -483,10 +483,7 @@ if(ARROW_ORC) list(APPEND ARROW_SRCS adapters/orc/adapter.cc adapters/orc/adapter_util.cc) endif() -if(NOT APPLE AND NOT MSVC_TOOLCHAIN) - # Localize thirdparty symbols using a linker version script. This hides them - # from the client application. The OS X linker does not support the - # version-script option. +if(CXX_LINKER_SUPPORTS_VERSION_SCRIPT) set(ARROW_VERSION_SCRIPT_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/symbols.map") set(ARROW_SHARED_LINK_FLAGS ${ARROW_VERSION_SCRIPT_FLAGS}) diff --git a/cpp/src/gandiva/CMakeLists.txt b/cpp/src/gandiva/CMakeLists.txt index 08f31ad95546..2da8bb680921 100644 --- a/cpp/src/gandiva/CMakeLists.txt +++ b/cpp/src/gandiva/CMakeLists.txt @@ -111,10 +111,7 @@ endif() # set(GANDIVA_SHARED_LINK_FLAGS "${GANDIVA_SHARED_LINK_FLAGS} /EXPORT:${SYMBOL}") # endforeach() # endif() -if(NOT APPLE AND NOT MSVC_TOOLCHAIN) - # Localize thirdparty symbols using a linker version script. This hides them - # from the client application. The OS X linker does not support the - # version-script option. +if(CXX_LINKER_SUPPORTS_VERSION_SCRIPT) set(GANDIVA_VERSION_SCRIPT_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/symbols.map") set(GANDIVA_SHARED_LINK_FLAGS diff --git a/cpp/src/gandiva/jni/CMakeLists.txt b/cpp/src/gandiva/jni/CMakeLists.txt index 04fd22eec9ab..046934141f6d 100644 --- a/cpp/src/gandiva/jni/CMakeLists.txt +++ b/cpp/src/gandiva/jni/CMakeLists.txt @@ -98,7 +98,7 @@ add_dependencies(gandiva ${GANDIVA_JNI_LIBRARIES}) if(ARROW_BUILD_SHARED) # filter out everything that is not needed for the jni bridge # statically linked stdc++ has conflicts with stdc++ loaded by other libraries. - if(NOT APPLE) + if(CXX_LINKER_SUPPORTS_VERSION_SCRIPT) set_target_properties(gandiva_jni_shared PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_SOURCE_DIR}/src/gandiva/jni/symbols.map" diff --git a/cpp/src/parquet/CMakeLists.txt b/cpp/src/parquet/CMakeLists.txt index a487760a03ea..ce4591325473 100644 --- a/cpp/src/parquet/CMakeLists.txt +++ b/cpp/src/parquet/CMakeLists.txt @@ -232,10 +232,7 @@ if(NOT PARQUET_MINIMAL_DEPENDENCY) endif(NOT PARQUET_MINIMAL_DEPENDENCY) -if(NOT APPLE AND NOT MSVC_TOOLCHAIN) - # Localize thirdparty symbols using a linker version script. This hides them - # from the client application. The OS X linker does not support the - # version-script option. +if(CXX_LINKER_SUPPORTS_VERSION_SCRIPT) set(PARQUET_SHARED_LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/symbols.map") endif() diff --git a/cpp/src/plasma/CMakeLists.txt b/cpp/src/plasma/CMakeLists.txt index a4e6e72b41b0..46603d6f85cc 100644 --- a/cpp/src/plasma/CMakeLists.txt +++ b/cpp/src/plasma/CMakeLists.txt @@ -61,10 +61,7 @@ if(ARROW_CUDA) add_definitions(-DPLASMA_CUDA) endif() -if(NOT APPLE AND NOT MSVC_TOOLCHAIN) - # Localize thirdparty symbols using a linker version script. This hides them - # from the client application. The OS X linker does not support the - # version-script option. +if(CXX_LINKER_SUPPORTS_VERSION_SCRIPT) set(PLASMA_SHARED_LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/symbols.map") endif()