How to use ArduinoJson with CMake?
This page explains how to include the ArduinoJson library in yourCMake project.
Method 1: using theFetchContent module
If you use CMake 3.14 or above, you can use the built-inFetchContent module.
cmake_minimum_required(VERSION 3.14)project(example)include(FetchContent)FetchContent_Declare(ArduinoJson GIT_REPOSITORY https://github.com/bblanchon/ArduinoJson.git GIT_TAG v7.4.2)FetchContent_MakeAvailable(ArduinoJson)add_executable(example example.cpp)target_link_libraries(example ArduinoJson)Method 2: usingcget
Alternatively, you can use thecget package manager.
On the command line prompt, run:
cgetinstallbblanchon/ArduinoJsonThen, in yourCMakeLists.txt, add the following:
cmake_minimum_required(VERSION 3.0)project(example)include(cget/cget/cget.cmake)find_package(ArduinoJson 7 REQUIRED)add_executable(example example.cpp)target_link_libraries(example ArduinoJson)Method 3: usinggit 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/ArduinoJsonThen, in yourCMakeLists.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)