FindGnuTLS.cmake 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindGnuTLS
  5. ----------
  6. Finds the GNU Transport Layer Security library (GnuTLS). The GnuTLS
  7. package includes the main libraries (libgnutls and libdane), as well as the
  8. optional gnutls-openssl compatibility extra library. They are all distributed
  9. as part of the same release. This module checks for the presence of the main
  10. libgnutls library and provides usage requirements for integrating GnuTLS into
  11. CMake projects.
  12. Imported Targets
  13. ^^^^^^^^^^^^^^^^
  14. This module provides the following :ref:`Imported Targets`:
  15. ``GnuTLS::GnuTLS``
  16. .. versionadded:: 3.16
  17. Target encapsulating the GnuTLS usage requirements, available if GnuTLS is
  18. found.
  19. Result Variables
  20. ^^^^^^^^^^^^^^^^
  21. This module defines the following variables:
  22. ``GnuTLS_FOUND``
  23. Boolean indicating whether the (requested version of) GnuTLS is found. For
  24. backward compatibility, the ``GNUTLS_FOUND`` variable is also set to the same
  25. value.
  26. ``GNUTLS_VERSION``
  27. .. versionadded:: 3.16
  28. The version of GnuTLS found.
  29. ``GNUTLS_INCLUDE_DIRS``
  30. Include directories needed to use GnuTLS.
  31. ``GNUTLS_LIBRARIES``
  32. Libraries needed to link against to use GnuTLS.
  33. ``GNUTLS_DEFINITIONS``
  34. Compiler options required for using GnuTLS.
  35. Cache Variables
  36. ^^^^^^^^^^^^^^^
  37. The following cache variables may also be set:
  38. ``GNUTLS_INCLUDE_DIR``
  39. The directory containing the ``gnutls/gnutls.h`` header file.
  40. ``GNUTLS_LIBRARY``
  41. The path to the GnuTLS library.
  42. Deprecated Variables
  43. ^^^^^^^^^^^^^^^^^^^^
  44. These variables are provided for backward compatibility:
  45. ``GNUTLS_VERSION_STRING``
  46. .. deprecated:: 3.16
  47. Superseded by ``GNUTLS_VERSION``.
  48. The version of GnuTLS found.
  49. Examples
  50. ^^^^^^^^
  51. Finding GnuTLS and linking it to a project target:
  52. .. code-block:: cmake
  53. find_package(GnuTLS)
  54. target_link_libraries(project_target PRIVATE GnuTLS::GnuTLS)
  55. #]=======================================================================]
  56. if (GNUTLS_INCLUDE_DIR AND GNUTLS_LIBRARY)
  57. # in cache already
  58. set(gnutls_FIND_QUIETLY TRUE)
  59. endif ()
  60. if (NOT WIN32)
  61. # try using pkg-config to get the directories and then use these values
  62. # in the find_path() and find_library() calls
  63. # also fills in GNUTLS_DEFINITIONS, although that isn't normally useful
  64. find_package(PkgConfig QUIET)
  65. if(PKG_CONFIG_FOUND)
  66. pkg_check_modules(PC_GNUTLS QUIET gnutls)
  67. endif()
  68. set(GNUTLS_DEFINITIONS ${PC_GNUTLS_CFLAGS_OTHER})
  69. set(GNUTLS_VERSION ${PC_GNUTLS_VERSION})
  70. # keep for backward compatibility
  71. set(GNUTLS_VERSION_STRING ${PC_GNUTLS_VERSION})
  72. endif ()
  73. find_path(GNUTLS_INCLUDE_DIR gnutls/gnutls.h
  74. HINTS
  75. ${PC_GNUTLS_INCLUDEDIR}
  76. ${PC_GNUTLS_INCLUDE_DIRS}
  77. )
  78. find_library(GNUTLS_LIBRARY NAMES gnutls libgnutls
  79. HINTS
  80. ${PC_GNUTLS_LIBDIR}
  81. ${PC_GNUTLS_LIBRARY_DIRS}
  82. )
  83. mark_as_advanced(GNUTLS_INCLUDE_DIR GNUTLS_LIBRARY)
  84. include(FindPackageHandleStandardArgs)
  85. find_package_handle_standard_args(GnuTLS
  86. REQUIRED_VARS GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR
  87. VERSION_VAR GNUTLS_VERSION_STRING)
  88. if(GnuTLS_FOUND)
  89. set(GNUTLS_LIBRARIES ${GNUTLS_LIBRARY})
  90. set(GNUTLS_INCLUDE_DIRS ${GNUTLS_INCLUDE_DIR})
  91. if(NOT TARGET GnuTLS::GnuTLS)
  92. add_library(GnuTLS::GnuTLS UNKNOWN IMPORTED)
  93. set_target_properties(GnuTLS::GnuTLS PROPERTIES
  94. INTERFACE_INCLUDE_DIRECTORIES "${GNUTLS_INCLUDE_DIRS}"
  95. INTERFACE_COMPILE_DEFINITIONS "${GNUTLS_DEFINITIONS}"
  96. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  97. IMPORTED_LOCATION "${GNUTLS_LIBRARIES}")
  98. endif()
  99. endif()