@@ -21,9 +21,15 @@ option(JWT_BUILD_DOCS "Adds a target for building the doxygen documentation" OFF
2121option (JWT_ENABLE_COVERAGE "Enable code coverage testing" OFF )
2222option (JWT_ENABLE_FUZZING "Enable fuzz testing" OFF )
2323
24- option (JWT_EXTERNAL_PICOJSON "Use find_package() to locate picojson, provided to integrate with package managers" OFF )
25- option (JWT_DISABLE_BASE64 "Do not include the base64 implementation from this library" OFF )
2624option (JWT_DISABLE_PICOJSON "Do not provide the picojson template specialiaze" OFF )
25+ option (JWT_DISABLE_BASE64 "Do not include the base64 implementation from this library" OFF )
26+ include (CMakeDependentOption)
27+ cmake_dependent_option(JWT_EXTERNAL_PICOJSON
28+ "Use find_package() to locate picojson, provided to integrate with package managers" OFF
29+ "NOT JWT_DISABLE_PICOJSON" OFF )
30+ cmake_dependent_option(JWT_EXTERNAL_NLOHMANN_JSON
31+ "Use find_package() to locate nlohman-json required for tests and examples" OFF
32+ "JWT_BUILD_EXAMPLES OR JWT_BUILD_TESTS" OFF )
2733
2834set (JWT_SSL_LIBRARY_OPTIONS OpenSSL LibreSSL wolfSSL)
2935set (JWT_SSL_LIBRARY OpenSSL CACHE STRING "Determines which SSL library to build with" )
@@ -63,18 +69,22 @@ elseif(${JWT_SSL_LIBRARY} MATCHES "wolfSSL")
6369 list (TRANSFORM wolfssl_INCLUDE_DIRS APPEND "/wolfssl" ) # This is required to access OpenSSL compatibility API
6470endif ()
6571
66- if (JWT_EXTERNAL_PICOJSON)
72+ if (NOT JWT_DISABLE_PICOJSON AND JWT_EXTERNAL_PICOJSON)
6773 find_package (picojson 1.3.0 REQUIRED)
6874endif ()
6975
70- find_package (nlohmann_json CONFIG)
71-
72- if (NOT nlohmann_json_FOUND)
73- message (STATUS "jwt-cpp: using FetchContent for nlohmann json" )
74- include (FetchContent)
75- fetchcontent_declare(nlohmann_json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz
76- URL_MD5 127794b2c82c0c5693805feaa2a703e2)
77- fetchcontent_makeavailable(nlohmann_json)
76+ if (JWT_BUILD_EXAMPLES OR JWT_BUILD_TESTS)
77+ if (JWT_EXTERNAL_NLOHMANN_JSON)
78+ message (STATUS "jwt-cpp: using find_package for nlohmann-json required for tests" )
79+ find_package (nlohmann_json CONFIG REQUIRED)
80+ else ()
81+ message (STATUS "jwt-cpp: using FetchContent for nlohmann-json required for tests" )
82+ include (FetchContent)
83+ fetchcontent_declare(nlohmann_json
84+ URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz
85+ URL_MD5 127794b2c82c0c5693805feaa2a703e2)
86+ fetchcontent_makeavailable(nlohmann_json)
87+ endif ()
7888endif ()
7989
8090set (JWT_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR} /include )
@@ -118,7 +128,7 @@ if(${JWT_SSL_LIBRARY} MATCHES "wolfSSL")
118128 target_compile_definitions (jwt-cpp INTERFACE OPENSSL_EXTRA OPENSSL_ALL)
119129endif ()
120130
121- if (JWT_EXTERNAL_PICOJSON)
131+ if (NOT JWT_DISABLE_PICOJSON AND JWT_EXTERNAL_PICOJSON)
122132 target_link_libraries (jwt-cpp INTERFACE picojson::picojson>)
123133endif ()
124134
@@ -129,7 +139,7 @@ endif()
129139
130140configure_package_config_file(
131141 ${CMAKE_CURRENT_LIST_DIR} /cmake/jwt-cpp-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR} /jwt-cpp-config.cmake
132- INSTALL_DESTINATION ${JWT_CMAKE_FILES_INSTALL_DIR} PATH_VARS JWT_EXTERNAL_PICOJSON JWT_SSL_LIBRARY )
142+ INSTALL_DESTINATION ${JWT_CMAKE_FILES_INSTALL_DIR} )
133143write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR} /jwt-cpp-config-version .cmake VERSION 0.7.0
134144 COMPATIBILITY ExactVersion)
135145
0 commit comments