From d49e9c9f73ecb3d9c16099a438fca86d44269149 Mon Sep 17 00:00:00 2001 From: Jonathan Keane Date: Sat, 10 May 2025 08:38:04 -0500 Subject: [PATCH 1/8] lz4 --- cpp/cmake_modules/ThirdpartyToolchain.cmake | 61 ++++++++++++++------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake index 92ea7e346f98..aa5cab4fcab6 100644 --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake @@ -2652,32 +2652,53 @@ if(ARROW_WITH_ZLIB) endif() macro(build_lz4) - message(STATUS "Building LZ4 from source") + message(STATUS "Building LZ4 from source using FetchContent") - set(LZ4_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/lz4_ep-install") + # Set LZ4 as vendored + set(LZ4_VENDORED TRUE) - set(LZ4_STATIC_LIB - "${LZ4_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}lz4${CMAKE_STATIC_LIBRARY_SUFFIX}") + # Declare the content + fetchcontent_declare(lz4_ep + URL ${LZ4_SOURCE_URL} + URL_HASH "SHA256=${ARROW_LZ4_BUILD_SHA256_CHECKSUM}" + SOURCE_SUBDIR "build/cmake") - set(LZ4_CMAKE_ARGS ${EP_COMMON_CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX= - -DLZ4_BUILD_CLI=OFF -DLZ4_BUILD_LEGACY_LZ4C=OFF) + # Prepare fetch content environment + prepare_fetchcontent() - # We need to copy the header in lib to directory outside of the build - externalproject_add(lz4_ep - ${EP_COMMON_OPTIONS} - CMAKE_ARGS ${LZ4_CMAKE_ARGS} - SOURCE_SUBDIR "build/cmake" - INSTALL_DIR ${LZ4_PREFIX} - URL ${LZ4_SOURCE_URL} - URL_HASH "SHA256=${ARROW_LZ4_BUILD_SHA256_CHECKSUM}" - BUILD_BYPRODUCTS ${LZ4_STATIC_LIB}) + # Set LZ4-specific build options as cache variables + set(LZ4_BUILD_CLI + OFF + CACHE BOOL "Don't build LZ4 CLI" FORCE) + set(LZ4_BUILD_LEGACY_LZ4C + OFF + CACHE BOOL "Don't build legacy LZ4 tools" FORCE) + + # Make the dependency available - this will actually perform the download and configure + fetchcontent_makeavailable(lz4_ep) - file(MAKE_DIRECTORY "${LZ4_PREFIX}/include") - add_library(LZ4::lz4 STATIC IMPORTED) - set_target_properties(LZ4::lz4 PROPERTIES IMPORTED_LOCATION "${LZ4_STATIC_LIB}") - target_include_directories(LZ4::lz4 BEFORE INTERFACE "${LZ4_PREFIX}/include") - add_dependencies(LZ4::lz4 lz4_ep) + # Get the source and binary directories after fetching content + fetchcontent_getproperties(lz4_ep + SOURCE_DIR LZ4_SOURCE_DIR + BINARY_DIR LZ4_BINARY_DIR) + + # Set up the imported library for compatibility with the rest of the build system + set(LZ4_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/_deps/lz4_ep-build") + set(LZ4_INCLUDE_DIR "${LZ4_SOURCE_DIR}/lib") + + # Since lz4 is now part of our build system, we can directly use the target + add_library(LZ4::lz4 ALIAS lz4_static) + + # Add lz4_static to the orc export set + if(NOT TARGET lz4_static) + message(FATAL_ERROR "Expected lz4_static target to be created by FetchContent") + endif() + if(NOT DEFINED CMAKE_EXPORT_NO_PACKAGE_REGISTRY) + set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY ON) + endif() + install(TARGETS lz4_static EXPORT orc_targets) + # Add to bundled static libs list(APPEND ARROW_BUNDLED_STATIC_LIBS LZ4::lz4) endmacro() From 2794a40776e335473ac192c5fbf74bbd29395a8d Mon Sep 17 00:00:00 2001 From: Jonathan Keane Date: Sun, 11 May 2025 23:00:47 -0500 Subject: [PATCH 2/8] PR comments --- cpp/cmake_modules/ThirdpartyToolchain.cmake | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake index aa5cab4fcab6..6cfcdc84c0cd 100644 --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake @@ -2677,27 +2677,9 @@ macro(build_lz4) # Make the dependency available - this will actually perform the download and configure fetchcontent_makeavailable(lz4_ep) - # Get the source and binary directories after fetching content - fetchcontent_getproperties(lz4_ep - SOURCE_DIR LZ4_SOURCE_DIR - BINARY_DIR LZ4_BINARY_DIR) - - # Set up the imported library for compatibility with the rest of the build system - set(LZ4_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/_deps/lz4_ep-build") - set(LZ4_INCLUDE_DIR "${LZ4_SOURCE_DIR}/lib") - # Since lz4 is now part of our build system, we can directly use the target add_library(LZ4::lz4 ALIAS lz4_static) - # Add lz4_static to the orc export set - if(NOT TARGET lz4_static) - message(FATAL_ERROR "Expected lz4_static target to be created by FetchContent") - endif() - if(NOT DEFINED CMAKE_EXPORT_NO_PACKAGE_REGISTRY) - set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY ON) - endif() - install(TARGETS lz4_static EXPORT orc_targets) - # Add to bundled static libs list(APPEND ARROW_BUNDLED_STATIC_LIBS LZ4::lz4) endmacro() From 73147b7b18138f15a8e1397fa534ebb893b26c9c Mon Sep 17 00:00:00 2001 From: Jonathan Keane Date: Mon, 12 May 2025 07:18:58 -0500 Subject: [PATCH 3/8] Add lz4 as an interface --- cpp/cmake_modules/ThirdpartyToolchain.cmake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake index 6cfcdc84c0cd..8de816ea55f3 100644 --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake @@ -2677,11 +2677,12 @@ macro(build_lz4) # Make the dependency available - this will actually perform the download and configure fetchcontent_makeavailable(lz4_ep) - # Since lz4 is now part of our build system, we can directly use the target - add_library(LZ4::lz4 ALIAS lz4_static) + # Add lz4 as an interfece library so other targets can depend on it + add_library(LZ4::lz4 INTERFACE IMPORTED) + target_link_libraries(LZ4::lz4 INTERFACE lz4_static) # Add to bundled static libs - list(APPEND ARROW_BUNDLED_STATIC_LIBS LZ4::lz4) + list(APPEND ARROW_BUNDLED_STATIC_LIBS lz4_static) endmacro() if(ARROW_WITH_LZ4) From adf80fb7069ea567478f7bba917bf3f4e084c719 Mon Sep 17 00:00:00 2001 From: Jonathan Keane Date: Mon, 12 May 2025 21:50:07 -0500 Subject: [PATCH 4/8] Update cpp/cmake_modules/ThirdpartyToolchain.cmake Co-authored-by: Sutou Kouhei --- cpp/cmake_modules/ThirdpartyToolchain.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake index 8de816ea55f3..2aa4edd62152 100644 --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake @@ -2677,7 +2677,9 @@ macro(build_lz4) # Make the dependency available - this will actually perform the download and configure fetchcontent_makeavailable(lz4_ep) - # Add lz4 as an interfece library so other targets can depend on it + # Use LZ4::lz4 as an imported library not an alias of lz4_static so other targets such as orc + # can depend on it as an external library. External libraries are ignored in + # install(TARGETS orc EXPORT orc_targets) and install(EXPORT orc_targets). add_library(LZ4::lz4 INTERFACE IMPORTED) target_link_libraries(LZ4::lz4 INTERFACE lz4_static) From cc97ec3e1b66626640508da1aff052377e877ba4 Mon Sep 17 00:00:00 2001 From: Jonathan Keane Date: Mon, 12 May 2025 21:50:14 -0500 Subject: [PATCH 5/8] Update cpp/cmake_modules/ThirdpartyToolchain.cmake Co-authored-by: Sutou Kouhei --- cpp/cmake_modules/ThirdpartyToolchain.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake index 2aa4edd62152..6a2a9b7b96fc 100644 --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake @@ -2683,7 +2683,8 @@ macro(build_lz4) add_library(LZ4::lz4 INTERFACE IMPORTED) target_link_libraries(LZ4::lz4 INTERFACE lz4_static) - # Add to bundled static libs + # Add to bundled static libs. + # We must use lz4_static (not imported target) not LZ4::lz4 (imported target). list(APPEND ARROW_BUNDLED_STATIC_LIBS lz4_static) endmacro() From 35e3edd8e84c4b011e9874c5cb207afe8dfe4462 Mon Sep 17 00:00:00 2001 From: Jonathan Keane Date: Tue, 13 May 2025 23:18:00 -0500 Subject: [PATCH 6/8] Try fixing TARGET_FILE:LZ4::lz4 --- cpp/cmake_modules/ThirdpartyToolchain.cmake | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake index 6a2a9b7b96fc..c0dde13ff86e 100644 --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake @@ -2694,6 +2694,15 @@ if(ARROW_WITH_LZ4) TRUE PC_PACKAGE_NAMES liblz4) + + # Set the target name based on how LZ4 was resolved + if(TARGET lz4_static) + set(LZ4_TARGET lz4_static) + elseif(TARGET LZ4::lz4) + set(LZ4_TARGET LZ4::lz4) + else() + message(FATAL_ERROR "Unable to determine LZ4 target name") + endif() endif() macro(build_zstd) @@ -4742,8 +4751,8 @@ function(build_orc) "-DSNAPPY_HOME=${ORC_SNAPPY_ROOT}" "-DSNAPPY_LIBRARY=$" "-DLZ4_HOME=${ORC_LZ4_ROOT}" - "-DLZ4_LIBRARY=$" - "-DLZ4_STATIC_LIB=$" + "-DLZ4_LIBRARY=$" + "-DLZ4_STATIC_LIB=$" "-DLZ4_INCLUDE_DIR=${ORC_LZ4_ROOT}/include" "-DSNAPPY_INCLUDE_DIR=${ORC_SNAPPY_INCLUDE_DIR}" "-DZSTD_HOME=${ORC_ZSTD_ROOT}" From ae2e181506fcf70f38ea426efef2137a2a2de503 Mon Sep 17 00:00:00 2001 From: Jonathan Keane Date: Wed, 14 May 2025 20:59:49 -0500 Subject: [PATCH 7/8] PR comments --- cpp/cmake_modules/ThirdpartyToolchain.cmake | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake index c0dde13ff86e..f7771eb3bd17 100644 --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake @@ -4725,7 +4725,12 @@ function(build_orc) INTERFACE_INCLUDE_DIRECTORIES) get_filename_component(ORC_SNAPPY_ROOT "${ORC_SNAPPY_INCLUDE_DIR}" DIRECTORY) - get_target_property(ORC_LZ4_ROOT LZ4::lz4 INTERFACE_INCLUDE_DIRECTORIES) + if(LZ4_VENDORED) + set(ORC_LZ4_TARGET lz4_static) + else() + set(ORC_LZ4_TARGET LZ4::lz4) + endif() + get_target_property(ORC_LZ4_ROOT ${ORC_LZ4_TARGET} INTERFACE_INCLUDE_DIRECTORIES) get_filename_component(ORC_LZ4_ROOT "${ORC_LZ4_ROOT}" DIRECTORY) get_target_property(ORC_ZSTD_ROOT ${ARROW_ZSTD_LIBZSTD} INTERFACE_INCLUDE_DIRECTORIES) @@ -4751,8 +4756,8 @@ function(build_orc) "-DSNAPPY_HOME=${ORC_SNAPPY_ROOT}" "-DSNAPPY_LIBRARY=$" "-DLZ4_HOME=${ORC_LZ4_ROOT}" - "-DLZ4_LIBRARY=$" - "-DLZ4_STATIC_LIB=$" + "-DLZ4_LIBRARY=$" + "-DLZ4_STATIC_LIB=$" "-DLZ4_INCLUDE_DIR=${ORC_LZ4_ROOT}/include" "-DSNAPPY_INCLUDE_DIR=${ORC_SNAPPY_INCLUDE_DIR}" "-DZSTD_HOME=${ORC_ZSTD_ROOT}" From a9c8fbd5562f7bf9e7fd77c5225cfbdc1655ea78 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Thu, 15 May 2025 13:36:38 +0900 Subject: [PATCH 8/8] Fix bundled LZ4 paths for ORC --- cpp/cmake_modules/ThirdpartyToolchain.cmake | 46 +++++++++------------ 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake index f7771eb3bd17..aea5bbf7cb20 100644 --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake @@ -2658,7 +2658,7 @@ macro(build_lz4) set(LZ4_VENDORED TRUE) # Declare the content - fetchcontent_declare(lz4_ep + fetchcontent_declare(lz4 URL ${LZ4_SOURCE_URL} URL_HASH "SHA256=${ARROW_LZ4_BUILD_SHA256_CHECKSUM}" SOURCE_SUBDIR "build/cmake") @@ -2675,7 +2675,7 @@ macro(build_lz4) CACHE BOOL "Don't build legacy LZ4 tools" FORCE) # Make the dependency available - this will actually perform the download and configure - fetchcontent_makeavailable(lz4_ep) + fetchcontent_makeavailable(lz4) # Use LZ4::lz4 as an imported library not an alias of lz4_static so other targets such as orc # can depend on it as an external library. External libraries are ignored in @@ -2694,15 +2694,6 @@ if(ARROW_WITH_LZ4) TRUE PC_PACKAGE_NAMES liblz4) - - # Set the target name based on how LZ4 was resolved - if(TARGET lz4_static) - set(LZ4_TARGET lz4_static) - elseif(TARGET LZ4::lz4) - set(LZ4_TARGET LZ4::lz4) - else() - message(FATAL_ERROR "Unable to determine LZ4 target name") - endif() endif() macro(build_zstd) @@ -4605,6 +4596,17 @@ target_include_directories(arrow::hadoop INTERFACE "${HADOOP_HOME}/include") 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) fetchcontent_declare(orc ${FC_DECLARE_COMMON_OPTIONS} @@ -4617,16 +4619,14 @@ function(build_orc) set(ORC_PREFER_STATIC_LZ4 OFF CACHE BOOL "" FORCE) - get_target_property(LZ4_INCLUDE_DIR LZ4::lz4 INTERFACE_INCLUDE_DIRECTORIES) - if(NOT LZ4_INCLUDE_DIR) - find_path(LZ4_INCLUDE_DIR NAMES lz4.h) - endif() - get_filename_component(LZ4_ROOT "${LZ4_INCLUDE_DIR}" DIRECTORY) set(LZ4_HOME - "${LZ4_ROOT}" + "${ORC_LZ4_ROOT}" + CACHE STRING "" FORCE) + set(LZ4_INCLUDE_DIR + "${ORC_LZ4_INCLUDE_DIR}" CACHE STRING "" FORCE) set(LZ4_LIBRARY - LZ4::lz4 + ${ORC_LZ4_TARGET} CACHE STRING "" FORCE) set(ORC_PREFER_STATIC_PROTOBUF @@ -4725,14 +4725,6 @@ function(build_orc) INTERFACE_INCLUDE_DIRECTORIES) get_filename_component(ORC_SNAPPY_ROOT "${ORC_SNAPPY_INCLUDE_DIR}" DIRECTORY) - if(LZ4_VENDORED) - set(ORC_LZ4_TARGET lz4_static) - else() - set(ORC_LZ4_TARGET LZ4::lz4) - endif() - get_target_property(ORC_LZ4_ROOT ${ORC_LZ4_TARGET} INTERFACE_INCLUDE_DIRECTORIES) - get_filename_component(ORC_LZ4_ROOT "${ORC_LZ4_ROOT}" DIRECTORY) - get_target_property(ORC_ZSTD_ROOT ${ARROW_ZSTD_LIBZSTD} INTERFACE_INCLUDE_DIRECTORIES) get_filename_component(ORC_ZSTD_ROOT "${ORC_ZSTD_ROOT}" DIRECTORY) @@ -4758,7 +4750,7 @@ function(build_orc) "-DLZ4_HOME=${ORC_LZ4_ROOT}" "-DLZ4_LIBRARY=$" "-DLZ4_STATIC_LIB=$" - "-DLZ4_INCLUDE_DIR=${ORC_LZ4_ROOT}/include" + "-DLZ4_INCLUDE_DIR=${ORC_LZ4_INCLUDE_DIR}" "-DSNAPPY_INCLUDE_DIR=${ORC_SNAPPY_INCLUDE_DIR}" "-DZSTD_HOME=${ORC_ZSTD_ROOT}" "-DZSTD_INCLUDE_DIR=$"