Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nlohmann_json package dependency #1017

Merged
merged 6 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the repo is cloned without submodule, will this work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now modified the second if condition to make it more explicit.

Error message if cloned without submodules,

  nlohmann_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:

  git submodule update --init --recursive

Error message if using release tar-ball:

CMake Error at CMakeLists.txt:290 (find_package):
  By not providing "Findnlohmann_json.cmake" in CMAKE_MODULE_PATH this
  project has asked CMake to find a package configuration file provided by
  "nlohmann_json", but CMake did not find one.

  Could not find a package configuration file provided by "nlohmann_json"
  with any of the following names:

    nlohmann_jsonConfig.cmake
    nlohmann_json-config.cmake

  Add the installation prefix of "nlohmann_json" to CMAKE_PREFIX_PATH or set
  "nlohmann_json_DIR" to a directory containing one of the above files.  If
  "nlohmann_json" provides a separate development package or SDK, be sure it
  has been installed.

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()