@@ -21,9 +21,15 @@ option(JWT_BUILD_DOCS "Adds a target for building the doxygen documentation" OFF
21
21
option (JWT_ENABLE_COVERAGE "Enable code coverage testing" OFF )
22
22
option (JWT_ENABLE_FUZZING "Enable fuzz testing" OFF )
23
23
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 )
26
24
option (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 )
27
33
28
34
set (JWT_SSL_LIBRARY_OPTIONS OpenSSL LibreSSL wolfSSL )
29
35
set (JWT_SSL_LIBRARY OpenSSL CACHE STRING "Determines which SSL library to build with" )
@@ -63,18 +69,22 @@ elseif(${JWT_SSL_LIBRARY} MATCHES "wolfSSL")
63
69
list (TRANSFORM wolfssl_INCLUDE_DIRS APPEND "/wolfssl" ) # This is required to access OpenSSL compatibility API
64
70
endif ()
65
71
66
- if (JWT_EXTERNAL_PICOJSON )
72
+ if (NOT JWT_DISABLE_PICOJSON AND JWT_EXTERNAL_PICOJSON )
67
73
find_package (picojson 1.3.0 REQUIRED )
68
74
endif ()
69
75
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 ()
78
88
endif ()
79
89
80
90
set (JWT_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR} /include )
@@ -118,7 +128,7 @@ if(${JWT_SSL_LIBRARY} MATCHES "wolfSSL")
118
128
target_compile_definitions (jwt-cpp INTERFACE OPENSSL_EXTRA OPENSSL_ALL )
119
129
endif ()
120
130
121
- if (JWT_EXTERNAL_PICOJSON )
131
+ if (NOT JWT_DISABLE_PICOJSON AND JWT_EXTERNAL_PICOJSON )
122
132
target_link_libraries (jwt-cpp INTERFACE picojson::picojson> )
123
133
endif ()
124
134
@@ -129,7 +139,7 @@ endif()
129
139
130
140
configure_package_config_file (
131
141
${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} )
133
143
write_basic_package_version_file (${CMAKE_CURRENT_BINARY_DIR} /jwt-cpp-config-version.cmake VERSION 0.7.0
134
144
COMPATIBILITY ExactVersion )
135
145
0 commit comments