This page explains how to include the ArduinoJson library in your CMake project.

Method 1: using the FetchContent module

If you use CMake 3.14 or above, you can use the built-in FetchContent module.

cmake_minimum_required(VERSION 3.14)
project(example)

include(FetchContent)
FetchContent_Declare(ArduinoJson
    GIT_REPOSITORY https://github.com/bblanchon/ArduinoJson.git
    GIT_TAG        v6.21.5
)
FetchContent_MakeAvailable(ArduinoJson)

add_executable(example example.cpp)
target_link_libraries(example ArduinoJson)

Method 2: using cget

Alternatively, you can use the cget package manager.

On the command line prompt, run:

cget install bblanchon/ArduinoJson

Then, in your CMakeLists.txt, add the following:

cmake_minimum_required(VERSION 3.0)
project(example)

include(cget/cget/cget.cmake)
find_package(ArduinoJson 6 REQUIRED)

add_executable(example example.cpp)
target_link_libraries(example ArduinoJson)

Method 3: using git submodule

Lastly, you can rely on Git submodules to fetch the ArduinoJson source.

On the command line prompt, run:

git submodule add https://github.com/bblanchon/ArduinoJson.git third-party/ArduinoJson

Then, in your CMakeLists.txt, add the following:

cmake_minimum_required(VERSION 3.0)
project(example)

add_subdirectory(third-party/ArduinoJson)

add_executable(example example.cpp)
target_link_libraries(example ArduinoJson)
Global warming stripes by Professor Ed Hawkins (University of Reading)