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

CMake FetchContent > Updating the documentation? #2073

Closed
ArthurSonzogni opened this issue Apr 29, 2020 · 1 comment · Fixed by #2074
Closed

CMake FetchContent > Updating the documentation? #2073

ArthurSonzogni opened this issue Apr 29, 2020 · 1 comment · Fixed by #2074
Assignees
Labels
documentation kind: enhancement/improvement solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@ArthurSonzogni
Copy link
Contributor

ArthurSonzogni commented Apr 29, 2020

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?

@nlohmann
Copy link
Owner

This is a good idea, and I would look forward to seeing a PR!

While you're at it, please also add a test like https://github.com/nlohmann/json/tree/develop/test/cmake_add_subdirectory so that we can be sure we do not break anything in the future. That test should then use the develop branch, however.

ArthurSonzogni added a commit to ArthurSonzogni/json that referenced this issue Apr 29, 2020
Github issue:
nlohmann#2073

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](https://cmake.org/cmake/help/v3.17/module/FetchContent.html)
It gives the following:
~~~cmake
include(FetchContent)

FetchContent_Declare(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:
~~~cmake
~~~

This patch updates the documentation and provide tests.
ArthurSonzogni added a commit to ArthurSonzogni/json that referenced this issue Apr 29, 2020
Github issue:
nlohmann#2073

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](https://cmake.org/cmake/help/v3.17/module/FetchContent.html)
It gives the following:
~~~cmake
include(FetchContent)

FetchContent_Declare(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:
~~~cmake
target_link_library(my_project PRIVATE nlohmann_json::nlohmann_json
~~~

This patch updates the documentation and provides tests.
ArthurSonzogni added a commit to ArthurSonzogni/json that referenced this issue Apr 29, 2020
Github issue:
nlohmann#2073

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](https://cmake.org/cmake/help/v3.17/module/FetchContent.html)
It gives the following:
~~~cmake
include(FetchContent)

FetchContent_Declare(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:
~~~cmake
target_link_library(my_project PRIVATE nlohmann_json::nlohmann_json
~~~

This patch updates the documentation and provides tests.
ArthurSonzogni added a commit to ArthurSonzogni/json that referenced this issue Apr 29, 2020
Github issue:
nlohmann#2073

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](https://cmake.org/cmake/help/v3.17/module/FetchContent.html)
It gives the following:
~~~cmake
include(FetchContent)

FetchContent_Declare(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:
~~~cmake
target_link_library(my_project PRIVATE nlohmann_json::nlohmann_json
~~~

This patch updates the documentation and provides tests.
ArthurSonzogni added a commit to ArthurSonzogni/json that referenced this issue Apr 29, 2020
Github issue:
nlohmann#2073

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](https://cmake.org/cmake/help/v3.17/module/FetchContent.html)
It gives the following:
~~~cmake
include(FetchContent)

FetchContent_Declare(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:
~~~cmake
target_link_library(my_project PRIVATE nlohmann_json::nlohmann_json
~~~

This patch updates the documentation and provides tests.
ArthurSonzogni added a commit to ArthurSonzogni/json that referenced this issue Apr 29, 2020
Github issue:
nlohmann#2073

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](https://cmake.org/cmake/help/v3.17/module/FetchContent.html)
It gives the following:
~~~cmake
include(FetchContent)

FetchContent_Declare(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:
~~~cmake
target_link_library(my_project PRIVATE nlohmann_json::nlohmann_json
~~~

This patch updates the documentation and provides tests.
ArthurSonzogni added a commit to ArthurSonzogni/json that referenced this issue Apr 29, 2020
Github issue:
nlohmann#2073

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](https://cmake.org/cmake/help/v3.17/module/FetchContent.html)
It gives the following:
~~~cmake
include(FetchContent)

FetchContent_Declare(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:
~~~cmake
target_link_library(my_project PRIVATE nlohmann_json::nlohmann_json
~~~

This patch updates the documentation and provides tests.
@nlohmann nlohmann linked a pull request Apr 30, 2020 that will close this issue
@nlohmann nlohmann added solution: proposed fix a fix for the issue has been proposed and waits for confirmation and removed state: waiting for PR labels Apr 30, 2020
@nlohmann nlohmann self-assigned this May 1, 2020
@nlohmann nlohmann added this to the Release 3.8.0 milestone May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation kind: enhancement/improvement solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants