Skip to content

Commit

Permalink
Merge branch 'master' into issue-341
Browse files Browse the repository at this point in the history
  • Loading branch information
prince-chrismc authored Apr 20, 2024
2 parents 9ac96c4 + d53e013 commit 8ee53c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
36 changes: 23 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ option(JWT_BUILD_DOCS "Adds a target for building the doxygen documentation" OFF
option(JWT_ENABLE_COVERAGE "Enable code coverage testing" OFF)
option(JWT_ENABLE_FUZZING "Enable fuzz testing" OFF)

option(JWT_EXTERNAL_PICOJSON "Use find_package() to locate picojson, provided to integrate with package managers" OFF)
option(JWT_DISABLE_BASE64 "Do not include the base64 implementation from this library" OFF)
option(JWT_DISABLE_PICOJSON "Do not provide the picojson template specialiaze" OFF)
option(JWT_DISABLE_BASE64 "Do not include the base64 implementation from this library" OFF)
include(CMakeDependentOption)
cmake_dependent_option(JWT_EXTERNAL_PICOJSON
"Use find_package() to locate picojson, provided to integrate with package managers" OFF
"NOT JWT_DISABLE_PICOJSON" OFF)
cmake_dependent_option(JWT_EXTERNAL_NLOHMANN_JSON
"Use find_package() to locate nlohman-json required for tests and examples" OFF
"JWT_BUILD_EXAMPLES OR JWT_BUILD_TESTS" OFF)

set(JWT_SSL_LIBRARY_OPTIONS OpenSSL LibreSSL wolfSSL)
set(JWT_SSL_LIBRARY OpenSSL CACHE STRING "Determines which SSL library to build with")
Expand Down Expand Up @@ -63,18 +69,22 @@ elseif(${JWT_SSL_LIBRARY} MATCHES "wolfSSL")
list(TRANSFORM wolfssl_INCLUDE_DIRS APPEND "/wolfssl") # This is required to access OpenSSL compatibility API
endif()

if(JWT_EXTERNAL_PICOJSON)
if(NOT JWT_DISABLE_PICOJSON AND JWT_EXTERNAL_PICOJSON)
find_package(picojson 1.3.0 REQUIRED)
endif()

find_package(nlohmann_json CONFIG)

if(NOT nlohmann_json_FOUND)
message(STATUS "jwt-cpp: using FetchContent for nlohmann json")
include(FetchContent)
fetchcontent_declare(nlohmann_json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz
URL_MD5 127794b2c82c0c5693805feaa2a703e2)
fetchcontent_makeavailable(nlohmann_json)
if(JWT_BUILD_EXAMPLES OR JWT_BUILD_TESTS)
if(JWT_EXTERNAL_NLOHMANN_JSON)
message(STATUS "jwt-cpp: using find_package for nlohmann-json required for tests")
find_package(nlohmann_json CONFIG REQUIRED)
else()
message(STATUS "jwt-cpp: using FetchContent for nlohmann-json required for tests")
include(FetchContent)
fetchcontent_declare(nlohmann_json
URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz
URL_MD5 127794b2c82c0c5693805feaa2a703e2)
fetchcontent_makeavailable(nlohmann_json)
endif()
endif()

set(JWT_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/include)
Expand Down Expand Up @@ -118,7 +128,7 @@ if(${JWT_SSL_LIBRARY} MATCHES "wolfSSL")
target_compile_definitions(jwt-cpp INTERFACE OPENSSL_EXTRA OPENSSL_ALL)
endif()

if(JWT_EXTERNAL_PICOJSON)
if(NOT JWT_DISABLE_PICOJSON AND JWT_EXTERNAL_PICOJSON)
target_link_libraries(jwt-cpp INTERFACE picojson::picojson>)
endif()

Expand All @@ -129,7 +139,7 @@ endif()

configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/jwt-cpp-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/jwt-cpp-config.cmake
INSTALL_DESTINATION ${JWT_CMAKE_FILES_INSTALL_DIR} PATH_VARS JWT_EXTERNAL_PICOJSON JWT_SSL_LIBRARY)
INSTALL_DESTINATION ${JWT_CMAKE_FILES_INSTALL_DIR})
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/jwt-cpp-config-version.cmake VERSION 0.7.0
COMPATIBILITY ExactVersion)

Expand Down
3 changes: 2 additions & 1 deletion cmake/jwt-cpp-config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@PACKAGE_INIT@

set(JWT_DISABLE_PICOJSON @JWT_DISABLE_PICOJSON@)
set(JWT_EXTERNAL_PICOJSON @JWT_EXTERNAL_PICOJSON@)
set(JWT_SSL_LIBRARY @JWT_SSL_LIBRARY@)

Expand All @@ -12,7 +13,7 @@ else()
find_dependency(${JWT_SSL_LIBRARY} REQUIRED)
endif()

if(JWT_EXTERNAL_PICOJSON)
if(NOT JWT_DISABLE_PICOJSON AND JWT_EXTERNAL_PICOJSON)
find_dependency(picojson REQUIRED)
endif()

Expand Down

0 comments on commit 8ee53c0

Please sign in to comment.