Skip to content

Commit

Permalink
Fix nlohmann_json package dependency (#1017)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Oct 19, 2021
1 parent bfab71a commit 55a6517
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
54 changes: 35 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,16 @@ option(WITH_PROMETHEUS "Whether to include the Prometheus Client in the SDK"
option(WITH_ELASTICSEARCH
"Whether to include the Elasticsearch Client in the SDK" OFF)

option(WITH_ZPAGES "Whether to include the Zpages Server in the SDK" OFF)

option(WITH_JAEGER "Whether to include the Jaeger exporter" OFF)

option(WITH_NO_GETENV "Whether the platform supports environment variables" OFF)

option(BUILD_TESTING "Whether to enable tests" ON)

option(BUILD_W3CTRACECONTEXT_TEST "Whether to build w3c trace context" OFF)

if(WITH_NO_GENENV)
add_definitions(-DNO_GETENV)
endif()
Expand Down Expand Up @@ -249,29 +253,41 @@ endif()
# GNUInstallDirs.
include(GNUInstallDirs)

if(NOT WITH_API_ONLY)
if((NOT WITH_API_ONLY)
OR 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)
if(NOT nlohmann_json_FOUND)
message("Using local nlohmann::json from submodule")
set(JSON_BuildTests
OFF
CACHE INTERNAL "")
set(JSON_Install
ON
CACHE INTERNAL "")
if(EXISTS ${PROJECT_SOURCE_DIR}/third_party/nlohmann-json)
# 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)
if(EXISTS ${PROJECT_SOURCE_DIR}/.git)
message("Trying to use local nlohmann::json from submodule")
set(JSON_BuildTests
OFF
CACHE INTERNAL "")
set(JSON_Install
ON
CACHE INTERNAL "")
if(EXISTS ${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/CMakeLists.txt)
# 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(
FATAL_ERROR
"\nnlohmann_json package was not found. Please either provide it manually or clone with submodules. "
"To initialize, fetch and checkout any nested submodules, you can use the following command:\n"
"git submodule update --init --recursive")
endif()
else()
message(
FATAL_ERROR
"\nnlohmann_json package was not found. Please either provide it manually or clone with submodules. "
"To initialize, fetch and checkout any nested submodules, you can use the following command:\n"
"git submodule update --init --recursive")
# Let's fail with default find_package error
find_package(nlohmann_json REQUIRED)
endif()
else()
message("Using external nlohmann::json")
Expand Down
4 changes: 3 additions & 1 deletion ext/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
add_subdirectory(zpages)
if(WITH_ZPAGES)
add_subdirectory(zpages)
endif()
add_subdirectory(http/client/curl)
8 changes: 6 additions & 2 deletions ext/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
add_subdirectory(zpages)
if(WITH_ZPAGES)
add_subdirectory(zpages)
endif()
add_subdirectory(http)
add_subdirectory(w3c_tracecontext_test)
if(BUILD_W3CTRACECONTEXT_TEST)
add_subdirectory(w3c_tracecontext_test)
endif()

0 comments on commit 55a6517

Please sign in to comment.