Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1986,3 +1986,31 @@ SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

--------------------------------------------------------------------------------

The file cpp/cmake_modules/BuildUtils.cmake contains code from

https://gist.github.com/cristianadam/ef920342939a89fae3e8a85ca9459b49

which is made available under the MIT license

Copyright (c) 2019 Cristian Adam

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 0 additions & 4 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,6 @@ endif()
#

# TODO: Also rework how these libs work
set(ARROW_LINK_LIBS)
set(ARROW_SHARED_INSTALL_INTERFACE_LIBS)
set(ARROW_STATIC_INSTALL_INTERFACE_LIBS)

# Libraries to link statically with libarrow.so
set(ARROW_LINK_LIBS)
set(ARROW_STATIC_LINK_LIBS)
Expand Down
95 changes: 95 additions & 0 deletions cpp/cmake_modules/BuildUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,85 @@ function(REUSE_PRECOMPILED_HEADER_LIB TARGET_NAME LIB_NAME)
endif()
endfunction()

# Based on MIT-licensed
# https://gist.github.com/cristianadam/ef920342939a89fae3e8a85ca9459b49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment saying what this does and why? This is a potential future head scratcher for whoever will debug this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I certainly will

function(create_merged_static_lib output_target)
set(options)
set(one_value_args NAME ROOT)
set(multi_value_args TO_MERGE)
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()

set(
output_lib_path
${BUILD_OUTPUT_ROOT_DIRECTORY}${CMAKE_STATIC_LIBRARY_PREFIX}${ARG_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}
)

set(all_library_paths $<TARGET_FILE:${ARG_ROOT}>)
foreach(lib ${ARG_TO_MERGE})
list(APPEND all_library_paths $<TARGET_FILE:${lib}>)
endforeach()

if(APPLE)
set(BUNDLE_COMMAND
"libtool"
"-no_warning_for_no_symbols"
"-static"
"-o"
${output_lib_path}
${all_library_paths})
elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(Clang|GNU)$")
set(ar_script_path ${CMAKE_BINARY_DIR}/${ARG_NAME}.ar)

file(WRITE ${ar_script_path}.in "CREATE ${output_lib_path}\n")
file(APPEND ${ar_script_path}.in "ADDLIB $<TARGET_FILE:${ARG_ROOT}>\n")

foreach(lib ${ARG_TO_MERGE})
file(APPEND ${ar_script_path}.in "ADDLIB $<TARGET_FILE:${lib}>\n")
endforeach()

file(APPEND ${ar_script_path}.in "SAVE\nEND\n")
file(GENERATE OUTPUT ${ar_script_path} INPUT ${ar_script_path}.in)
set(ar_tool ${CMAKE_AR})

if(CMAKE_INTERPROCEDURAL_OPTIMIZATION)
set(ar_tool ${CMAKE_CXX_COMPILER_AR})
endif()

set(BUNDLE_COMMAND ${ar_tool} -M < ${ar_script_path})

elseif(MSVC)
if(NOT CMAKE_LIBTOOL)
find_program(lib_tool lib HINTS "${CMAKE_CXX_COMPILER}/..")
if("${lib_tool}" STREQUAL "lib_tool-NOTFOUND")
message(FATAL_ERROR "Cannot locate libtool to bundle libraries")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to lib.exe instead of libtool on Windows, right?
We will be able to use ${CMAKE_LINKER} on MSVC case: set(BUNDLE_TOOL ${CMAKE_LINKER})

endif()
else()
set(${lib_tool} ${CMAKE_LIBTOOL})
endif()
set(BUNDLE_TOOL ${lib_tool})
set(BUNDLE_COMMAND ${BUNDLE_TOOL} /NOLOGO /OUT:${output_lib_path}
${all_library_paths})
else()
message(FATAL_ERROR "Unknown bundle scenario!")
endif()

add_custom_command(COMMAND ${BUNDLE_COMMAND}
OUTPUT ${output_lib_path}
COMMENT "Bundling ${output_lib_path}"
VERBATIM)

add_custom_target(${output_target} ALL DEPENDS ${output_lib_path})
add_dependencies(${output_target} ${ARG_ROOT} ${ARG_TO_MERGE})
install(FILES ${output_lib_path} DESTINATION ${CMAKE_INSTALL_LIBDIR})
endfunction()

# \arg OUTPUTS list to append built targets to
function(ADD_ARROW_LIB LIB_NAME)
set(options BUILD_SHARED BUILD_STATIC)
Expand All @@ -140,6 +219,7 @@ function(ADD_ARROW_LIB LIB_NAME)
STATIC_LINK_LIBS
SHARED_LINK_LIBS
SHARED_PRIVATE_LINK_LIBS
BUNDLE_STATIC_LIBS
EXTRA_INCLUDES
PRIVATE_INCLUDES
DEPENDENCIES
Expand Down Expand Up @@ -341,6 +421,11 @@ function(ADD_ARROW_LIB LIB_NAME)
set(LIB_NAME_STATIC ${LIB_NAME})
endif()

if(ARG_BUNDLE_STATIC_LIBS)
set(LIB_NAME_BUNDLED ${LIB_NAME_STATIC})
set(LIB_NAME_STATIC ${LIB_NAME_STATIC}_unbundled)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about _plain or _raw?

endif()

if(ARROW_BUILD_STATIC AND WIN32)
target_compile_definitions(${LIB_NAME}_static PUBLIC ARROW_STATIC)
endif()
Expand All @@ -359,6 +444,16 @@ function(ADD_ARROW_LIB LIB_NAME)
"$<BUILD_INTERFACE:${ARG_STATIC_LINK_LIBS}>"
"$<INSTALL_INTERFACE:${INTERFACE_LIBS}>")

if(ARG_BUNDLE_STATIC_LIBS)
create_merged_static_lib(${LIB_NAME}_static_bundled
NAME
${LIB_NAME_BUNDLED}
ROOT
${LIB_NAME}_static
TO_MERGE
${ARG_BUNDLE_STATIC_LIBS})
endif()

install(TARGETS ${LIB_NAME}_static ${INSTALL_IS_OPTIONAL}
EXPORT ${LIB_NAME}_targets
RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR}
Expand Down
14 changes: 14 additions & 0 deletions cpp/src/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,18 @@ endif()

set(ARROW_ALL_SRCS ${ARROW_SRCS} ${ARROW_C_SRCS})

# We bundle some private static dependencies into the Arrow static library,
# for convenience.
set(ARROW_BUNDLE_STATIC_LIBS)

if(ARROW_JEMALLOC)
list(APPEND ARROW_BUNDLE_STATIC_LIBS jemalloc::jemalloc)
endif()

if(ARROW_MIMALLOC)
list(APPEND ARROW_BUNDLE_STATIC_LIBS mimalloc::mimalloc)
endif()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following will be better because we can use both jemalloc and mimalloc at the same time.

set(ARROW_BUNDLE_STATIC_LIBS)

if(ARROW_JEMALLOC)
  list(APPEND ARROW_BUNDLE_STATIC_LIBS jemalloc::jemalloc)
endif()

if(ARROW_MIMALLOC)
  list(APPEND ARROW_BUNDLE_STATIC_LIBS mimalloc::mimalloc)
endif()

add_arrow_lib(arrow
CMAKE_PACKAGE_NAME
Arrow
Expand All @@ -437,6 +449,8 @@ add_arrow_lib(arrow
${ARROW_SHARED_PRIVATE_LINK_LIBS}
STATIC_LINK_LIBS
${ARROW_STATIC_LINK_LIBS}
BUNDLE_STATIC_LIBS
${ARROW_BUNDLE_STATIC_LIBS}
SHARED_INSTALL_INTERFACE_LIBS
${ARROW_SHARED_INSTALL_INTERFACE_LIBS}
STATIC_INSTALL_INTERFACE_LIBS
Expand Down