You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by yi...@apache.org on 2022/07/04 04:10:46 UTC

[arrow] branch master updated: ARROW-16886: [C++] Add option to disable PIC (#13475)

This is an automated email from the ASF dual-hosted git repository.

yibocai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 897a4c0ce7 ARROW-16886: [C++] Add option to disable PIC (#13475)
897a4c0ce7 is described below

commit 897a4c0ce73c3fe07872beee2c1d2128e44f6dd4
Author: Sutou Kouhei <ko...@clear-code.com>
AuthorDate: Mon Jul 4 13:10:38 2022 +0900

    ARROW-16886: [C++] Add option to disable PIC (#13475)
    
    It's for performance.
    
    See https://github.com/apache/arrow/issues/13367 for use case.
    
    Lead-authored-by: Sutou Kouhei <ko...@clear-code.com>
    Co-authored-by: Sutou Kouhei <ko...@cozmixng.org>
    Signed-off-by: Yibo Cai <yi...@arm.com>
---
 cpp/CMakeLists.txt                    | 6 ++++++
 cpp/cmake_modules/BuildUtils.cmake    | 5 +++--
 cpp/cmake_modules/DefineOptions.cmake | 3 +++
 cpp/cmake_modules/SetupCxxFlags.cmake | 2 +-
 4 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index 6fc9f1a95b..08f6fe35bc 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -194,6 +194,12 @@ endif()
 # cmake options
 include(DefineOptions)
 
+if(ARROW_BUILD_SHARED AND NOT ARROW_POSITION_INDEPENDENT_CODE)
+  message(WARNING "Can't disable position-independent code to build shared libraries, enabling"
+  )
+  set(ARROW_POSITION_INDEPENDENT_CODE ON)
+endif()
+
 # Needed for linting targets, etc.
 if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
   find_package(PythonInterp)
diff --git a/cpp/cmake_modules/BuildUtils.cmake b/cpp/cmake_modules/BuildUtils.cmake
index c2347ad681..5ce65ee51d 100644
--- a/cpp/cmake_modules/BuildUtils.cmake
+++ b/cpp/cmake_modules/BuildUtils.cmake
@@ -204,7 +204,8 @@ function(ADD_ARROW_LIB LIB_NAME)
 
   if(WIN32
      OR (CMAKE_GENERATOR STREQUAL Xcode)
-     OR CMAKE_VERSION VERSION_LESS 3.12)
+     OR CMAKE_VERSION VERSION_LESS 3.12
+     OR NOT ARROW_POSITION_INDEPENDENT_CODE)
     # We need to compile C++ separately for each library kind (shared and static)
     # because of dllexport declarations on Windows.
     # The Xcode generator doesn't reliably work with Xcode as target names are not
@@ -222,7 +223,7 @@ function(ADD_ARROW_LIB LIB_NAME)
     # that "objlib" into each library kind, to avoid compiling twice
     add_library(${LIB_NAME}_objlib OBJECT ${ARG_SOURCES})
     # Necessary to make static linking into other shared libraries work properly
-    set_property(TARGET ${LIB_NAME}_objlib PROPERTY POSITION_INDEPENDENT_CODE 1)
+    set_property(TARGET ${LIB_NAME}_objlib PROPERTY POSITION_INDEPENDENT_CODE ON)
     if(ARG_DEPENDENCIES)
       add_dependencies(${LIB_NAME}_objlib ${ARG_DEPENDENCIES})
     endif()
diff --git a/cpp/cmake_modules/DefineOptions.cmake b/cpp/cmake_modules/DefineOptions.cmake
index 8dc7d77ed4..d5590a95ee 100644
--- a/cpp/cmake_modules/DefineOptions.cmake
+++ b/cpp/cmake_modules/DefineOptions.cmake
@@ -109,6 +109,9 @@ if(ARROW_DEFINE_OPTIONS)
 
   define_option(ARROW_NO_DEPRECATED_API "Exclude deprecated APIs from build" OFF)
 
+  define_option(ARROW_POSITION_INDEPENDENT_CODE
+                "Whether to create position-independent target" ON)
+
   define_option(ARROW_USE_CCACHE "Use ccache when compiling (if available)" ON)
 
   define_option(ARROW_USE_LD_GOLD "Use ld.gold for linking on Linux (if available)" OFF)
diff --git a/cpp/cmake_modules/SetupCxxFlags.cmake b/cpp/cmake_modules/SetupCxxFlags.cmake
index 66b84dbc29..0a40ebe48a 100644
--- a/cpp/cmake_modules/SetupCxxFlags.cmake
+++ b/cpp/cmake_modules/SetupCxxFlags.cmake
@@ -131,7 +131,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
 
 # Build with -fPIC so that can static link our libraries into other people's
 # shared libraries
-set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+set(CMAKE_POSITION_INDEPENDENT_CODE ${ARROW_POSITION_INDEPENDENT_CODE})
 
 string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)