arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject [arrow] branch master updated: ARROW-1723: [C++] add ARROW_STATIC to mark static libs on Windows
Date Fri, 27 Oct 2017 02:46:45 GMT
This is an automated email from the ASF dual-hosted git repository.

wesm 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 2ed886e  ARROW-1723: [C++] add ARROW_STATIC to mark static libs on Windows
2ed886e is described below

commit 2ed886ee707822b398cdb22f4d4c10116fa1d9f3
Author: John Jenkins <jjenkins@wolve.com>
AuthorDate: Thu Oct 26 22:45:55 2017 -0400

    ARROW-1723: [C++] add ARROW_STATIC to mark static libs on Windows
    
    Add a preprocessor macro ARROW_STATIC when doing static library builds on Windows. Clients
developing/building off the static library will also need to define this - please let me know
how this should be documented, if this is an acceptable approach.
    
    Author: John Jenkins <jjenkins@wolve.com>
    
    Closes #1244 from JohnPJenkins/windows-static-lib and squashes the following commits:
    
    46b1a215 [John Jenkins] [ARROW-1723] rework static lib generation on Windows
---
 cpp/README.md                      |  8 +++++++
 cpp/cmake_modules/BuildUtils.cmake | 49 ++++++++++++++++++++++++--------------
 cpp/src/arrow/util/visibility.h    |  4 +++-
 3 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/cpp/README.md b/cpp/README.md
index 9c26842..6038353 100644
--- a/cpp/README.md
+++ b/cpp/README.md
@@ -69,6 +69,14 @@ Simple release build:
 
 Detailed unit test logs will be placed in the build directory under `build/test-logs`.
 
+### Statically linking to Arrow on Windows
+
+The Arrow headers on Windows static library builds (enabled by the CMake
+option `ARROW_BUILD_STATIC`) use the preprocessor macro `ARROW_STATIC` to
+suppress dllimport/dllexport marking of symbols. Projects that statically link
+against Arrow on Windows additionally need this definition. The Unix builds do
+not use the macro.
+
 ### Building/Running benchmarks
 
 Follow the directions for simple build except run cmake
diff --git a/cpp/cmake_modules/BuildUtils.cmake b/cpp/cmake_modules/BuildUtils.cmake
index fb09e4e..207bb9a 100644
--- a/cpp/cmake_modules/BuildUtils.cmake
+++ b/cpp/cmake_modules/BuildUtils.cmake
@@ -98,21 +98,28 @@ function(ADD_ARROW_LIB LIB_NAME)
     message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}")
   endif()
 
-  add_library(${LIB_NAME}_objlib OBJECT
-    ${ARG_SOURCES}
-  )
-
-  if (ARG_DEPENDENCIES)
-    add_dependencies(${LIB_NAME}_objlib ${ARG_DEPENDENCIES})
+  if(MSVC)
+    set(LIB_DEPS ${ARG_SOURCES})
+    set(EXTRA_DEPS ${ARG_DEPENDENCIES})
+  else()
+    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 (ARG_DEPENDENCIES)
+      add_dependencies(${LIB_NAME}_objlib ${ARG_DEPENDENCIES})
+    endif()
+    set(LIB_DEPS $<TARGET_OBJECTS:${LIB_NAME}_objlib>)
+    set(EXTRA_DEPS)
   endif()
 
-  # Necessary to make static linking into other shared libraries work properly
-  set_property(TARGET ${LIB_NAME}_objlib PROPERTY POSITION_INDEPENDENT_CODE 1)
-
   set(RUNTIME_INSTALL_DIR bin)
 
   if (ARROW_BUILD_SHARED)
-    add_library(${LIB_NAME}_shared SHARED $<TARGET_OBJECTS:${LIB_NAME}_objlib>)
+    add_library(${LIB_NAME}_shared SHARED ${LIB_DEPS})
+    if (EXTRA_DEPS)
+      add_dependencies(${LIB_NAME}_shared ${EXTRA_DEPS})
+    endif()
 
     if(APPLE)
       # On OS X, you can avoid linking at library load time and instead
@@ -154,22 +161,28 @@ function(ADD_ARROW_LIB LIB_NAME)
   endif()
 
   if (ARROW_BUILD_STATIC)
-      if (MSVC)
-        set(LIB_NAME_STATIC ${LIB_NAME}_static)
-      else()
-        set(LIB_NAME_STATIC ${LIB_NAME})
-      endif()
-      add_library(${LIB_NAME}_static STATIC $<TARGET_OBJECTS:${LIB_NAME}_objlib>)
+    add_library(${LIB_NAME}_static STATIC ${LIB_DEPS})
+    if(EXTRA_DEPS)
+      add_dependencies(${LIB_NAME}_static ${EXTRA_DEPS})
+    endif()
+
+    if (MSVC)
+      set(LIB_NAME_STATIC ${LIB_NAME}_static)
+      target_compile_definitions(${LIB_NAME}_static PUBLIC ARROW_STATIC)
+    else()
+      set(LIB_NAME_STATIC ${LIB_NAME})
+    endif()
+
     set_target_properties(${LIB_NAME}_static
       PROPERTIES
       LIBRARY_OUTPUT_DIRECTORY "${BUILD_OUTPUT_ROOT_DIRECTORY}"
       OUTPUT_NAME ${LIB_NAME_STATIC})
 
-  target_link_libraries(${LIB_NAME}_static
+    target_link_libraries(${LIB_NAME}_static
       LINK_PUBLIC ${ARG_STATIC_LINK_LIBS}
       LINK_PRIVATE ${ARG_STATIC_PRIVATE_LINK_LIBS})
 
-  install(TARGETS ${LIB_NAME}_static
+    install(TARGETS ${LIB_NAME}_static
       RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR}
       LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
       ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
diff --git a/cpp/src/arrow/util/visibility.h b/cpp/src/arrow/util/visibility.h
index ea78e57..119c55d 100644
--- a/cpp/src/arrow/util/visibility.h
+++ b/cpp/src/arrow/util/visibility.h
@@ -25,7 +25,9 @@
 #pragma GCC diagnostic ignored "-Wattributes"
 #endif
 
-#ifdef ARROW_EXPORTING
+#ifdef ARROW_STATIC
+#define ARROW_EXPORT
+#elif defined(ARROW_EXPORTING)
 #define ARROW_EXPORT __declspec(dllexport)
 #else
 #define ARROW_EXPORT __declspec(dllimport)

-- 
To stop receiving notification emails like this one, please contact
['"commits@arrow.apache.org" <commits@arrow.apache.org>'].

Mime
View raw message