2021-05-24 21:34:59 +08:00
|
|
|
#[=======================================================================[.rst:
|
|
|
|
FindLibJWT
|
|
|
|
----------
|
|
|
|
|
|
|
|
Find the JWT C Library (libjwt)
|
|
|
|
|
|
|
|
|
|
|
|
This module accepts optional COMPONENTS to select the crypto backend (these are mutually exclusive)::
|
|
|
|
|
|
|
|
openssl (default)
|
|
|
|
gnutls
|
|
|
|
|
|
|
|
IMPORTED Targets
|
|
|
|
^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
This module defines the following :prop_tgt:`IMPORTED` targets:
|
|
|
|
|
|
|
|
``JWT::libjwt``
|
|
|
|
The JWT library, if found with the specified crypto backend.
|
|
|
|
|
|
|
|
Result Variables
|
|
|
|
^^^^^^^^^^^^^^^^
|
2020-03-06 01:29:27 +08:00
|
|
|
|
2021-05-24 21:34:59 +08:00
|
|
|
``LIBJWT_FOUND``
|
|
|
|
System has libjwt
|
2021-06-04 06:14:42 +08:00
|
|
|
``LIBJWT_INCLUDE_DIRS``
|
2021-05-24 21:34:59 +08:00
|
|
|
The libjwt include directory
|
|
|
|
``LIBJWT_LIBRARIES``
|
|
|
|
The libraries needed to use libjwt
|
|
|
|
#]=======================================================================]
|
|
|
|
|
|
|
|
include(FindPackageHandleStandardArgs)
|
2020-03-06 01:29:27 +08:00
|
|
|
find_package(PkgConfig QUIET)
|
2021-05-24 21:34:59 +08:00
|
|
|
|
|
|
|
if(LibJWT_FIND_COMPONENTS)
|
|
|
|
set(LIBJWT_CRYPTO_BACKEND "")
|
|
|
|
foreach(component IN LISTS LibJWT_FIND_COMPONENTS)
|
|
|
|
if(component MATCHES "^(openssl|gnutls)")
|
|
|
|
if(LIBJWT_CRYPTO_BACKEND)
|
|
|
|
message(FATAL_ERROR "LibJWT: Only one crypto library can be selected.")
|
|
|
|
endif()
|
|
|
|
set(LIBJWT_CRYPTO_BACKEND ${component})
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "LibJWT: Wrong crypto backend specified.")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
else()
|
|
|
|
set(LIBJWT_CRYPTO_BACKEND "openssl")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(LIBJWT_LIB_NAMES "")
|
|
|
|
if(LIBJWT_CRYPTO_BACKEND STREQUAL "openssl")
|
|
|
|
set(LIBJWT_LIB_NAMES "jwt" "libjwt")
|
|
|
|
elseif(LIBJWT_CRYPTO_BACKEND STREQUAL "gnutls")
|
|
|
|
set(LIBJWT_LIB_NAMES "jwt-gnutls" "libjwt-gnutls")
|
|
|
|
endif()
|
|
|
|
|
2020-03-06 01:29:27 +08:00
|
|
|
pkg_check_modules(PC_LIBJWT QUIET libjwt)
|
|
|
|
|
|
|
|
find_path(LIBJWT_INCLUDE_DIR
|
|
|
|
NAMES jwt.h
|
2021-05-24 21:34:59 +08:00
|
|
|
HINTS
|
|
|
|
${PC_LIBJWT_INCLUDEDIR}
|
|
|
|
${PC_LIBJWT_INCLUDE_DIRS})
|
|
|
|
mark_as_advanced(LIBJWT_INCLUDE_DIR)
|
2020-03-06 01:29:27 +08:00
|
|
|
|
|
|
|
find_library(LIBJWT_LIBRARY
|
2021-05-24 21:34:59 +08:00
|
|
|
NAMES ${LIBJWT_LIB_NAMES}
|
|
|
|
HINTS
|
|
|
|
${PC_LIBJWT_LIBDIR}
|
|
|
|
${PC_LIBJWT_LIBRARY_DIR})
|
|
|
|
mark_as_advanced(LIBJWT_LIBRARY)
|
2020-03-06 01:29:27 +08:00
|
|
|
|
|
|
|
find_package_handle_standard_args(LibJWT
|
2021-05-24 21:34:59 +08:00
|
|
|
REQUIRED_VARS
|
|
|
|
LIBJWT_INCLUDE_DIR
|
|
|
|
LIBJWT_LIBRARY
|
|
|
|
FAIL_MESSAGE
|
|
|
|
"Could NOT find LibJWT with the crypto backend ${LIBJWT_CRYPTO_BACKEND}.")
|
2020-03-06 01:29:27 +08:00
|
|
|
|
|
|
|
if(LIBJWT_FOUND)
|
2021-05-24 21:34:59 +08:00
|
|
|
set(LIBJWT_LIBRARIES ${LIBJWT_LIBRARY})
|
|
|
|
set(LIBJWT_INCLUDE_DIRS ${LIBJWT_INCLUDE_DIR})
|
2020-03-06 01:29:27 +08:00
|
|
|
|
2021-05-24 21:34:59 +08:00
|
|
|
add_library(JWT::libjwt UNKNOWN IMPORTED)
|
|
|
|
set_target_properties(JWT::libjwt PROPERTIES
|
|
|
|
INTERFACE_INCLUDE_DIRECTORIES "${LIBJWT_INCLUDE_DIRS}"
|
|
|
|
IMPORTED_LOCATION "${LIBJWT_LIBRARY}")
|
|
|
|
endif()
|