📤 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>
This commit is contained in:
Stéphane Janel
2022-10-03 11:01:42 +02:00
committed by GitHub
parent cba92ab173
commit 07a2f64b0d
7 changed files with 20 additions and 25458 deletions

View File

@@ -78,9 +78,9 @@ jobs:
- uses: actions/checkout@v2
- name: install cmake
run: |
wget https://cmake.org/files/v3.12/cmake-3.12.4.tar.gz
tar -zxf cmake-3.12.4.tar.gz
cd cmake-3.12.4
wget https://cmake.org/files/v3.14/cmake-3.14.7.tar.gz
tar -zxf cmake-3.14.7.tar.gz
cd cmake-3.14.7
./bootstrap
make -j $(nproc)
sudo make install

View File

@@ -38,8 +38,6 @@ jobs:
with:
version: ${{matrix.target.tag}}
- if: matrix.target.name == 'nlohmann-json'
run: rm -rf include/nlohmann
- if: matrix.target.name == 'nlohmann-json'
uses: ./.github/actions/install/nlohmann-json
with:

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.14)
# HUNTER_ENABLED is always set if this package is included in a project using hunter (HunterGate sets it) In this case
# 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)
find_package(picojson 1.3.0 REQUIRED)
endif()
find_package(nlohmann_json CONFIG)
if(NOT nlohmann_json_FOUND)
include(FetchContent)
fetchcontent_declare(nlohmann_json GIT_REPOSITORY https://github.com/nlohmann/json.git GIT_TAG v3.11.2)
fetchcontent_makeavailable(nlohmann_json)
endif()
set(JWT_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(JWT_HEADER_FILES ${JWT_INCLUDE_PATH}/jwt-cpp/jwt.h)
foreach(traits ${JWT_JSON_TRAITS_OPTIONS})
@@ -107,7 +117,7 @@ if(JWT_EXTERNAL_PICOJSON)
target_link_libraries(jwt-cpp INTERFACE picojson::picojson>)
endif()
# Hunter needs relative paths so the files are palced correctly
# Hunter needs relative paths so the files are placed correctly
if(NOT JWT_CMAKE_FILES_INSTALL_DIR)
set(JWT_CMAKE_FILES_INSTALL_DIR cmake)
endif()

View File

@@ -30,4 +30,4 @@ add_executable(es256k es256k.cpp)
target_link_libraries(es256k jwt-cpp::jwt-cpp)
add_executable(partial-claim-verifier partial-claim-verifier.cpp)
target_link_libraries(partial-claim-verifier jwt-cpp::jwt-cpp)
target_link_libraries(partial-claim-verifier jwt-cpp::jwt-cpp nlohmann_json::nlohmann_json)

View File

@@ -19,8 +19,8 @@ endif()
find_package(nlohmann_json CONFIG)
if(TARGET nlohmann_json::nlohmann_json)
add_executable(nlohmann-json nlohmann-json.cpp)
target_link_libraries(nlohmann-json nlohmann_json::nlohmann_json jwt-cpp::jwt-cpp)
add_executable(nlohmann-json nlohmann-json.cpp)
target_link_libraries(nlohmann-json nlohmann_json::nlohmann_json jwt-cpp::jwt-cpp)
endif()
include("../../cmake/private-find-kazuho-picojson.cmake")

File diff suppressed because it is too large Load Diff

View File

@@ -52,7 +52,8 @@ else()
target_link_libraries(jwt-cpp-test PRIVATE boost_json)
endif()
endif()
target_link_libraries(jwt-cpp-test PRIVATE jwt-cpp $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:${CMAKE_DL_LIBS}>)
target_link_libraries(jwt-cpp-test PRIVATE jwt-cpp nlohmann_json::nlohmann_json
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:${CMAKE_DL_LIBS}>)
gtest_add_tests(TARGET jwt-cpp-test)