Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
  • This project
    • Loading...
  • Sign in / Register
J
json
  • Project
    • Overview
    • Details
    • Activity
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 0
    • Issues 0
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Chen Yisong
  • json
  • Repository

Switch branch/tag
  • json
  • test
  • cmake_fetch_content
  • project
  • main.cpp
Find file
BlameHistoryPermalink
  • ArthurSonzogni's avatar
    Add CMake fetchcontent documentation and tests · c3317066
    ArthurSonzogni authored Apr 29, 2020
    Github issue:
    https://github.com/nlohmann/json/issues/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.
    c3317066
main.cpp 103 Bytes
EditWeb IDE
×

Replace main.cpp

Attach a file by drag & drop or click to upload


Cancel
A new branch will be created in your fork and a new merge request will be started.