Skip to content
Draft
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
89 changes: 28 additions & 61 deletions cpp/cmake_modules/ThirdpartyToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3761,66 +3761,31 @@ function(build_orc)

message(STATUS "Building Apache ORC from source")

if(LZ4_VENDORED)
set(ORC_LZ4_TARGET lz4_static)
set(ORC_LZ4_ROOT "${lz4_SOURCE_DIR}")
set(ORC_LZ4_INCLUDE_DIR "${lz4_SOURCE_DIR}/lib")
else()
set(ORC_LZ4_TARGET LZ4::lz4)
get_target_property(ORC_LZ4_INCLUDE_DIR ${ORC_LZ4_TARGET}
INTERFACE_INCLUDE_DIRECTORIES)
get_filename_component(ORC_LZ4_ROOT "${ORC_LZ4_INCLUDE_DIR}" DIRECTORY)
endif()

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.29)
# ORC 2.3.0 doesn't include apache/orc#2437 yet. Patch it so
# FetchContent can reuse Arrow's bundled dependency targets directly.
set(ORC_PATCH_COMMAND)
find_program(GIT git)
if(GIT)
set(ORC_PATCH_COMMAND ${GIT} apply ${CMAKE_CURRENT_LIST_DIR}/orc-2437.patch)
else()
find_program(PATCH patch)
if(PATCH)
set(ORC_PATCH_COMMAND ${PATCH} -p1 -i ${CMAKE_CURRENT_LIST_DIR}/orc-2437.patch)
endif()
endif()
if(NOT ORC_PATCH_COMMAND)
message(FATAL_ERROR "git or patch is required to patch bundled ORC")
endif()

fetchcontent_declare(orc
${FC_DECLARE_COMMON_OPTIONS}
PATCH_COMMAND ${ORC_PATCH_COMMAND}
URL ${ORC_SOURCE_URL}
URL_HASH "SHA256=${ARROW_ORC_BUILD_SHA256_CHECKSUM}")
prepare_fetchcontent()

set(CMAKE_UNITY_BUILD FALSE)

set(ORC_PREFER_STATIC_LZ4 OFF)
set(LZ4_HOME "${ORC_LZ4_ROOT}")
set(LZ4_INCLUDE_DIR "${ORC_LZ4_INCLUDE_DIR}")
set(LZ4_LIBRARY ${ORC_LZ4_TARGET})

set(ORC_PREFER_STATIC_PROTOBUF OFF)
get_target_property(PROTOBUF_INCLUDE_DIR ${ARROW_PROTOBUF_LIBPROTOBUF}
INTERFACE_INCLUDE_DIRECTORIES)
get_filename_component(Protobuf_ROOT "${PROTOBUF_INCLUDE_DIR}" DIRECTORY)
set(PROTOBUF_HOME ${Protobuf_ROOT})
set(PROTOBUF_EXECUTABLE ${ARROW_PROTOBUF_PROTOC})
set(PROTOBUF_LIBRARY ${ARROW_PROTOBUF_LIBPROTOBUF})
set(PROTOC_LIBRARY ${ARROW_PROTOBUF_LIBPROTOC})

set(ORC_PREFER_STATIC_SNAPPY OFF)
get_target_property(SNAPPY_INCLUDE_DIR ${Snappy_TARGET} INTERFACE_INCLUDE_DIRECTORIES)
get_filename_component(Snappy_ROOT "${SNAPPY_INCLUDE_DIR}" DIRECTORY)
set(SNAPPY_HOME ${Snappy_ROOT})
set(SNAPPY_LIBRARY ${Snappy_TARGET})

set(ORC_PREFER_STATIC_ZLIB OFF)
get_target_property(ZLIB_INCLUDE_DIR ZLIB::ZLIB INTERFACE_INCLUDE_DIRECTORIES)
get_filename_component(ZLIB_ROOT "${ZLIB_INCLUDE_DIR}" DIRECTORY)
set(ZLIB_HOME ${ZLIB_ROOT})
# From CMake 3.21 onwards the set(CACHE) command does not remove
# any normal variable of the same name from the current scope. We
# have to manually remove the variable via unset to avoid ORC not
# finding the ZLIB_LIBRARY.
unset(ZLIB_LIBRARY)
set(ZLIB_LIBRARY
ZLIB::ZLIB
CACHE STRING "" FORCE)

set(ORC_PREFER_STATIC_ZSTD OFF)
get_target_property(ZSTD_INCLUDE_DIR ${ARROW_ZSTD_LIBZSTD}
INTERFACE_INCLUDE_DIRECTORIES)
get_filename_component(ZSTD_ROOT "${ZSTD_INCLUDE_DIR}" DIRECTORY)
set(ZSTD_HOME ${ZSTD_ROOT})
set(ZSTD_LIBRARY ${ARROW_ZSTD_LIBZSTD})

set(BUILD_CPP_TESTS OFF)
set(BUILD_JAVA OFF)
set(BUILD_LIBHDFSPP OFF)
Expand All @@ -3830,15 +3795,6 @@ function(build_orc)

fetchcontent_makeavailable(orc)

# ORC 2.2.1 unconditionally adds /std:c++17 on MSVC via
# add_compile_options, which overrides CMAKE_CXX_STANDARD and causes
# ABI mismatches with protobuf (GlobalEmptyStringConstexpr vs
# GlobalEmptyStringDynamicInit). Override the standard on the orc target.
# Fixed in ORC 2.3.0: https://github.com/apache/orc/commit/7674f43
if(MSVC)
target_compile_options(orc PRIVATE "/std:c++${CMAKE_CXX_STANDARD}")
endif()

add_library(orc::orc INTERFACE IMPORTED)
target_link_libraries(orc::orc INTERFACE orc)
target_link_libraries(orc::orc INTERFACE ${ARROW_PROTOBUF_LIBPROTOBUF})
Expand Down Expand Up @@ -3889,6 +3845,17 @@ function(build_orc)
get_target_property(ORC_ZLIB_ROOT ZLIB::ZLIB INTERFACE_INCLUDE_DIRECTORIES)
get_filename_component(ORC_ZLIB_ROOT "${ORC_ZLIB_ROOT}" DIRECTORY)

if(LZ4_VENDORED)
set(ORC_LZ4_TARGET lz4_static)
set(ORC_LZ4_ROOT "${lz4_SOURCE_DIR}")
set(ORC_LZ4_INCLUDE_DIR "${lz4_SOURCE_DIR}/lib")
else()
set(ORC_LZ4_TARGET LZ4::lz4)
get_target_property(ORC_LZ4_INCLUDE_DIR ${ORC_LZ4_TARGET}
INTERFACE_INCLUDE_DIRECTORIES)
get_filename_component(ORC_LZ4_ROOT "${ORC_LZ4_INCLUDE_DIR}" DIRECTORY)
endif()

if(ORC_ABSL_INCLUDE_DIR)
set(ORC_CXX_FLAGS "${EP_CXX_FLAGS} -isystem ${ORC_ABSL_INCLUDE_DIR}")
else()
Expand Down
104 changes: 104 additions & 0 deletions cpp/cmake_modules/orc-2437.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# 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.

diff --git a/cmake_modules/ThirdpartyToolchain.cmake b/cmake_modules/ThirdpartyToolchain.cmake
index c03afa8f29..e8cfb85aa1 100644
--- a/cmake_modules/ThirdpartyToolchain.cmake
+++ b/cmake_modules/ThirdpartyToolchain.cmake
@@ -172,6 +172,12 @@ elseif (ORC_PACKAGE_KIND STREQUAL "vcpkg")
list (APPEND ORC_SYSTEM_DEPENDENCIES Protobuf)
list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:protobuf::libprotobuf>")
set (PROTOBUF_EXECUTABLE protobuf::protoc)
+elseif (TARGET ${ARROW_PROTOBUF_LIBPROTOBUF})
+ # Used by Apache Arrow only, remove this once Arrow leverages FetchContent for Protobuf
+ add_library (orc_protobuf INTERFACE IMPORTED)
+ target_link_libraries(orc_protobuf INTERFACE ${ARROW_PROTOBUF_LIBPROTOBUF})
+ set (PROTOBUF_EXECUTABLE ${ARROW_PROTOBUF_PROTOC})
+ message(STATUS "Using existing ${ARROW_PROTOBUF_LIBPROTOBUF}")
elseif (NOT "${PROTOBUF_HOME}" STREQUAL "")
find_package (ProtobufAlt REQUIRED)

@@ -181,12 +187,6 @@ elseif (NOT "${PROTOBUF_HOME}" STREQUAL "")
orc_add_resolved_library (orc_protobuf ${PROTOBUF_LIBRARY} ${PROTOBUF_INCLUDE_DIR})
endif ()

- if (ORC_PREFER_STATIC_PROTOBUF AND PROTOC_STATIC_LIB)
- orc_add_resolved_library (orc_protoc ${PROTOC_STATIC_LIB} ${PROTOBUF_INCLUDE_DIR})
- else ()
- orc_add_resolved_library (orc_protoc ${PROTOC_LIBRARY} ${PROTOBUF_INCLUDE_DIR})
- endif ()
-
list (APPEND ORC_SYSTEM_DEPENDENCIES ProtobufAlt)
list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:protobuf::libprotobuf>")
orc_provide_find_module (ProtobufAlt)
@@ -245,9 +245,7 @@ else ()

add_library(orc_protobuf INTERFACE IMPORTED)
target_link_libraries(orc_protobuf INTERFACE protobuf::libprotobuf)
- if(NOT PROTOBUF_EXECUTABLE)
- set(PROTOBUF_EXECUTABLE protobuf::protoc)
- endif()
+ set(PROTOBUF_EXECUTABLE protobuf::protoc)
endblock()
endif ()

@@ -277,6 +275,16 @@ elseif (NOT "${SNAPPY_HOME}" STREQUAL "")
list (APPEND ORC_SYSTEM_DEPENDENCIES SnappyAlt)
list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:Snappy::snappy>")
orc_provide_find_module (SnappyAlt)
+elseif (TARGET Snappy::snappy)
+ # Used by Apache Arrow only, remove this once Arrow leverages FetchContent for Snappy
+ add_library (orc_snappy INTERFACE IMPORTED)
+ target_link_libraries(orc_snappy INTERFACE Snappy::snappy)
+ message(STATUS "Using existing Snappy::snappy")
+elseif (TARGET Snappy::snappy-static)
+ # Used by Apache Arrow only, remove this once Arrow leverages FetchContent for Snappy
+ add_library (orc_snappy INTERFACE IMPORTED)
+ target_link_libraries(orc_snappy INTERFACE Snappy::snappy-static)
+ message(STATUS "Using existing Snappy::snappy-static")
else ()
block(PROPAGATE ORC_SYSTEM_DEPENDENCIES ORC_INSTALL_INTERFACE_TARGETS)
prepare_fetchcontent()
@@ -359,6 +367,11 @@ elseif (NOT "${ZLIB_HOME}" STREQUAL "")
list (APPEND ORC_SYSTEM_DEPENDENCIES ZLIBAlt)
list (APPEND ORC_INSTALL_INTERFACE_TARGETS "$<INSTALL_INTERFACE:ZLIB::ZLIB>")
orc_provide_find_module (ZLIBAlt)
+elseif (TARGET ZLIB::ZLIB)
+ # Used by Apache Arrow only, remove this once Arrow leverages FetchContent for ZLIB
+ add_library (orc_zlib INTERFACE IMPORTED)
+ target_link_libraries(orc_zlib INTERFACE ZLIB::ZLIB)
+ message(STATUS "Using existing ZLIB::ZLIB")
else ()
block(PROPAGATE ORC_SYSTEM_DEPENDENCIES ORC_INSTALL_INTERFACE_TARGETS ZLIB_LIBRARIES ZLIB_INCLUDE_DIRS)
prepare_fetchcontent()
@@ -450,6 +463,16 @@ elseif (NOT "${ZSTD_HOME}" STREQUAL "")
endif ()
list (APPEND ORC_SYSTEM_DEPENDENCIES ZSTDAlt)
orc_provide_find_module (ZSTDAlt)
+elseif (TARGET zstd::libzstd_shared)
+ # Used by Apache Arrow only, remove this once Arrow leverages FetchContent for zstd
+ add_library (orc_zstd INTERFACE IMPORTED)
+ target_link_libraries(orc_zstd INTERFACE zstd::libzstd_shared)
+ message(STATUS "Using existing zstd::libzstd_shared")
+elseif (TARGET zstd::libzstd_static)
+ # Used by Apache Arrow only, remove this once Arrow leverages FetchContent for zstd
+ add_library (orc_zstd INTERFACE IMPORTED)
+ target_link_libraries(orc_zstd INTERFACE zstd::libzstd_static)
+ message(STATUS "Using existing zstd::libzstd_static")
else ()
block(PROPAGATE ORC_SYSTEM_DEPENDENCIES ORC_INSTALL_INTERFACE_TARGETS)
prepare_fetchcontent()
4 changes: 2 additions & 2 deletions cpp/thirdparty/versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ ARROW_OPENTELEMETRY_BUILD_VERSION=v1.21.0
ARROW_OPENTELEMETRY_BUILD_SHA256_CHECKSUM=98e5546f577a11b52a57faed1f4cc60d8c1daa44760eba393f43eab5a8ec46a2
ARROW_OPENTELEMETRY_PROTO_BUILD_VERSION=v1.7.0
ARROW_OPENTELEMETRY_PROTO_BUILD_SHA256_CHECKSUM=11330d850f5e24d34c4246bc8cb21fcd311e7565d219195713455a576bb11bed
ARROW_ORC_BUILD_VERSION=2.2.1
ARROW_ORC_BUILD_SHA256_CHECKSUM=52fc762332442e8b05d7182f8c035f9e04d945b9a52be22ab69f28b3f37d4500
ARROW_ORC_BUILD_VERSION=2.3.0
ARROW_ORC_BUILD_SHA256_CHECKSUM=6c9e2f6663ac9ef34ca4ae5ae4f004a651e5fe31f2e05b6eb5d99d105091d87c
ARROW_PROTOBUF_BUILD_VERSION=v31.1
ARROW_PROTOBUF_BUILD_SHA256_CHECKSUM=12bfd76d27b9ac3d65c00966901609e020481b9474ef75c7ff4601ac06fa0b82
# Because of https://github.com/Tencent/rapidjson/pull/1323, we require
Expand Down
Loading