Skip to content

Commit

Permalink
If external nlohmann::json is not found, then use one from our submod…
Browse files Browse the repository at this point in the history
…ule (#865)
  • Loading branch information
maxgolov authored Jun 18, 2021
1 parent 4947ab7 commit a779c3b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
25 changes: 20 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,24 @@ endif()
# GNUInstallDirs.
include(GNUInstallDirs)

find_package(nlohmann_json QUIET)
if(NOT nlohmann_json_FOUND)
message("Using local nlohmann::json from submodule")
set(JSON_BuildTests
OFF
CACHE INTERNAL "")
set(JSON_Install
OFF
CACHE INTERNAL "")
# This option allows to link nlohmann_json::nlohmann_json target
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/nlohmann-json)
# This option allows to add header to include directories
include_directories(
${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/single_include)
else()
message("Using external nlohmann::json")
endif()

if(WITH_OTLP)
set(protobuf_MODULE_COMPATIBLE ON)
find_package(Protobuf)
Expand Down Expand Up @@ -268,13 +286,13 @@ if(WITH_OTLP)
include(cmake/opentelemetry-proto.cmake)
include(CMakeDependentOption)
find_package(CURL)
find_package(nlohmann_json)

cmake_dependent_option(
WITH_OTLP_GRPC "Whether to include the OTLP gRPC exporter in the SDK" ON
"gRPC_FOUND" OFF)
cmake_dependent_option(
WITH_OTLP_HTTP "Whether to include the OTLP http exporter in the SDK" ON
"CURL_FOUND;nlohmann_json_FOUND" OFF)
"CURL_FOUND" OFF)
endif()

list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")
Expand Down Expand Up @@ -329,9 +347,6 @@ if(NOT WITH_API_ONLY)
endif()
endif()

# Add nlohmann/json submodule to include directories
include_directories(third_party/nlohmann-json/single_include)

# Export cmake config and support find_packages(opentelemetry-cpp CONFIG) Write
# config file for find_packages(opentelemetry-cpp CONFIG)
set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
Expand Down
2 changes: 0 additions & 2 deletions exporters/etw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
find_package(nlohmann_json REQUIRED)

add_library(opentelemetry_exporter_etw INTERFACE)

target_include_directories(
Expand Down
7 changes: 2 additions & 5 deletions exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ endif()

if(WITH_OTLP_HTTP)
find_package(CURL REQUIRED)
find_package(nlohmann_json REQUIRED)
add_library(opentelemetry_exporter_otlp_http src/otlp_http_exporter.cc)

set_target_properties(opentelemetry_exporter_otlp_http
PROPERTIES EXPORT_NAME otlp_http_exporter)

target_link_libraries(
opentelemetry_exporter_otlp_http
PUBLIC opentelemetry_otlp_recordable http_client_curl
nlohmann_json::nlohmann_json)
target_link_libraries(opentelemetry_exporter_otlp_http
PUBLIC opentelemetry_otlp_recordable http_client_curl)

list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http)
endif()
Expand Down
11 changes: 1 addition & 10 deletions ext/test/w3c_tracecontext_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,10 @@ find_package(CURL)
if(NOT CURL_FOUND)
message(WARNING "Skipping example_w3c_tracecontext_test: CURL not found")
else()
find_package(nlohmann_json QUIET)
if(NOT nlohmann_json_FOUND)
# Add library from git submodule to include path
include_directories(
${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/single_include)
else()
# Add header-only library found by CMake
set(NLOHMANN_JSON_LIB nlohmann_json::nlohmann_json)
endif()
add_executable(w3c_tracecontext_test main.cc)
target_link_libraries(
w3c_tracecontext_test
PRIVATE ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace http_client_curl
opentelemetry_exporter_ostream_span ${CURL_LIBRARIES}
${NLOHMANN_JSON_LIB})
nlohmann_json::nlohmann_json)
endif()

0 comments on commit a779c3b

Please sign in to comment.