Skip to content

Commit 6b3444f

Browse files
committed
ARROW-15066: [C++] Enable use of OpenTelemetry from conda-forge
1 parent 11d2e48 commit 6b3444f

1 file changed

Lines changed: 42 additions & 32 deletions

File tree

‎cpp/cmake_modules/ThirdpartyToolchain.cmake‎

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ set(ARROW_THIRDPARTY_DEPENDENCIES
6363
GTest
6464
LLVM
6565
Lz4
66+
nlohmann_json
6667
opentelemetry-cpp
6768
ORC
6869
re2
@@ -162,6 +163,8 @@ macro(build_dependency DEPENDENCY_NAME)
162163
build_gtest()
163164
elseif("${DEPENDENCY_NAME}" STREQUAL "Lz4")
164165
build_lz4()
166+
elseif("${DEPENDENCY_NAME}" STREQUAL "nlohmann_json")
167+
build_nlohmann_json()
165168
elseif("${DEPENDENCY_NAME}" STREQUAL "opentelemetry-cpp")
166169
build_opentelemetry()
167170
elseif("${DEPENDENCY_NAME}" STREQUAL "ORC")
@@ -276,6 +279,7 @@ if(PARQUET_REQUIRE_ENCRYPTION)
276279
endif()
277280

278281
if(ARROW_WITH_OPENTELEMETRY)
282+
set(ARROW_WITH_NLOHMANN_JSON ON)
279283
set(ARROW_WITH_PROTOBUF ON)
280284
endif()
281285

@@ -304,6 +308,7 @@ endif()
304308

305309
if(ARROW_GCS)
306310
set(ARROW_WITH_GOOGLE_CLOUD_CPP ON)
311+
set(ARROW_WITH_NLOHMANN_JSON ON)
307312
endif()
308313

309314
if(ARROW_JSON)
@@ -3749,36 +3754,42 @@ macro(build_crc32c_once)
37493754
endif()
37503755
endmacro()
37513756

3752-
macro(build_nlohmann_json_once)
3753-
if(NOT TARGET nlohmann_json_ep)
3754-
message(STATUS "Building nlohmann-json from source")
3755-
# "Build" nlohmann-json
3756-
set(NLOHMANN_JSON_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/nlohmann_json_ep-install")
3757-
set(NLOHMANN_JSON_INCLUDE_DIR "${NLOHMANN_JSON_PREFIX}/include")
3758-
set(NLOHMANN_JSON_CMAKE_ARGS
3759-
${EP_COMMON_CMAKE_ARGS} "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
3760-
-DBUILD_TESTING=OFF -DJSON_BuildTests=OFF)
3757+
macro(build_nlohmann_json)
3758+
message(STATUS "Building nlohmann-json from source")
3759+
# "Build" nlohmann-json
3760+
set(NLOHMANN_JSON_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/nlohmann_json_ep-install")
3761+
set(NLOHMANN_JSON_INCLUDE_DIR "${NLOHMANN_JSON_PREFIX}/include")
3762+
set(NLOHMANN_JSON_CMAKE_ARGS
3763+
${EP_COMMON_CMAKE_ARGS} "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>" -DBUILD_TESTING=OFF
3764+
-DJSON_BuildTests=OFF)
37613765

3762-
set(NLOHMANN_JSON_BUILD_BYPRODUCTS ${NLOHMANN_JSON_PREFIX}/include/nlohmann/json.hpp)
3766+
set(NLOHMANN_JSON_BUILD_BYPRODUCTS ${NLOHMANN_JSON_PREFIX}/include/nlohmann/json.hpp)
37633767

3764-
externalproject_add(nlohmann_json_ep
3765-
${EP_LOG_OPTIONS}
3766-
INSTALL_DIR ${NLOHMANN_JSON_PREFIX}
3767-
URL ${NLOHMANN_JSON_SOURCE_URL}
3768-
URL_HASH "SHA256=${ARROW_NLOHMANN_JSON_BUILD_SHA256_CHECKSUM}"
3769-
CMAKE_ARGS ${NLOHMANN_JSON_CMAKE_ARGS}
3770-
BUILD_BYPRODUCTS ${NLOHMANN_JSON_BUILD_BYPRODUCTS})
3768+
externalproject_add(nlohmann_json_ep
3769+
${EP_LOG_OPTIONS}
3770+
INSTALL_DIR ${NLOHMANN_JSON_PREFIX}
3771+
URL ${NLOHMANN_JSON_SOURCE_URL}
3772+
URL_HASH "SHA256=${ARROW_NLOHMANN_JSON_BUILD_SHA256_CHECKSUM}"
3773+
CMAKE_ARGS ${NLOHMANN_JSON_CMAKE_ARGS}
3774+
BUILD_BYPRODUCTS ${NLOHMANN_JSON_BUILD_BYPRODUCTS})
37713775

3772-
# Work around https://gitlab.kitware.com/cmake/cmake/issues/15052
3773-
file(MAKE_DIRECTORY ${NLOHMANN_JSON_INCLUDE_DIR})
3776+
# Work around https://gitlab.kitware.com/cmake/cmake/issues/15052
3777+
file(MAKE_DIRECTORY ${NLOHMANN_JSON_INCLUDE_DIR})
37743778

3775-
add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED)
3776-
set_target_properties(nlohmann_json::nlohmann_json
3777-
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
3778-
"${NLOHMANN_JSON_INCLUDE_DIR}")
3779-
add_dependencies(nlohmann_json::nlohmann_json nlohmann_json_ep)
3780-
endif()
3779+
add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED)
3780+
set_target_properties(nlohmann_json::nlohmann_json
3781+
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
3782+
"${NLOHMANN_JSON_INCLUDE_DIR}")
3783+
add_dependencies(nlohmann_json::nlohmann_json nlohmann_json_ep)
37813784
endmacro()
3785+
if(ARROW_WITH_NLOHMANN_JSON)
3786+
set(nlohmann_json_SOURCE "AUTO")
3787+
resolve_dependency(nlohmann_json)
3788+
get_target_property(nlohmann_json_INCLUDE_DIR nlohmann_json::nlohmann_json
3789+
INTERFACE_INCLUDE_DIRECTORIES)
3790+
include_directories(SYSTEM ${nlohmann_json_INCLUDE_DIR})
3791+
message(STATUS "Found nlohmann_json headers: ${nlohmann_json_INCLUDE_DIR}")
3792+
endif()
37823793

37833794
macro(build_google_cloud_cpp_storage)
37843795
message(STATUS "Building google-cloud-cpp from source")
@@ -3787,7 +3798,6 @@ macro(build_google_cloud_cpp_storage)
37873798
# List of dependencies taken from https://github.com/googleapis/google-cloud-cpp/blob/master/doc/packaging.md
37883799
build_absl_once()
37893800
build_crc32c_once()
3790-
build_nlohmann_json_once()
37913801

37923802
# Curl is required on all platforms, but building it internally might also trip over S3's copy.
37933803
# For now, force its inclusion from the underlying system or fail.
@@ -3827,7 +3837,7 @@ macro(build_google_cloud_cpp_storage)
38273837

38283838
add_dependencies(google_cloud_cpp_dependencies absl_ep)
38293839
add_dependencies(google_cloud_cpp_dependencies crc32c_ep)
3830-
add_dependencies(google_cloud_cpp_dependencies nlohmann_json_ep)
3840+
add_dependencies(google_cloud_cpp_dependencies nlohmann_json::nlohmann_json)
38313841

38323842
set(GOOGLE_CLOUD_CPP_STATIC_LIBRARY_STORAGE
38333843
"${GOOGLE_CLOUD_CPP_INSTALL_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}google_cloud_cpp_storage${CMAKE_STATIC_LIBRARY_SUFFIX}"
@@ -4020,9 +4030,6 @@ endif()
40204030
macro(build_opentelemetry)
40214031
message(STATUS "Building OpenTelemetry from source")
40224032

4023-
build_nlohmann_json_once()
4024-
find_curl()
4025-
40264033
set(OPENTELEMETRY_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/opentelemetry_ep-install")
40274034
set(OPENTELEMETRY_INCLUDE_DIR "${OPENTELEMETRY_PREFIX}/include")
40284035
set(OPENTELEMETRY_STATIC_LIB
@@ -4130,8 +4137,8 @@ macro(build_opentelemetry)
41304137
INSTALL_COMMAND ""
41314138
EXCLUDE_FROM_ALL OFF)
41324139

4133-
add_dependencies(opentelemetry_dependencies nlohmann_json_ep opentelemetry_proto_ep
4134-
${ARROW_PROTOBUF_LIBPROTOBUF})
4140+
add_dependencies(opentelemetry_dependencies nlohmann_json::nlohmann_json
4141+
opentelemetry_proto_ep ${ARROW_PROTOBUF_LIBPROTOBUF})
41354142

41364143
set(OPENTELEMETRY_PREFIX_PATH_LIST_SEP_CHAR "|")
41374144
# JOIN is CMake >=3.12 only
@@ -4222,6 +4229,9 @@ macro(build_opentelemetry)
42224229
endmacro()
42234230

42244231
if(ARROW_WITH_OPENTELEMETRY)
4232+
# cURL is required whether we build from source or use an existing installation
4233+
# (OTel's cmake files do not call find_curl for you)
4234+
find_curl()
42254235
set(opentelemetry-cpp_SOURCE "AUTO")
42264236
resolve_dependency(opentelemetry-cpp)
42274237
get_target_property(OPENTELEMETRY_INCLUDE_DIR opentelemetry-cpp::api

0 commit comments

Comments
 (0)