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

json parser: use fetch content #66

Closed
Nicogene opened this issue Feb 5, 2021 · 2 comments · Fixed by #65
Closed

json parser: use fetch content #66

Nicogene opened this issue Feb 5, 2021 · 2 comments · Fixed by #65
Assignees
Labels
enhancement New feature or request

Comments

@Nicogene
Copy link
Member

Nicogene commented Feb 5, 2021

In #65 we added the json.hpp in the repo but it would be better to use cmake FetchContent

@Nicogene Nicogene added the enhancement New feature or request label Feb 5, 2021
@Nicogene Nicogene self-assigned this Feb 5, 2021
@traversaro
Copy link
Member

traversaro commented Feb 5, 2021

A typical boilerplate for this is:

option(YARP_TELEMETRY_USES_SYSTEM_nlohmann_json OFF)
if(YARP_TELEMETRY_USES_SYSTEM_nlohmann_json)
  find_package(nlohmann_json REQUIRED)
else()
  include(FetchContent)

  FetchContent_Declare(json
    GIT_REPOSITORY https://github.com/nlohmann/json.git
    GIT_TAG v3.7.3)

  FetchContent_GetProperties(json)
  if(NOT json_POPULATED)
    FetchContent_Populate(json)
    add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} EXCLUDE_FROM_ALL)
  endif()
endif()

and then in the CMake code you just use nlohmann_json::nlohmann_json , see https://github.com/nlohmann/json#embedded-fetchcontent .

@Nicogene
Copy link
Member Author

Nicogene commented Feb 5, 2021

I completely missed this https://github.com/nlohmann/json#embedded-fetchcontent !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants