arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject arrow git commit: ARROW-330: CMake functions to simplify shared / static library configuration
Date Wed, 28 Dec 2016 15:54:42 GMT
Repository: arrow
Updated Branches:
  refs/heads/master cfbdb6800 -> 8aab00ee1


ARROW-330: CMake functions to simplify shared / static library configuration

This also fixes ARROW-303

Author: Uwe L. Korn <uwelk@xhochy.com>

Closes #255 from xhochy/ARROW-330 and squashes the following commits:

a495d16 [Uwe L. Korn] Fix linking order
17131c9 [Uwe L. Korn] ARROW-330: CMake functions to simplify shared / static library configuration


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/8aab00ee
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/8aab00ee
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/8aab00ee

Branch: refs/heads/master
Commit: 8aab00ee16d9dfe7ed578c8dbe59761eaa68670f
Parents: cfbdb68
Author: Uwe L. Korn <uwelk@xhochy.com>
Authored: Wed Dec 28 10:54:27 2016 -0500
Committer: Wes McKinney <wes.mckinney@twosigma.com>
Committed: Wed Dec 28 10:54:27 2016 -0500

----------------------------------------------------------------------
 cpp/CMakeLists.txt                 | 54 ++----------------
 cpp/cmake_modules/BuildUtils.cmake | 77 ++++++++++++++++++++++++++
 cpp/src/arrow/io/CMakeLists.txt    | 97 +++++++++++++++++----------------
 cpp/src/arrow/io/memory.h          |  2 +-
 cpp/src/arrow/ipc/CMakeLists.txt   | 67 ++++++++++-------------
 5 files changed, 164 insertions(+), 133 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/8aab00ee/cpp/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index 47b7671..bf30543 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -717,61 +717,19 @@ set(ARROW_SRCS
   src/arrow/util/bit-util.cc
 )
 
-add_library(arrow_objlib OBJECT
-  ${ARROW_SRCS}
-)
-
-# Necessary to make static linking into other shared libraries work properly
-set_property(TARGET arrow_objlib PROPERTY POSITION_INDEPENDENT_CODE 1)
-
 if(NOT APPLE)
   # 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.
-  set(SHARED_LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/arrow/symbols.map")
-endif()
-
-if (ARROW_BUILD_SHARED)
-  add_library(arrow_shared SHARED $<TARGET_OBJECTS:arrow_objlib>)
-  if(APPLE)
-    set_target_properties(arrow_shared PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
-  endif()
-  set_target_properties(arrow_shared
-    PROPERTIES
-    LIBRARY_OUTPUT_DIRECTORY "${BUILD_OUTPUT_ROOT_DIRECTORY}"
-    LINK_FLAGS "${SHARED_LINK_FLAGS}"
-    OUTPUT_NAME "arrow")
-  target_link_libraries(arrow_shared
-    LINK_PUBLIC ${ARROW_LINK_LIBS}
-    LINK_PRIVATE ${ARROW_PRIVATE_LINK_LIBS})
-
-  install(TARGETS arrow_shared
-    LIBRARY DESTINATION lib
-    ARCHIVE DESTINATION lib)
+  set(ARROW_SHARED_LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/arrow/symbols.map")
 endif()
 
-if (ARROW_BUILD_STATIC)
-  add_library(arrow_static STATIC $<TARGET_OBJECTS:arrow_objlib>)
-  set_target_properties(arrow_static
-    PROPERTIES
-    LIBRARY_OUTPUT_DIRECTORY "${BUILD_OUTPUT_ROOT_DIRECTORY}"
-    OUTPUT_NAME "arrow")
+include(BuildUtils)
 
-  target_link_libraries(arrow_static
-    LINK_PUBLIC ${ARROW_LINK_LIBS}
-    LINK_PRIVATE ${ARROW_PRIVATE_LINK_LIBS})
-
-  install(TARGETS arrow_static
-    LIBRARY DESTINATION lib
-    ARCHIVE DESTINATION lib)
-endif()
-
-if (APPLE)
-  set_target_properties(arrow_shared
-    PROPERTIES
-    BUILD_WITH_INSTALL_RPATH ON
-    INSTALL_NAME_DIR "@rpath")
-endif()
+ADD_ARROW_LIB(arrow
+    SOURCES ${ARROW_SRCS}
+    SHARED_LINK_FLAGS ${ARROW_SHARED_LINK_FLAGS}
+)
 
 add_subdirectory(src/arrow)
 add_subdirectory(src/arrow/io)

http://git-wip-us.apache.org/repos/asf/arrow/blob/8aab00ee/cpp/cmake_modules/BuildUtils.cmake
----------------------------------------------------------------------
diff --git a/cpp/cmake_modules/BuildUtils.cmake b/cpp/cmake_modules/BuildUtils.cmake
new file mode 100644
index 0000000..b620de5
--- /dev/null
+++ b/cpp/cmake_modules/BuildUtils.cmake
@@ -0,0 +1,77 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+function(ADD_ARROW_LIB LIB_NAME)
+  set(options)
+  set(one_value_args SHARED_LINK_FLAGS)
+  set(multi_value_args SOURCES STATIC_LINK_LIBS STATIC_PRIVATE_LINK_LIBS SHARED_LINK_LIBS
SHARED_PRIVATE_LINK_LIBS)
+  cmake_parse_arguments(ARG "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
+  if(ARG_UNPARSED_ARGUMENTS)
+    message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}")
+  endif()
+
+  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)
+
+  if (ARROW_BUILD_SHARED)
+    add_library(${LIB_NAME}_shared SHARED $<TARGET_OBJECTS:${LIB_NAME}_objlib>)
+    if(APPLE)
+      set_target_properties(${LIB_NAME}_shared PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
+    endif()
+    set_target_properties(${LIB_NAME}_shared
+      PROPERTIES
+      LIBRARY_OUTPUT_DIRECTORY "${BUILD_OUTPUT_ROOT_DIRECTORY}"
+      LINK_FLAGS "${ARG_SHARED_LINK_FLAGS}"
+      OUTPUT_NAME ${LIB_NAME})
+  target_link_libraries(${LIB_NAME}_shared
+      LINK_PUBLIC ${ARG_SHARED_LINK_LIBS}
+      LINK_PRIVATE ${ARG_SHARED_PRIVATE_LINK_LIBS})
+  
+  install(TARGETS ${LIB_NAME}_shared
+      LIBRARY DESTINATION lib
+      ARCHIVE DESTINATION lib)
+  endif()
+  
+  if (ARROW_BUILD_STATIC)
+      add_library(${LIB_NAME}_static STATIC $<TARGET_OBJECTS:${LIB_NAME}_objlib>)
+    set_target_properties(${LIB_NAME}_static
+      PROPERTIES
+      LIBRARY_OUTPUT_DIRECTORY "${BUILD_OUTPUT_ROOT_DIRECTORY}"
+      OUTPUT_NAME ${LIB_NAME})
+  
+  target_link_libraries(${LIB_NAME}_static
+      LINK_PUBLIC ${ARG_STATIC_LINK_LIBS}
+      LINK_PRIVATE ${ARG_STATIC_PRIVATE_LINK_LIBS})
+  
+  install(TARGETS ${LIB_NAME}_static
+      LIBRARY DESTINATION lib
+      ARCHIVE DESTINATION lib)
+  endif()
+  
+  if (APPLE)
+      set_target_properties(${LIB_NAME}_shared
+      PROPERTIES
+      BUILD_WITH_INSTALL_RPATH ON
+      INSTALL_NAME_DIR "@rpath")
+  endif()
+
+endfunction()
+

http://git-wip-us.apache.org/repos/asf/arrow/blob/8aab00ee/cpp/src/arrow/io/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/io/CMakeLists.txt b/cpp/src/arrow/io/CMakeLists.txt
index 1e65a1a..b8882e4 100644
--- a/cpp/src/arrow/io/CMakeLists.txt
+++ b/cpp/src/arrow/io/CMakeLists.txt
@@ -18,30 +18,65 @@
 # ----------------------------------------------------------------------
 # arrow_io : Arrow IO interfaces
 
+# HDFS thirdparty setup
+if (DEFINED ENV{HADOOP_HOME})
+  set(HADOOP_HOME $ENV{HADOOP_HOME})
+  if (NOT EXISTS "${HADOOP_HOME}/include/hdfs.h")
+    message(STATUS "Did not find hdfs.h in expected location, using vendored one")
+    set(HADOOP_HOME "${THIRDPARTY_DIR}/hadoop")
+  endif()
+else()
+  set(HADOOP_HOME "${THIRDPARTY_DIR}/hadoop")
+endif()
+
+set(HDFS_H_PATH "${HADOOP_HOME}/include/hdfs.h")
+if (NOT EXISTS ${HDFS_H_PATH})
+  message(FATAL_ERROR "Did not find hdfs.h at ${HDFS_H_PATH}")
+endif()
+message(STATUS "Found hdfs.h at: " ${HDFS_H_PATH})
+
+include_directories(SYSTEM "${HADOOP_HOME}/include")
+
+# arrow_io library
 if (MSVC)
-  set(ARROW_IO_LINK_LIBS
+  set(ARROW_IO_STATIC_LINK_LIBS
+    arrow_static
+  )
+  set(ARROW_IO_SHARED_LINK_LIBS
     arrow_shared
   )
 else()
-  set(ARROW_IO_LINK_LIBS
+  set(ARROW_IO_STATIC_LINK_LIBS
+    arrow_static
+    dl
+  )
+  set(ARROW_IO_SHARED_LINK_LIBS
     arrow_shared
     dl
   )
 endif()
 
 if (ARROW_BOOST_USE_SHARED)
-  set(ARROW_IO_PRIVATE_LINK_LIBS
+  set(ARROW_IO_SHARED_PRIVATE_LINK_LIBS
     boost_system_shared
     boost_filesystem_shared)
 else()
-  set(ARROW_IO_PRIVATE_LINK_LIBS
+  set(ARROW_IO_SHARED_PRIVATE_LINK_LIBS
     boost_system_static
     boost_filesystem_static)
 endif()
 
-set(ARROW_IO_TEST_LINK_LIBS
-  arrow_io
-  ${ARROW_IO_PRIVATE_LINK_LIBS})
+set(ARROW_IO_STATIC_PRIVATE_LINK_LIBS
+  boost_system_static
+  boost_filesystem_static)
+
+if (ARROW_BUILD_STATIC)
+  set(ARROW_IO_TEST_LINK_LIBS
+    arrow_io_static)
+else()
+  set(ARROW_IO_TEST_LINK_LIBS
+    arrow_io_shared)
+endif()
 
 set(ARROW_IO_SRCS
   file.cc
@@ -51,32 +86,6 @@ set(ARROW_IO_SRCS
   memory.cc
 )
 
-# HDFS thirdparty setup
-if (DEFINED ENV{HADOOP_HOME})
-  set(HADOOP_HOME $ENV{HADOOP_HOME})
-  if (NOT EXISTS "${HADOOP_HOME}/include/hdfs.h")
-    message(STATUS "Did not find hdfs.h in expected location, using vendored one")
-    set(HADOOP_HOME "${THIRDPARTY_DIR}/hadoop")
-  endif()
-else()
-  set(HADOOP_HOME "${THIRDPARTY_DIR}/hadoop")
-endif()
-
-set(HDFS_H_PATH "${HADOOP_HOME}/include/hdfs.h")
-if (NOT EXISTS ${HDFS_H_PATH})
-  message(FATAL_ERROR "Did not find hdfs.h at ${HDFS_H_PATH}")
-endif()
-message(STATUS "Found hdfs.h at: " ${HDFS_H_PATH})
-
-include_directories(SYSTEM "${HADOOP_HOME}/include")
-
-add_library(arrow_io SHARED
-  ${ARROW_IO_SRCS}
-)
-target_link_libraries(arrow_io
-  LINK_PUBLIC ${ARROW_IO_LINK_LIBS}
-  LINK_PRIVATE ${ARROW_IO_PRIVATE_LINK_LIBS})
-
 if(NOT APPLE)
   # Localize thirdparty symbols using a linker version script. This hides them
   # from the client application. The OS X linker does not support the
@@ -84,16 +93,14 @@ if(NOT APPLE)
   set(ARROW_IO_LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/symbols.map")
 endif()
 
-SET_TARGET_PROPERTIES(arrow_io PROPERTIES
-  LINKER_LANGUAGE CXX
-  LINK_FLAGS "${ARROW_IO_LINK_FLAGS}")
-
-if (APPLE)
-  set_target_properties(arrow_io
-    PROPERTIES
-    BUILD_WITH_INSTALL_RPATH ON
-    INSTALL_NAME_DIR "@rpath")
-endif()
+ADD_ARROW_LIB(arrow_io
+  SOURCES ${ARROW_IO_SRCS}
+  SHARED_LINK_FLAGS ${ARROW_IO_LINK_FLAGS}
+  SHARED_LINK_LIBS ${ARROW_IO_SHARED_LINK_LIBS}
+  SHARED_PRIVATE_LINK_LIBS ${ARROW_IO_SHARED_PRIVATE_LINK_LIBS}
+  STATIC_LINK_LIBS ${ARROW_IO_STATIC_LINK_LIBS}
+  STATIC_PRIVATE_LINK_LIBS ${ARROW_IO_STATIC_PRIVATE_LINK_LIBS}
+)
 
 ADD_ARROW_TEST(io-file-test)
 ARROW_TEST_LINK_LIBRARIES(io-file-test
@@ -115,10 +122,6 @@ install(FILES
   memory.h
   DESTINATION include/arrow/io)
 
-install(TARGETS arrow_io
-  LIBRARY DESTINATION lib
-  ARCHIVE DESTINATION lib)
-
 # pkg-config support
 configure_file(arrow-io.pc.in
   "${CMAKE_CURRENT_BINARY_DIR}/arrow-io.pc"

http://git-wip-us.apache.org/repos/asf/arrow/blob/8aab00ee/cpp/src/arrow/io/memory.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/io/memory.h b/cpp/src/arrow/io/memory.h
index b72f93b..2faf280 100644
--- a/cpp/src/arrow/io/memory.h
+++ b/cpp/src/arrow/io/memory.h
@@ -101,7 +101,7 @@ class ARROW_EXPORT BufferReader : public ReadableFileInterface {
  public:
   explicit BufferReader(const std::shared_ptr<Buffer>& buffer);
   BufferReader(const uint8_t* data, int64_t size);
-  ~BufferReader();
+  virtual ~BufferReader();
 
   Status Close() override;
   Status Tell(int64_t* position) override;

http://git-wip-us.apache.org/repos/asf/arrow/blob/8aab00ee/cpp/src/arrow/ipc/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/ipc/CMakeLists.txt b/cpp/src/arrow/ipc/CMakeLists.txt
index d3e625a..11ca191 100644
--- a/cpp/src/arrow/ipc/CMakeLists.txt
+++ b/cpp/src/arrow/ipc/CMakeLists.txt
@@ -19,17 +19,25 @@
 # arrow_ipc
 #######################################
 
-set(ARROW_IPC_LINK_LIBS
-  arrow_io
+set(ARROW_IPC_SHARED_LINK_LIBS
+  arrow_io_shared
   arrow_shared
 )
 
-set(ARROW_IPC_PRIVATE_LINK_LIBS
-  )
+set(ARROW_IPC_STATIC_LINK_LIBS
+  arrow_static
+  arrow_io_static
+)
 
-set(ARROW_IPC_TEST_LINK_LIBS
-  arrow_ipc
-  ${ARROW_IPC_PRIVATE_LINK_LIBS})
+if (ARROW_BUILD_STATIC)
+  set(ARROW_IPC_TEST_LINK_LIBS
+    arrow_io_static
+    arrow_ipc_static)
+else()
+  set(ARROW_IPC_TEST_LINK_LIBS
+    arrow_io_shared
+    arrow_ipc_shared)
+endif()
 
 set(ARROW_IPC_SRCS
   adapter.cc
@@ -40,20 +48,6 @@ set(ARROW_IPC_SRCS
   metadata-internal.cc
 )
 
-# TODO(wesm): SHARED and STATIC targets
-add_library(arrow_ipc SHARED
-  ${ARROW_IPC_SRCS}
-)
-if(RAPIDJSON_VENDORED)
-  add_dependencies(arrow_ipc rapidjson_ep)
-endif()
-if(FLATBUFFERS_VENDORED)
-  add_dependencies(arrow_ipc flatbuffers_ep)
-endif()
-target_link_libraries(arrow_ipc
-  LINK_PUBLIC ${ARROW_IPC_LINK_LIBS}
-  LINK_PRIVATE ${ARROW_IPC_PRIVATE_LINK_LIBS})
-
 if(NOT APPLE)
   # Localize thirdparty symbols using a linker version script. This hides them
   # from the client application. The OS X linker does not support the
@@ -61,15 +55,18 @@ if(NOT APPLE)
   set(ARROW_IPC_LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/symbols.map")
 endif()
 
-SET_TARGET_PROPERTIES(arrow_ipc PROPERTIES
-  LINKER_LANGUAGE CXX
-  LINK_FLAGS "${ARROW_IPC_LINK_FLAGS}")
+ADD_ARROW_LIB(arrow_ipc
+    SOURCES ${ARROW_IPC_SRCS}
+    SHARED_LINK_FLAGS ${ARROW_IPC_LINK_FLAGS}
+    SHARED_LINK_LIBS ${ARROW_IPC_SHARED_LINK_LIBS}
+    STATIC_LINK_LIBS ${ARROW_IO_SHARED_PRIVATE_LINK_LIBS}
+)
 
-if (APPLE)
-  set_target_properties(arrow_ipc
-    PROPERTIES
-    BUILD_WITH_INSTALL_RPATH ON
-    INSTALL_NAME_DIR "@rpath")
+if(RAPIDJSON_VENDORED)
+  add_dependencies(arrow_ipc_objlib rapidjson_ep)
+endif()
+if(FLATBUFFERS_VENDORED)
+  add_dependencies(arrow_ipc_objlib flatbuffers_ep)
 endif()
 
 ADD_ARROW_TEST(ipc-adapter-test)
@@ -93,9 +90,9 @@ ADD_ARROW_TEST(json-integration-test)
 if (ARROW_BUILD_TESTS)
   if (APPLE)
     target_link_libraries(json-integration-test
+      arrow_ipc_static
+      arrow_io_static
       arrow_static
-      arrow_io
-      arrow_ipc
       gflags
       gtest
       boost_filesystem_static
@@ -105,9 +102,9 @@ if (ARROW_BUILD_TESTS)
       PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
   else()
     target_link_libraries(json-integration-test
+      arrow_ipc_static
+      arrow_io_static
       arrow_static
-      arrow_io
-      arrow_ipc
       gflags
       gtest
       pthread
@@ -156,10 +153,6 @@ install(FILES
   metadata.h
   DESTINATION include/arrow/ipc)
 
-install(TARGETS arrow_ipc
-  LIBRARY DESTINATION lib
-  ARCHIVE DESTINATION lib)
-
 # pkg-config support
 configure_file(arrow-ipc.pc.in
   "${CMAKE_CURRENT_BINARY_DIR}/arrow-ipc.pc"


Mime
View raw message