Skip to content

Commit

Permalink
Try to build nlohmann-json only it's depended. (open-telemetry#1505)
Browse files Browse the repository at this point in the history
Signed-off-by: owentou <[email protected]>
  • Loading branch information
owent authored and yxue committed Dec 5, 2022
1 parent a2e62c4 commit 485a1e1
Showing 1 changed file with 38 additions and 36 deletions.
74 changes: 38 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,42 +239,6 @@ endif()
# GNUInstallDirs.
include(GNUInstallDirs)

if((NOT WITH_API_ONLY)
AND (WITH_ELASTICSEARCH
OR WITH_ZIPKIN
OR WITH_OTLP
OR WITH_OTLP_HTTP
OR WITH_ZPAGES
OR BUILD_W3CTRACECONTEXT_TEST
OR WITH_ETW
))
# nlohmann_json package is required for most SDK build configurations
find_package(nlohmann_json QUIET)
set(nlohmann_json_clone FALSE)
if(nlohmann_json_FOUND)
message("Using external nlohmann::json")
elseif(EXISTS ${PROJECT_SOURCE_DIR}/.git
AND EXISTS
${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/CMakeLists.txt)
message("Trying to use local nlohmann::json from submodule")
set(JSON_BuildTests
OFF
CACHE INTERNAL "")
set(JSON_Install
ON
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()
set(nlohmann_json_clone TRUE)
include(cmake/nlohmann-json.cmake)
message("\nnlohmann_json package was not found. Cloning from github")
endif()
endif()

if(WITH_PROMETHEUS)
find_package(prometheus-cpp CONFIG QUIET)
if(NOT prometheus-cpp_FOUND)
Expand Down Expand Up @@ -353,6 +317,44 @@ if(WITH_OTLP)
include(cmake/opentelemetry-proto.cmake)
endif()

if(WITH_ELASTICSEARCH
OR WITH_ZIPKIN
OR WITH_OTLP_HTTP
OR WITH_ZPAGES
OR BUILD_W3CTRACECONTEXT_TEST
OR WITH_ETW)
set(USE_NLOHMANN_JSON ON)
else()
set(USE_NLOHMANN_JSON OFF)
endif()
if((NOT WITH_API_ONLY) AND USE_NLOHMANN_JSON)
# nlohmann_json package is required for most SDK build configurations
find_package(nlohmann_json QUIET)
set(nlohmann_json_clone FALSE)
if(nlohmann_json_FOUND)
message("Using external nlohmann::json")
elseif(EXISTS ${PROJECT_SOURCE_DIR}/.git
AND EXISTS
${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/CMakeLists.txt)
message("Trying to use local nlohmann::json from submodule")
set(JSON_BuildTests
OFF
CACHE INTERNAL "")
set(JSON_Install
ON
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()
set(nlohmann_json_clone TRUE)
include(cmake/nlohmann-json.cmake)
message("\nnlohmann_json package was not found. Cloning from github")
endif()
endif()

list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")

include(CTest)
Expand Down

0 comments on commit 485a1e1

Please sign in to comment.