FindGnuTLS.cmake 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindGnuTLS
  5. ----------
  6. Find the GNU Transport Layer Security library (gnutls)
  7. IMPORTED Targets
  8. ^^^^^^^^^^^^^^^^
  9. This module defines :prop_tgt:`IMPORTED` target ``GnuTLS::GnuTLS``, if
  10. gnutls has been found.
  11. Result Variables
  12. ^^^^^^^^^^^^^^^^
  13. ``GNUTLS_FOUND``
  14. System has gnutls
  15. ``GNUTLS_INCLUDE_DIR``
  16. The gnutls include directory
  17. ``GNUTLS_LIBRARIES``
  18. The libraries needed to use gnutls
  19. ``GNUTLS_DEFINITIONS``
  20. Compiler switches required for using gnutls
  21. ``GNUTLS_VERSION``
  22. version of gnutls.
  23. #]=======================================================================]
  24. # Note that this doesn't try to find the gnutls-extra package.
  25. if (GNUTLS_INCLUDE_DIR AND GNUTLS_LIBRARY)
  26. # in cache already
  27. set(gnutls_FIND_QUIETLY TRUE)
  28. endif ()
  29. if (NOT WIN32)
  30. # try using pkg-config to get the directories and then use these values
  31. # in the find_path() and find_library() calls
  32. # also fills in GNUTLS_DEFINITIONS, although that isn't normally useful
  33. find_package(PkgConfig QUIET)
  34. PKG_CHECK_MODULES(PC_GNUTLS QUIET gnutls)
  35. set(GNUTLS_DEFINITIONS ${PC_GNUTLS_CFLAGS_OTHER})
  36. set(GNUTLS_VERSION ${PC_GNUTLS_VERSION})
  37. # keep for backward compatibility
  38. set(GNUTLS_VERSION_STRING ${PC_GNUTLS_VERSION})
  39. endif ()
  40. find_path(GNUTLS_INCLUDE_DIR gnutls/gnutls.h
  41. HINTS
  42. ${PC_GNUTLS_INCLUDEDIR}
  43. ${PC_GNUTLS_INCLUDE_DIRS}
  44. )
  45. find_library(GNUTLS_LIBRARY NAMES gnutls libgnutls
  46. HINTS
  47. ${PC_GNUTLS_LIBDIR}
  48. ${PC_GNUTLS_LIBRARY_DIRS}
  49. )
  50. mark_as_advanced(GNUTLS_INCLUDE_DIR GNUTLS_LIBRARY)
  51. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  52. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GnuTLS
  53. REQUIRED_VARS GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR
  54. VERSION_VAR GNUTLS_VERSION_STRING)
  55. if(GNUTLS_FOUND)
  56. set(GNUTLS_LIBRARIES ${GNUTLS_LIBRARY})
  57. set(GNUTLS_INCLUDE_DIRS ${GNUTLS_INCLUDE_DIR})
  58. if(NOT TARGET GnuTLS::GnuTLS)
  59. add_library(GnuTLS::GnuTLS UNKNOWN IMPORTED)
  60. set_target_properties(GnuTLS::GnuTLS PROPERTIES
  61. INTERFACE_INCLUDE_DIRECTORIES "${GNUTLS_INCLUDE_DIRS}"
  62. INTERFACE_COMPILE_DEFINITIONS "${GNUTLS_DEFINITIONS}"
  63. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  64. IMPORTED_LOCATION "${GNUTLS_LIBRARIES}")
  65. endif()
  66. endif()