Skip to content

Commit

Permalink
apacheGH-39823: [C++] Allow building cpp/src/arrow/**/*.cc without wa…
Browse files Browse the repository at this point in the history
…iting bundled libraries
  • Loading branch information
kou committed Jan 30, 2024
1 parent 63498c2 commit 6ac50a9
Show file tree
Hide file tree
Showing 31 changed files with 624 additions and 451 deletions.
80 changes: 4 additions & 76 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -686,13 +686,9 @@ endif()
#

# Libraries to link statically with libarrow.so.
#
# Note that arrow::hadoop is a header only target that refers
# cpp/thirdparty/hadoop/include/. See
# cpp/cmake_modules/ThirdpartyToolchain.cmake for details.
set(ARROW_SHARED_LINK_LIBS arrow::flatbuffers arrow::hadoop)
set(ARROW_SHARED_LINK_LIBS)
set(ARROW_SHARED_INSTALL_INTERFACE_LIBS)
set(ARROW_STATIC_LINK_LIBS arrow::flatbuffers arrow::hadoop)
set(ARROW_STATIC_LINK_LIBS arrow::flatbuffers)
set(ARROW_STATIC_INSTALL_INTERFACE_LIBS)

# We must use google-cloud-cpp::storage first. If
Expand All @@ -705,81 +701,60 @@ set(ARROW_STATIC_INSTALL_INTERFACE_LIBS)
# /opt/homebrew/include/absl/**/*.h are used instead of .h provided by
# bundled Abseil.
if(ARROW_GCS)
list(APPEND ARROW_SHARED_LINK_LIBS google-cloud-cpp::storage)
list(APPEND ARROW_STATIC_LINK_LIBS google-cloud-cpp::storage)
if(google_cloud_cpp_storage_SOURCE STREQUAL "SYSTEM")
list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS google-cloud-cpp::storage)
endif()
endif()

if(ARROW_USE_BOOST)
list(APPEND ARROW_SHARED_LINK_LIBS Boost::headers)
list(APPEND ARROW_STATIC_LINK_LIBS Boost::headers)
endif()

if(ARROW_USE_OPENSSL)
set(ARROW_OPENSSL_LIBS OpenSSL::Crypto OpenSSL::SSL)
list(APPEND ARROW_SHARED_LINK_LIBS ${ARROW_OPENSSL_LIBS})
list(APPEND ARROW_STATIC_LINK_LIBS ${ARROW_OPENSSL_LIBS})
list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS ${ARROW_OPENSSL_LIBS})
endif()

if(ARROW_WITH_BROTLI)
# Order is important for static linking
set(ARROW_BROTLI_LIBS Brotli::brotlienc Brotli::brotlidec Brotli::brotlicommon)
list(APPEND ARROW_SHARED_LINK_LIBS ${ARROW_BROTLI_LIBS})
list(APPEND ARROW_STATIC_LINK_LIBS ${ARROW_BROTLI_LIBS})
if(Brotli_SOURCE STREQUAL "SYSTEM")
list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS ${ARROW_BROTLI_LIBS})
endif()
endif()

if(ARROW_WITH_BZ2)
list(APPEND ARROW_STATIC_LINK_LIBS BZip2::BZip2)
if(BZip2_SOURCE STREQUAL "SYSTEM")
list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS BZip2::BZip2)
endif()
endif()

if(ARROW_WITH_LZ4)
list(APPEND ARROW_STATIC_LINK_LIBS LZ4::lz4)
if(lz4_SOURCE STREQUAL "SYSTEM")
list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS LZ4::lz4)
endif()
endif()

if(ARROW_WITH_SNAPPY)
list(APPEND ARROW_STATIC_LINK_LIBS ${Snappy_TARGET})
if(Snappy_SOURCE STREQUAL "SYSTEM")
list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS ${Snappy_TARGET})
endif()
endif()

if(ARROW_WITH_ZLIB)
list(APPEND ARROW_STATIC_LINK_LIBS ZLIB::ZLIB)
if(ZLIB_SOURCE STREQUAL "SYSTEM")
list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS ZLIB::ZLIB)
endif()
endif()

if(ARROW_WITH_ZSTD)
list(APPEND ARROW_STATIC_LINK_LIBS ${ARROW_ZSTD_LIBZSTD})
if(zstd_SOURCE STREQUAL "SYSTEM")
list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS ${ARROW_ZSTD_LIBZSTD})
endif()
endif()

if(ARROW_ORC)
list(APPEND ARROW_SHARED_LINK_LIBS orc::orc ${ARROW_PROTOBUF_LIBPROTOBUF})
list(APPEND ARROW_STATIC_LINK_LIBS orc::orc ${ARROW_PROTOBUF_LIBPROTOBUF})
if(ORC_SOURCE STREQUAL "SYSTEM")
list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS orc::orc
${ARROW_PROTOBUF_LIBPROTOBUF})
endif()
endif()

if(ARROW_USE_GLOG)
list(APPEND ARROW_SHARED_LINK_LIBS glog::glog)
list(APPEND ARROW_STATIC_LINK_LIBS glog::glog)
if(GLOG_SOURCE STREQUAL "SYSTEM")
list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS glog::glog)
Expand All @@ -788,8 +763,6 @@ if(ARROW_USE_GLOG)
endif()

if(ARROW_S3)
list(APPEND ARROW_SHARED_LINK_LIBS ${AWSSDK_LINK_LIBRARIES})
list(APPEND ARROW_STATIC_LINK_LIBS ${AWSSDK_LINK_LIBRARIES})
if(AWSSDK_SOURCE STREQUAL "SYSTEM")
list(APPEND
ARROW_STATIC_INSTALL_INTERFACE_LIBS
Expand All @@ -806,70 +779,33 @@ if(ARROW_S3)
endif()

if(ARROW_WITH_OPENTELEMETRY)
list(APPEND
ARROW_SHARED_LINK_LIBS
opentelemetry-cpp::trace
opentelemetry-cpp::ostream_span_exporter
opentelemetry-cpp::otlp_http_exporter)
list(APPEND
ARROW_STATIC_LINK_LIBS
opentelemetry-cpp::trace
opentelemetry-cpp::ostream_span_exporter
opentelemetry-cpp::otlp_http_exporter)
if(opentelemetry_SOURCE STREQUAL "SYSTEM")
list(APPEND
ARROW_STATIC_INSTALL_INTERFACE_LIBS
opentelemetry-cpp::trace
opentelemetry-cpp::ostream_span_exporter
opentelemetry-cpp::otlp_http_exporter)
list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS ${ARROW_OPENTELEMETRY_LIBS})
endif()
if(Protobuf_SOURCE STREQUAL "SYSTEM")
list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS ${ARROW_PROTOBUF_LIBPROTOBUF})
endif()
list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS CURL::libcurl)
endif()

if(ARROW_WITH_AZURE_SDK)
list(APPEND ARROW_SHARED_LINK_LIBS ${AZURE_SDK_LINK_LIBRARIES})
list(APPEND ARROW_STATIC_LINK_LIBS ${AZURE_SDK_LINK_LIBRARIES})
endif()

if(ARROW_WITH_UTF8PROC)
list(APPEND ARROW_SHARED_LINK_LIBS utf8proc::utf8proc)
list(APPEND ARROW_STATIC_LINK_LIBS utf8proc::utf8proc)
if(utf8proc_SOURCE STREQUAL "SYSTEM")
list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS utf8proc::utf8proc)
endif()
endif()

if(ARROW_WITH_RE2)
list(APPEND ARROW_SHARED_LINK_LIBS re2::re2)
list(APPEND ARROW_STATIC_LINK_LIBS re2::re2)
if(re2_SOURCE STREQUAL "SYSTEM")
list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS re2::re2)
endif()
endif()

if(ARROW_WITH_RAPIDJSON)
list(APPEND ARROW_SHARED_LINK_LIBS rapidjson::rapidjson)
list(APPEND ARROW_STATIC_LINK_LIBS rapidjson::rapidjson)
endif()

if(ARROW_USE_XSIMD)
list(APPEND ARROW_SHARED_LINK_LIBS ${ARROW_XSIMD})
list(APPEND ARROW_STATIC_LINK_LIBS ${ARROW_XSIMD})
endif()

add_custom_target(arrow_dependencies)
add_custom_target(arrow_benchmark_dependencies)
add_custom_target(arrow_test_dependencies)

# ARROW-4581: CMake can be finicky about invoking the ExternalProject builds
# for some of the library dependencies, so we "nuke it from orbit" by making
# the toolchain dependency explicit using these "dependencies" targets
add_dependencies(arrow_dependencies toolchain)
add_dependencies(arrow_test_dependencies toolchain-tests)

if(ARROW_STATIC_LINK_LIBS)
add_dependencies(arrow_dependencies ${ARROW_STATIC_LINK_LIBS})
if(ARROW_HDFS OR ARROW_ORC)
Expand All @@ -895,8 +831,7 @@ endif()

if(ARROW_BUILD_BENCHMARKS)
# Some benchmarks use gtest
add_dependencies(arrow_benchmark_dependencies arrow_test_dependencies
toolchain-benchmarks)
add_dependencies(arrow_benchmark_dependencies arrow_test_dependencies)
endif()

set(ARROW_TEST_STATIC_LINK_LIBS arrow_testing_static arrow_static
Expand Down Expand Up @@ -942,15 +877,8 @@ if(ARROW_BUILD_BENCHMARKS)
endif()
endif()

if(ARROW_JEMALLOC)
list(APPEND ARROW_SHARED_LINK_LIBS jemalloc::jemalloc)
list(APPEND ARROW_STATIC_LINK_LIBS jemalloc::jemalloc)
endif()

if(ARROW_MIMALLOC)
add_definitions(-DARROW_MIMALLOC)
list(APPEND ARROW_SHARED_LINK_LIBS mimalloc::mimalloc)
list(APPEND ARROW_STATIC_LINK_LIBS mimalloc::mimalloc)
endif()

# ----------------------------------------------------------------------
Expand Down
16 changes: 15 additions & 1 deletion cpp/cmake_modules/FindRapidJSONAlt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ endif()
find_package(RapidJSON ${find_package_args})
if(RapidJSON_FOUND)
set(RapidJSONAlt_FOUND TRUE)
set(RAPIDJSON_INCLUDE_DIR ${RAPIDJSON_INCLUDE_DIRS})
if(NOT TARGET RapidJSON)
add_library(RapidJSON INTERFACE IMPORTED)
target_include_directories(RapidJSON INTERFACE "${RAPIDJSON_INCLUDE_DIRS}")
endif()
return()
endif()

Expand Down Expand Up @@ -74,3 +77,14 @@ find_package_handle_standard_args(
RapidJSONAlt
REQUIRED_VARS RAPIDJSON_INCLUDE_DIR
VERSION_VAR RAPIDJSON_VERSION)

if(RapidJSONAlt_FOUND)
if(WIN32 AND "${RAPIDJSON_INCLUDE_DIR}" MATCHES "^/")
# MSYS2
execute_process(COMMAND "cygpath" "--windows" "${RAPIDJSON_INCLUDE_DIR}"
OUTPUT_VARIABLE RAPIDJSON_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
add_library(RapidJSON INTERFACE IMPORTED)
target_include_directories(RapidJSON INTERFACE "${RAPIDJSON_INCLUDE_DIR}")
endif()
Loading

0 comments on commit 6ac50a9

Please sign in to comment.