mirror of
https://github.com/apache/arrow.git
synced 2026-10-29 00:56:31 +08:00
[ARROW-1723] rework static lib generation on Windows
- Add ARROW_STATIC macro when compiling sources for static library target on Windows - Build sources independently for shared and static targets (Unix builds still share compilation artifacts)
This commit is contained in:
1 parent
2e040896d5
commit
46b1a2156b
3 files changed
+42
-19
No files matched your search
@@ -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
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user