From f412884e09d5d4152fa9360e2dbb0bc45a128c10 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Fri, 6 Oct 2023 06:11:30 +0900 Subject: [PATCH] GH-38055: [C++] Don't find/use Threads::Threads with ARROW_ENABLE_THREADING=OFF --- cpp/CMakeLists.txt | 4 +- cpp/cmake_modules/ThirdpartyToolchain.cmake | 192 ++++++++++---------- cpp/src/arrow/ArrowConfig.cmake.in | 8 +- 3 files changed, 109 insertions(+), 95 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index f0acab0389b19..8566508406bd4 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -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() diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake index 6d6a2bf7751ee..25ed090224b7d 100644 --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake @@ -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) @@ -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) @@ -2053,6 +2055,9 @@ 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() @@ -2060,6 +2065,10 @@ 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. @@ -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) @@ -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) @@ -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) @@ -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 @@ -4201,17 +4214,16 @@ 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 @@ -4219,14 +4231,13 @@ macro(build_google_cloud_cpp_storage) "${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 @@ -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 @@ -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) @@ -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}) @@ -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) @@ -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() diff --git a/cpp/src/arrow/ArrowConfig.cmake.in b/cpp/src/arrow/ArrowConfig.cmake.in index 7bd19fb41a31f..27910b3f3c311 100644 --- a/cpp/src/arrow/ArrowConfig.cmake.in +++ b/cpp/src/arrow/ArrowConfig.cmake.in @@ -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()