Skip to content

CMake FetchContent > Updating the documentation? #2073

@ArthurSonzogni

Description

@ArthurSonzogni

nlohmann::json documents 2 way of depending on it using CMake

  1. Copy-paste the project/source into your own project.
  2. Install nlohman::json and then use find_package.

(1) pollutes your git repository, (2) requires everyone to install the dependencies themselves.

Since 2018, CMake provide some kind of 'package manager' features using FetchContent
It gives the following:

include(FetchContent)

FetchContent_Declare(nlohmann_json
  GIT_REPOSITORY https://github.com/nlohmann/json
  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()

Then declares the dependency in the target using it:

target_link_library(my_project PRIVATE nlohmann_json::nlohmann_json

I think it might worth updating the README to include this. What do you think? Would you like to receive a PR about this? If yes, do you have any special instructions?

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions