Skip to content

Commit

Permalink
apacheGH-38055: [C++] Don't find/use Threads::Threads with ARROW_ENAB…
Browse files Browse the repository at this point in the history
…LE_THREADING=OFF
  • Loading branch information
kou committed Oct 5, 2023
1 parent 1084382 commit f412884
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 95 deletions.
4 changes: 3 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,9 @@ endif()

set(ARROW_SYSTEM_LINK_LIBS)

list(APPEND ARROW_SYSTEM_LINK_LIBS Threads::Threads)
if(ARROW_ENABLE_THREADING)
list(APPEND ARROW_SYSTEM_LINK_LIBS Threads::Threads)
endif()
if(CMAKE_THREAD_LIBS_INIT)
string(APPEND ARROW_PC_LIBS_PRIVATE " ${CMAKE_THREAD_LIBS_INIT}")
endif()
Expand Down
192 changes: 101 additions & 91 deletions cpp/cmake_modules/ThirdpartyToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1016,8 +1016,10 @@ endmacro()
# ----------------------------------------------------------------------
# Find pthreads

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(ARROW_ENABLE_THREADING)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
endif()

# ----------------------------------------------------------------------
# Add Boost dependencies (code adapted from Apache Kudu)
Expand Down Expand Up @@ -2038,9 +2040,9 @@ macro(build_jemalloc)
# The include directory must exist before it is referenced by a target.
file(MAKE_DIRECTORY "${JEMALLOC_INCLUDE_DIR}")
add_library(jemalloc::jemalloc STATIC IMPORTED)
set_target_properties(jemalloc::jemalloc
PROPERTIES INTERFACE_LINK_LIBRARIES Threads::Threads
IMPORTED_LOCATION "${JEMALLOC_STATIC_LIB}")
set_target_properties(jemalloc::jemalloc PROPERTIES IMPORTED_LOCATION
"${JEMALLOC_STATIC_LIB}")
target_link_libraries(jemalloc::jemalloc INTERFACE Threads::Threads)
target_include_directories(jemalloc::jemalloc BEFORE
INTERFACE "${JEMALLOC_INCLUDE_DIR}")
add_dependencies(jemalloc::jemalloc jemalloc_ep)
Expand All @@ -2053,13 +2055,20 @@ macro(build_jemalloc)
endmacro()

if(ARROW_JEMALLOC)
if(NOT ARROW_ENABLE_THREADING)
message(FATAL_ERROR "Can't use jemalloc with ARROW_ENABLE_THREADING=OFF")
endif()
resolve_dependency(jemalloc HAVE_ALT TRUE)
endif()

# ----------------------------------------------------------------------
# mimalloc - Cross-platform high-performance allocator, from Microsoft

if(ARROW_MIMALLOC)
if(NOT ARROW_ENABLE_THREADING)
message(FATAL_ERROR "Can't use mimalloc with ARROW_ENABLE_THREADING=OFF")
endif()

message(STATUS "Building (vendored) mimalloc from source")
# We only use a vendored mimalloc as we want to control its build options.

Expand Down Expand Up @@ -2096,9 +2105,11 @@ if(ARROW_MIMALLOC)
file(MAKE_DIRECTORY ${MIMALLOC_INCLUDE_DIR})

add_library(mimalloc::mimalloc STATIC IMPORTED)
set_target_properties(mimalloc::mimalloc
PROPERTIES INTERFACE_LINK_LIBRARIES Threads::Threads
IMPORTED_LOCATION "${MIMALLOC_STATIC_LIB}")
set_target_properties(mimalloc::mimalloc PROPERTIES IMPORTED_LOCATION
"${MIMALLOC_STATIC_LIB}")
if(ARROW_ENABLE_THREADING)
target_link_libraries(mimalloc::mimalloc INTERFACE Threads::Threads)
endif()
target_include_directories(mimalloc::mimalloc BEFORE
INTERFACE "${MIMALLOC_INCLUDE_DIR}")
if(WIN32)
Expand Down Expand Up @@ -3899,9 +3910,9 @@ macro(build_grpc)
absl::log_severity)

add_library(gRPC::gpr STATIC IMPORTED)
set_target_properties(gRPC::gpr
PROPERTIES IMPORTED_LOCATION "${GRPC_STATIC_LIBRARY_GPR}"
INTERFACE_LINK_LIBRARIES "${GRPC_GPR_ABSL_LIBRARIES}")
set_target_properties(gRPC::gpr PROPERTIES IMPORTED_LOCATION
"${GRPC_STATIC_LIBRARY_GPR}")
target_link_libraries(gRPC::gpr INTERFACE ${GRPC_GPR_ABSL_LIBRARIES})
target_include_directories(gRPC::gpr BEFORE INTERFACE "${GRPC_INCLUDE_DIR}")

add_library(gRPC::address_sorting STATIC IMPORTED)
Expand All @@ -3918,25 +3929,23 @@ macro(build_grpc)
INTERFACE "${GRPC_INCLUDE_DIR}")

add_library(gRPC::grpc STATIC IMPORTED)
set(GRPC_LINK_LIBRARIES
gRPC::gpr
gRPC::upb
gRPC::address_sorting
re2::re2
c-ares::cares
ZLIB::ZLIB
OpenSSL::SSL
Threads::Threads)
set_target_properties(gRPC::grpc
PROPERTIES IMPORTED_LOCATION "${GRPC_STATIC_LIBRARY_GRPC}"
INTERFACE_LINK_LIBRARIES "${GRPC_LINK_LIBRARIES}")
set_target_properties(gRPC::grpc PROPERTIES IMPORTED_LOCATION
"${GRPC_STATIC_LIBRARY_GRPC}")
target_link_libraries(gRPC::grpc
INTERFACE gRPC::gpr
gRPC::upb
gRPC::address_sorting
re2::re2
c-ares::cares
ZLIB::ZLIB
OpenSSL::SSL
Threads::Threads)
target_include_directories(gRPC::grpc BEFORE INTERFACE "${GRPC_INCLUDE_DIR}")

add_library(gRPC::grpc++ STATIC IMPORTED)
set(GRPCPP_LINK_LIBRARIES gRPC::grpc ${ARROW_PROTOBUF_LIBPROTOBUF})
set_target_properties(gRPC::grpc++
PROPERTIES IMPORTED_LOCATION "${GRPC_STATIC_LIBRARY_GRPCPP}"
INTERFACE_LINK_LIBRARIES "${GRPCPP_LINK_LIBRARIES}")
set_target_properties(gRPC::grpc++ PROPERTIES IMPORTED_LOCATION
"${GRPC_STATIC_LIBRARY_GRPCPP}")
target_link_libraries(gRPC::grpc++ INTERFACE gRPC::grpc ${ARROW_PROTOBUF_LIBPROTOBUF})
target_include_directories(gRPC::grpc++ BEFORE INTERFACE "${GRPC_INCLUDE_DIR}")

add_executable(gRPC::grpc_cpp_plugin IMPORTED)
Expand Down Expand Up @@ -3983,6 +3992,10 @@ macro(build_grpc)
endmacro()

if(ARROW_WITH_GRPC)
if(NOT ARROW_ENABLE_THREADING)
message(FATAL_ERROR "Can't use gRPC with ARROW_ENABLE_THREADING=OFF")
endif()

set(ARROW_GRPC_REQUIRED_VERSION "1.30.0")
if(NOT Protobuf_SOURCE STREQUAL gRPC_SOURCE)
# ARROW-15495: Protobuf/gRPC must come from the same source
Expand Down Expand Up @@ -4201,32 +4214,30 @@ macro(build_google_cloud_cpp_storage)
# (subsitute `main` for the SHA of the version we use)
# Version 1.39.0 is at a different place (they refactored after):
# https://github.com/googleapis/google-cloud-cpp/blob/29e5af8ca9b26cec62106d189b50549f4dc1c598/google/cloud/CMakeLists.txt#L146-L155
set_property(TARGET google-cloud-cpp::common
PROPERTY INTERFACE_LINK_LIBRARIES
absl::base
absl::cord
absl::memory
absl::optional
absl::span
absl::time
absl::variant
Threads::Threads
OpenSSL::Crypto)
target_link_libraries(google-cloud-cpp::common
INTERFACE absl::base
absl::cord
absl::memory
absl::optional
absl::span
absl::time
absl::variant
Threads::Threads
OpenSSL::Crypto)

add_library(google-cloud-cpp::rest-internal STATIC IMPORTED)
set_target_properties(google-cloud-cpp::rest-internal
PROPERTIES IMPORTED_LOCATION
"${GOOGLE_CLOUD_CPP_STATIC_LIBRARY_REST_INTERNAL}")
target_include_directories(google-cloud-cpp::rest-internal BEFORE
INTERFACE "${GOOGLE_CLOUD_CPP_INCLUDE_DIR}")
set_property(TARGET google-cloud-cpp::rest-internal
PROPERTY INTERFACE_LINK_LIBRARIES
absl::span
google-cloud-cpp::common
CURL::libcurl
nlohmann_json::nlohmann_json
OpenSSL::SSL
OpenSSL::Crypto)
target_link_libraries(google-cloud-cpp::rest-internal
INTERFACE absl::span
google-cloud-cpp::common
CURL::libcurl
nlohmann_json::nlohmann_json
OpenSSL::SSL
OpenSSL::Crypto)

add_library(google-cloud-cpp::storage STATIC IMPORTED)
set_target_properties(google-cloud-cpp::storage
Expand All @@ -4235,22 +4246,21 @@ macro(build_google_cloud_cpp_storage)
target_include_directories(google-cloud-cpp::storage BEFORE
INTERFACE "${GOOGLE_CLOUD_CPP_INCLUDE_DIR}")
# Update this from https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/storage/google_cloud_cpp_storage.cmake
set_property(TARGET google-cloud-cpp::storage
PROPERTY INTERFACE_LINK_LIBRARIES
google-cloud-cpp::common
google-cloud-cpp::rest-internal
absl::memory
absl::strings
absl::str_format
absl::time
absl::variant
nlohmann_json::nlohmann_json
Crc32c::crc32c
CURL::libcurl
Threads::Threads
OpenSSL::SSL
OpenSSL::Crypto
ZLIB::ZLIB)
target_link_libraries(google-cloud-cpp::storage
INTERFACE google-cloud-cpp::common
google-cloud-cpp::rest-internal
absl::memory
absl::strings
absl::str_format
absl::time
absl::variant
nlohmann_json::nlohmann_json
Crc32c::crc32c
CURL::libcurl
Threads::Threads
OpenSSL::SSL
OpenSSL::Crypto
ZLIB::ZLIB)
add_dependencies(google-cloud-cpp::storage google_cloud_cpp_ep)

list(APPEND
Expand Down Expand Up @@ -4297,6 +4307,11 @@ macro(build_google_cloud_cpp_storage)
endmacro()

if(ARROW_WITH_GOOGLE_CLOUD_CPP)
if(NOT ARROW_ENABLE_THREADING)
message(FATAL_ERROR "Can't use Google Cloud Platform C++ Client Libraries with ARROW_ENABLE_THREADING=OFF"
)
endif()

resolve_dependency(google_cloud_cpp_storage PC_PACKAGE_NAMES google_cloud_cpp_storage)
get_target_property(google_cloud_cpp_storage_INCLUDE_DIR google-cloud-cpp::storage
INTERFACE_INCLUDE_DIRECTORIES)
Expand Down Expand Up @@ -4403,7 +4418,7 @@ macro(build_orc)
list(APPEND ORC_LINK_LIBRARIES absl::log_internal_check_op)
endif()
if(NOT MSVC)
if(NOT APPLE)
if(NOT APPLE AND ARROW_ENABLE_THREADING)
list(APPEND ORC_LINK_LIBRARIES Threads::Threads)
endif()
list(APPEND ORC_LINK_LIBRARIES ${CMAKE_DL_LIBS})
Expand Down Expand Up @@ -4582,34 +4597,25 @@ macro(build_opentelemetry)

set(OPENTELEMETRY_VENDORED 1)

set_target_properties(opentelemetry-cpp::common
PROPERTIES INTERFACE_LINK_LIBRARIES
"opentelemetry-cpp::api;opentelemetry-cpp::sdk;Threads::Threads"
)
set_target_properties(opentelemetry-cpp::resources
PROPERTIES INTERFACE_LINK_LIBRARIES "opentelemetry-cpp::common")
set_target_properties(opentelemetry-cpp::trace
PROPERTIES INTERFACE_LINK_LIBRARIES
"opentelemetry-cpp::common;opentelemetry-cpp::resources"
)
set_target_properties(opentelemetry-cpp::http_client_curl
PROPERTIES INTERFACE_LINK_LIBRARIES
"opentelemetry-cpp::ext;CURL::libcurl")
set_target_properties(opentelemetry-cpp::proto
PROPERTIES INTERFACE_LINK_LIBRARIES
"${ARROW_PROTOBUF_LIBPROTOBUF}")
set_target_properties(opentelemetry-cpp::otlp_recordable
PROPERTIES INTERFACE_LINK_LIBRARIES
"opentelemetry-cpp::trace;opentelemetry-cpp::resources;opentelemetry-cpp::proto"
)
set_target_properties(opentelemetry-cpp::otlp_http_client
PROPERTIES INTERFACE_LINK_LIBRARIES
"opentelemetry-cpp::sdk;opentelemetry-cpp::proto;opentelemetry-cpp::http_client_curl;nlohmann_json::nlohmann_json"
)
set_target_properties(opentelemetry-cpp::otlp_http_exporter
PROPERTIES INTERFACE_LINK_LIBRARIES
"opentelemetry-cpp::otlp_recordable;opentelemetry-cpp::otlp_http_client"
)
target_link_libraries(opentelemetry-cpp::common
INTERFACE opentelemetry-cpp::api opentelemetry-cpp::sdk
Threads::Threads)
target_link_libraries(opentelemetry-cpp::resources INTERFACE opentelemetry-cpp::common)
target_link_libraries(opentelemetry-cpp::trace INTERFACE opentelemetry-cpp::common
opentelemetry-cpp::resources)
target_link_libraries(opentelemetry-cpp::http_client_curl
INTERFACE opentelemetry-cpp::ext CURL::libcurl)
target_link_libraries(opentelemetry-cpp::proto INTERFACE ${ARROW_PROTOBUF_LIBPROTOBUF})
target_link_libraries(opentelemetry-cpp::otlp_recordable
INTERFACE opentelemetry-cpp::trace opentelemetry-cpp::resources
opentelemetry-cpp::proto)
target_link_libraries(opentelemetry-cpp::otlp_http_client
INTERFACE opentelemetry-cpp::sdk opentelemetry-cpp::proto
opentelemetry-cpp::http_client_curl
nlohmann_json::nlohmann_json)
target_link_libraries(opentelemetry-cpp::otlp_http_exporter
INTERFACE opentelemetry-cpp::otlp_recordable
opentelemetry-cpp::otlp_http_client)

foreach(_OPENTELEMETRY_LIB ${_OPENTELEMETRY_LIBS})
add_dependencies(opentelemetry-cpp::${_OPENTELEMETRY_LIB} opentelemetry_ep)
Expand All @@ -4621,6 +4627,10 @@ macro(build_opentelemetry)
endmacro()

if(ARROW_WITH_OPENTELEMETRY)
if(NOT ARROW_ENABLE_THREADING)
message(FATAL_ERROR "Can't use OpenTelemetry with ARROW_ENABLE_THREADING=OFF")
endif()

# cURL is required whether we build from source or use an existing installation
# (OTel's cmake files do not call find_curl for you)
find_curl()
Expand Down
8 changes: 5 additions & 3 deletions cpp/src/arrow/ArrowConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ endmacro()
if(ARROW_BUILD_STATIC)
include(CMakeFindDependencyMacro)

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_dependency(Threads)
if(ARROW_ENABLE_THREADING)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_dependency(Threads)
endif()

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

0 comments on commit f412884

Please sign in to comment.