Skip to content

Commit 07a2f64

Browse files
📤 Do not embed nlohmann::json directly, use find_package / FetchContent instead (#254)
* Do not embed nlohmann::json directly, use find_package / FetchContent instead * Clea up traits workflow Headers are no longer vendored Co-authored-by: Chris Mc <prince.chrismc@gmail.com>
1 parent cba92ab commit 07a2f64

File tree

7 files changed

+20
-25458
lines changed

7 files changed

+20
-25458
lines changed

.github/workflows/cmake.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ jobs:
7878
- uses: actions/checkout@v2
7979
- name: install cmake
8080
run: |
81-
wget https://cmake.org/files/v3.12/cmake-3.12.4.tar.gz
82-
tar -zxf cmake-3.12.4.tar.gz
83-
cd cmake-3.12.4
81+
wget https://cmake.org/files/v3.14/cmake-3.14.7.tar.gz
82+
tar -zxf cmake-3.14.7.tar.gz
83+
cd cmake-3.14.7
8484
./bootstrap
8585
make -j $(nproc)
8686
sudo make install

.github/workflows/traits.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ jobs:
3838
with:
3939
version: ${{matrix.target.tag}}
4040

41-
- if: matrix.target.name == 'nlohmann-json'
42-
run: rm -rf include/nlohmann
4341
- if: matrix.target.name == 'nlohmann-json'
4442
uses: ./.github/actions/install/nlohmann-json
4543
with:

CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.12)
1+
cmake_minimum_required(VERSION 3.14)
22

33
# HUNTER_ENABLED is always set if this package is included in a project using hunter (HunterGate sets it) In this case
44
# we will use hunter as well to stay consistent. If not the use can supply it on configure to force using hunter.
@@ -62,6 +62,16 @@ if(JWT_EXTERNAL_PICOJSON)
6262
find_package(picojson 1.3.0 REQUIRED)
6363
endif()
6464

65+
find_package(nlohmann_json CONFIG)
66+
67+
if(NOT nlohmann_json_FOUND)
68+
include(FetchContent)
69+
70+
fetchcontent_declare(nlohmann_json GIT_REPOSITORY https://github.com/nlohmann/json.git GIT_TAG v3.11.2)
71+
72+
fetchcontent_makeavailable(nlohmann_json)
73+
endif()
74+
6575
set(JWT_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/include)
6676
set(JWT_HEADER_FILES ${JWT_INCLUDE_PATH}/jwt-cpp/jwt.h)
6777
foreach(traits ${JWT_JSON_TRAITS_OPTIONS})
@@ -107,7 +117,7 @@ if(JWT_EXTERNAL_PICOJSON)
107117
target_link_libraries(jwt-cpp INTERFACE picojson::picojson>)
108118
endif()
109119

110-
# Hunter needs relative paths so the files are palced correctly
120+
# Hunter needs relative paths so the files are placed correctly
111121
if(NOT JWT_CMAKE_FILES_INSTALL_DIR)
112122
set(JWT_CMAKE_FILES_INSTALL_DIR cmake)
113123
endif()

example/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ add_executable(es256k es256k.cpp)
3030
target_link_libraries(es256k jwt-cpp::jwt-cpp)
3131

3232
add_executable(partial-claim-verifier partial-claim-verifier.cpp)
33-
target_link_libraries(partial-claim-verifier jwt-cpp::jwt-cpp)
33+
target_link_libraries(partial-claim-verifier jwt-cpp::jwt-cpp nlohmann_json::nlohmann_json)

example/traits/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ endif()
1919

2020
find_package(nlohmann_json CONFIG)
2121
if(TARGET nlohmann_json::nlohmann_json)
22-
add_executable(nlohmann-json nlohmann-json.cpp)
23-
target_link_libraries(nlohmann-json nlohmann_json::nlohmann_json jwt-cpp::jwt-cpp)
22+
add_executable(nlohmann-json nlohmann-json.cpp)
23+
target_link_libraries(nlohmann-json nlohmann_json::nlohmann_json jwt-cpp::jwt-cpp)
2424
endif()
2525

2626
include("../../cmake/private-find-kazuho-picojson.cmake")

0 commit comments

Comments
 (0)