Skip to content

Commit

Permalink
apacheGH-37352: [C++] Don't put all dependencies to ArrowConfig.cmake…
Browse files Browse the repository at this point in the history
…/arrow.pc

Split Flight related dependencies such as gRPC to
ArrowFlightConfig.cmake/arrow-flight.pc from ArrowConfig.cmake/arrow.pc.

Split Parquet related dependencies such as Thrift to
ParquetConfig.cmake/parquet.pc from ArrowConfig.cmake/arrow.pc.
  • Loading branch information
kou committed Aug 26, 2023
1 parent c9bfca5 commit e352564
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 70 deletions.
6 changes: 6 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,18 @@ set(ARROW_PC_CFLAGS_PRIVATE " -DARROW_STATIC")
set(ARROW_PC_LIBS_PRIVATE "")
set(ARROW_PC_REQUIRES_PRIVATE "")

# For arrow-flight.pc.
set(ARROW_FLIGHT_PC_REQUIRES_PRIVATE "")

# For arrow-testing.pc.
set(ARROW_TESTING_PC_CFLAGS "")
set(ARROW_TESTING_PC_CFLAGS_PRIVATE " -DARROW_TESTING_STATIC")
set(ARROW_TESTING_PC_LIBS "")
set(ARROW_TESTING_PC_REQUIRES "")

# For parquet.pc.
set(PARQUET_PC_REQUIRES_PRIVATE "")

include(ThirdpartyToolchain)

# Add common flags
Expand Down
108 changes: 80 additions & 28 deletions cpp/cmake_modules/ThirdpartyToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ set(ARROW_BUNDLED_STATIC_LIBS)
# Accumulate all system dependencies to provide suitable static link
# parameters to the third party libraries.
set(ARROW_SYSTEM_DEPENDENCIES)
set(ARROW_FLIGHT_SYSTEM_DEPENDENCIES)
set(ARROW_TESTING_SYSTEM_DEPENDENCIES)
set(PARQUET_SYSTEM_DEPENDENCIES)

# ----------------------------------------------------------------------
# Toolchain linkage options
Expand Down Expand Up @@ -233,6 +236,7 @@ macro(resolve_dependency DEPENDENCY_NAME)
set(options)
set(one_value_args
ARROW_CMAKE_PACKAGE_NAME
ARROW_PC_PACKAGE_NAME
FORCE_ANY_NEWER_VERSION
HAVE_ALT
IS_RUNTIME_DEPENDENCY
Expand Down Expand Up @@ -297,12 +301,26 @@ macro(resolve_dependency DEPENDENCY_NAME)
if(NOT ARG_ARROW_CMAKE_PACKAGE_NAME)
set(ARG_ARROW_CMAKE_PACKAGE_NAME "Arrow")
endif()
if(ARG_ARROW_CMAKE_PACKAGE_NAME STREQUAL "Arrow")
provide_find_module(${PACKAGE_NAME} "Arrow")
list(APPEND ARROW_SYSTEM_DEPENDENCIES ${PACKAGE_NAME})
else()
provide_find_module(${PACKAGE_NAME} ${ARG_ARROW_CMAKE_PACKAGE_NAME})
# ArrowFlight -> _Arrow_Flight
string(REGEX REPLACE "([A-Z])" "_\\1" ARG_ARROW_CMAKE_PACKAGE_NAME_SNAKE
${ARG_ARROW_CMAKE_PACKAGE_NAME})
# _Arrow_Flight -> Arrow_Flight
string(SUBSTRING ${ARG_ARROW_CMAKE_PACKAGE_NAME_SNAKE} 1 -1
ARG_ARROW_CMAKE_PACKAGE_NAME_SNAKE)
# Arrow_Flight -> ARROW_FLIGHT
string(TOUPPER ${ARG_ARROW_CMAKE_PACKAGE_NAME_SNAKE}
ARG_ARROW_CMAKE_PACKAGE_NAME_UPPER_SNAKE)
provide_find_module(${PACKAGE_NAME} ${ARG_ARROW_CMAKE_PACKAGE_NAME})
list(APPEND ${ARG_ARROW_CMAKE_PACKAGE_NAME_UPPER_SNAKE}_SYSTEM_DEPENDENCIES
${PACKAGE_NAME})
if(NOT ARG_ARROW_PC_PACKAGE_NAME)
set(ARG_ARROW_PC_PACKAGE_NAME "arrow")
endif()
# arrow-flight -> arrow_flight
string(REPLACE "-" "_" ARG_ARROW_PC_PACKAGE_NAME_SNAKE ${ARG_ARROW_PC_PACKAGE_NAME})
# arrow_flight -> ARROW_FLIGHT
string(TOUPPER ${ARG_ARROW_PC_PACKAGE_NAME_SNAKE}
ARG_ARROW_PC_PACKAGE_NAME_UPPER_SNAKE)
if(ARROW_BUILD_STATIC)
find_package(PkgConfig QUIET)
foreach(ARG_PC_PACKAGE_NAME ${ARG_PC_PACKAGE_NAMES})
Expand All @@ -311,13 +329,16 @@ macro(resolve_dependency DEPENDENCY_NAME)
NO_CMAKE_PATH
NO_CMAKE_ENVIRONMENT_PATH
QUIET)
set(RESOLVE_DEPENDENCY_PC_PACKAGE
"pkg-config package for ${ARG_PC_PACKAGE_NAME} ")
string(APPEND RESOLVE_DEPENDENCY_PC_PACKAGE
"that is used by ${ARG_ARROW_PC_PACKAGE_NAME} for static link")
if(${${ARG_PC_PACKAGE_NAME}_PC_FOUND})
message(STATUS "Using pkg-config package for ${ARG_PC_PACKAGE_NAME} for static link"
)
string(APPEND ARROW_PC_REQUIRES_PRIVATE " ${ARG_PC_PACKAGE_NAME}")
message(STATUS "Using ${RESOLVE_DEPENDENCY_PC_PACKAGE}")
string(APPEND ${ARG_ARROW_PC_PACKAGE_NAME_UPPER_SNAKE}_PC_REQUIRES_PRIVATE
" ${ARG_PC_PACKAGE_NAME}")
else()
message(STATUS "pkg-config package for ${ARG_PC_PACKAGE_NAME} for static link isn't found"
)
message(STATUS "${RESOLVE_DEPENDENCY_PC_PACKAGE} isn't found")
endif()
endforeach()
endif()
Expand Down Expand Up @@ -1614,12 +1635,16 @@ endmacro()
if(ARROW_WITH_THRIFT)
# Thrift C++ code generated by 0.13 requires 0.11 or greater
resolve_dependency(Thrift
ARROW_CMAKE_PACKAGE_NAME
Parquet
ARROW_PC_PACKAGE_NAME
parquet
HAVE_ALT
TRUE
REQUIRED_VERSION
0.11.0
PC_PACKAGE_NAMES
thrift)
thrift
REQUIRED_VERSION
0.11.0)

string(REPLACE "." ";" Thrift_VERSION_LIST ${Thrift_VERSION})
list(GET Thrift_VERSION_LIST 0 Thrift_VERSION_MAJOR)
Expand Down Expand Up @@ -1715,6 +1740,13 @@ if(ARROW_WITH_PROTOBUF)
else()
set(ARROW_PROTOBUF_REQUIRED_VERSION "2.6.1")
endif()
if(ARROW_FLIGHT)
set(ARROW_PROTOBUF_ARROW_CMAKE_PACKAGE_NAME "ArrowFlight")
set(ARROW_PROTOBUF_ARROW_PC_PACKAGE_NAME "arrow-flight")
else()
set(ARROW_PROTOBUF_ARROW_CMAKE_PACKAGE_NAME "Arrow")
set(ARROW_PROTOBUF_ARROW_PC_PACKAGE_NAME "arrow")
endif()
# We need to use FORCE_ANY_NEWER_VERSION here to accept Protobuf
# newer version such as 23.4. If we don't use it, 23.4 is processed
# as an incompatible version with 3.12.0 with protobuf-config.cmake
Expand All @@ -1724,14 +1756,18 @@ if(ARROW_WITH_PROTOBUF)
# we use FORCE_ANY_NEWER_VERSION here, we can bypass the check and
# use 23.4.
resolve_dependency(Protobuf
ARROW_CMAKE_PACKAGE_NAME
${ARROW_PROTOBUF_ARROW_CMAKE_PACKAGE_NAME}
ARROW_PC_PACKAGE_NAME
${ARROW_PROTOBUF_ARROW_PC_PACKAGE_NAME}
FORCE_ANY_NEWER_VERSION
TRUE
HAVE_ALT
TRUE
REQUIRED_VERSION
${ARROW_PROTOBUF_REQUIRED_VERSION}
PC_PACKAGE_NAMES
protobuf)
protobuf
REQUIRED_VERSION
${ARROW_PROTOBUF_REQUIRED_VERSION})

if(NOT Protobuf_USE_STATIC_LIBS AND MSVC_TOOLCHAIN)
add_definitions(-DPROTOBUF_USE_DLLS)
Expand Down Expand Up @@ -2167,12 +2203,12 @@ endmacro()
if(ARROW_TESTING)
set(GTestAlt_NEED_CXX_STANDARD_CHECK TRUE)
resolve_dependency(GTest
ARROW_CMAKE_PACKAGE_NAME
ArrowTesting
HAVE_ALT
TRUE
REQUIRED_VERSION
1.10.0
ARROW_CMAKE_PACKAGE_NAME
"ArrowTesting")
1.10.0)

if(GTest_SOURCE STREQUAL "SYSTEM")
find_package(PkgConfig QUIET)
Expand Down Expand Up @@ -2351,10 +2387,12 @@ endif()

if(ARROW_USE_XSIMD)
resolve_dependency(xsimd
FORCE_ANY_NEWER_VERSION
TRUE
REQUIRED_VERSION
"8.1.0"
FORCE_ANY_NEWER_VERSION
TRUE)
PC_PACKAGE_NAMES
xsimd)

if(xsimd_SOURCE STREQUAL "BUNDLED")
add_library(arrow::xsimd INTERFACE IMPORTED)
Expand Down Expand Up @@ -2678,10 +2716,10 @@ endmacro()

if(ARROW_WITH_UTF8PROC)
resolve_dependency(utf8proc
REQUIRED_VERSION
"2.2.0"
PC_PACKAGE_NAMES
libutf8proc)
libutf8proc
REQUIRED_VERSION
"2.2.0")
add_definitions(-DARROW_WITH_UTF8PROC)
endif()

Expand Down Expand Up @@ -3694,6 +3732,10 @@ endmacro()

macro(build_grpc)
resolve_dependency(c-ares
ARROW_CMAKE_PACKAGE_NAME
ArrowFlight
ARROW_PC_PACKAGE_NAME
arrow-flight
HAVE_ALT
TRUE
PC_PACKAGE_NAMES
Expand Down Expand Up @@ -3998,12 +4040,16 @@ if(ARROW_WITH_GRPC)
set(gRPC_SOURCE "${Protobuf_SOURCE}")
endif()
resolve_dependency(gRPC
ARROW_CMAKE_PACKAGE_NAME
ArrowFlight
ARROW_PC_PACKAGE_NAME
arrow-flight
HAVE_ALT
TRUE
REQUIRED_VERSION
${ARROW_GRPC_REQUIRED_VERSION}
PC_PACKAGE_NAMES
grpc++)
grpc++
REQUIRED_VERSION
${ARROW_GRPC_REQUIRED_VERSION})

if(GRPC_VENDORED)
# Remove "v" from "vX.Y.Z"
Expand Down Expand Up @@ -5119,7 +5165,13 @@ macro(build_ucx)
endmacro()

if(ARROW_WITH_UCX)
resolve_dependency(ucx PC_PACKAGE_NAMES ucx)
resolve_dependency(ucx
ARROW_CMAKE_PACKAGE_NAME
ArrowFlight
ARROW_PC_PACKAGE_NAME
arrow-flight
PC_PACKAGE_NAMES
ucx)
add_library(ucx::ucx INTERFACE IMPORTED)
target_include_directories(ucx::ucx INTERFACE "${UCX_INCLUDE_DIRS}")
target_link_libraries(ucx::ucx INTERFACE ucx::ucp ucx::uct ucx::ucs)
Expand Down
24 changes: 14 additions & 10 deletions cpp/src/arrow/ArrowConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,17 @@ set(ARROW_SYSTEM_DEPENDENCIES "@ARROW_SYSTEM_DEPENDENCIES@")

include("${CMAKE_CURRENT_LIST_DIR}/ArrowOptions.cmake")

if(ARROW_BUILD_STATIC)
include(CMakeFindDependencyMacro)

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_dependency(Threads)

macro(arrow_find_dependencies dependencies)
if(DEFINED CMAKE_MODULE_PATH)
set(ARROW_CMAKE_MODULE_PATH_OLD ${CMAKE_MODULE_PATH})
else()
unset(ARROW_CMAKE_MODULE_PATH_OLD)
endif()
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")

foreach(_DEPENDENCY ${ARROW_SYSTEM_DEPENDENCIES})
foreach(dependency ${dependencies})
set(ARROW_OPENSSL_HOMEBREW_MAKE_DETECTABLE FALSE)
if(${_DEPENDENCY} STREQUAL "OpenSSL" AND NOT OPENSSL_ROOT_DIR)
if(${dependency} STREQUAL "OpenSSL" AND NOT OPENSSL_ROOT_DIR)
find_program(ARROW_BREW brew)
if(ARROW_BREW)
set(ARROW_OPENSSL_ROOT_DIR_ORIGINAL ${OPENSSL_ROOT_DIR})
Expand All @@ -78,7 +72,7 @@ if(ARROW_BUILD_STATIC)
endif()
endif()
endif()
find_dependency(${_DEPENDENCY})
find_dependency(${dependency})
if(ARROW_OPENSSL_HOMEBREW_MAKE_DETECTABLE)
set(OPENSSL_ROOT_DIR ${ARROW_OPENSSL_ROOT_DIR_ORIGINAL})
endif()
Expand All @@ -90,6 +84,16 @@ if(ARROW_BUILD_STATIC)
else()
unset(CMAKE_MODULE_PATH)
endif()
endmacro()

if(ARROW_BUILD_STATIC)
include(CMakeFindDependencyMacro)

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_dependency(Threads)

arrow_find_dependencies("${ARROW_SYSTEM_DEPENDENCIES}")
endif()

include("${CMAKE_CURRENT_LIST_DIR}/ArrowTargets.cmake")
Expand Down
18 changes: 2 additions & 16 deletions cpp/src/arrow/ArrowTestingConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,12 @@

@PACKAGE_INIT@

set(ARROW_GTEST_SOURCE "@GTest_SOURCE@")
set(ARROW_TESTING_SYSTEM_DEPENDENCIES "@ARROW_TESTING_SYSTEM_DEPENDENCIES@")

include(CMakeFindDependencyMacro)
find_dependency(Arrow)

if(DEFINED CMAKE_MODULE_PATH)
set(ARROW_TESTING_CMAKE_MODULE_PATH_OLD ${CMAKE_MODULE_PATH})
else()
unset(ARROW_TESTING_CMAKE_MODULE_PATH_OLD)
endif()
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
if("${ARROW_GTEST_SOURCE}" STREQUAL "SYSTEM")
find_dependency(GTestAlt)
endif()
if(DEFINED ARROW_TESTING_CMAKE_MODULE_PATH_OLD)
set(CMAKE_MODULE_PATH ${ARROW_TESTING_CMAKE_MODULE_PATH_OLD})
unset(ARROW_TESTING_CMAKE_MODULE_PATH_OLD)
else()
unset(CMAKE_MODULE_PATH)
endif()
arrow_find_dependencies("${ARROW_TESTING_SYSTEM_DEPENDENCIES}")

include("${CMAKE_CURRENT_LIST_DIR}/ArrowTestingTargets.cmake")

Expand Down
6 changes: 6 additions & 0 deletions cpp/src/arrow/flight/ArrowFlightConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@

@PACKAGE_INIT@

set(ARROW_FLIGHT_SYSTEM_DEPENDENCIES "@ARROW_FLIGHT_SYSTEM_DEPENDENCIES@")

include(CMakeFindDependencyMacro)
find_dependency(Arrow)

if(ARROW_BUILD_STATIC)
arrow_find_dependencies("${ARROW_FLIGHT_SYSTEM_DEPENDENCIES}")
endif()

include("${CMAKE_CURRENT_LIST_DIR}/ArrowFlightTargets.cmake")

arrow_keep_backward_compatibility(ArrowFlight arrow_flight)
Expand Down
1 change: 1 addition & 0 deletions cpp/src/arrow/flight/arrow-flight.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ Name: Apache Arrow Flight
Description: Apache Arrow's RPC system built on gRPC
Version: @ARROW_VERSION@
Requires: arrow
Requires.private:@ARROW_FLIGHT_PC_REQUIRES_PRIVATE@
Libs: -L${libdir} -larrow_flight
Cflags.private: -DARROW_FLIGHT_STATIC
6 changes: 6 additions & 0 deletions cpp/src/parquet/ParquetConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@

@PACKAGE_INIT@

set(PARQUET_SYSTEM_DEPENDENCIES "@PARQUET_FLIGHT_SYSTEM_DEPENDENCIES@")

include(CMakeFindDependencyMacro)
find_dependency(Arrow)

if(ARROW_BUILD_STATIC)
arrow_find_dependencies("${PARQUET_SYSTEM_DEPENDENCIES}")
endif()

set(PARQUET_VERSION "@ARROW_VERSION@")
set(PARQUET_SO_VERSION "@ARROW_SO_VERSION@")
set(PARQUET_FULL_SO_VERSION "@ARROW_FULL_SO_VERSION@")
Expand Down
1 change: 1 addition & 0 deletions cpp/src/parquet/parquet.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Name: Apache Parquet
Description: Apache Parquet is a columnar storage format.
Version: @ARROW_VERSION@
Requires: arrow
Requires.private:@PARQUET_PC_REQUIRES_PRIVATE@
Libs: -L${libdir} -lparquet
Cflags: -I${includedir}
Cflags.private: -DPARQUET_STATIC
2 changes: 1 addition & 1 deletion dev/release/verify-apt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pushd build/minimal_build
cmake .
make -j$(nproc)
./arrow-example
c++ -std=c++17 -o arrow-example example.cc $(pkg-config --cflags --libs arrow)
c++ -o arrow-example example.cc $(pkg-config --cflags --libs arrow) -std=c++17
./arrow-example
popd
echo "::endgroup::"
Expand Down
2 changes: 1 addition & 1 deletion dev/release/verify-yum.sh
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pushd build/minimal_build
${cmake_command} .
make -j$(nproc)
./arrow-example
c++ -std=c++17 -o arrow-example example.cc $(pkg-config --cflags --libs arrow)
c++ -o arrow-example example.cc $(pkg-config --cflags --libs arrow) -std=c++17
./arrow-example
popd
echo "::endgroup::"
Expand Down
Loading

0 comments on commit e352564

Please sign in to comment.