decrypt drsuapi attributes
[wireshark-sm.git] / cmake / modules / FindGNUTLS.cmake
blob853da4eb655dcd3229f1dfafb18286041546b57e
2 # - Find gnutls
3 # Find the native GNUTLS includes and library
5 #  GNUTLS_INCLUDE_DIRS - where to find gnutls.h, etc.
6 #  GNUTLS_LIBRARIES    - List of libraries when using gnutls.
7 #  GNUTLS_FOUND        - True if gnutls found.
8 #  GNUTLS_DLL_DIR      - (Windows) Path to the GnuTLS DLLs.
9 #  GNUTLS_DLLS         - (Windows) List of required GnuTLS DLLs.
12 if(GNUTLS_INCLUDE_DIRS)
13   # Already in cache, be silent
14   set(GNUTLS_FIND_QUIETLY TRUE)
15 endif()
17 include(FindWSWinLibs)
18 findwswinlibs("gnutls-.*" "GNUTLS_HINTS")
20 if(NOT USE_REPOSITORY)
21   find_package(PkgConfig)
22   pkg_search_module(GNUTLS gnutls)
23 endif()
25 # sources include gnutls/gnutls.h, look for that location instead of gnutls.h.
26 find_path(GNUTLS_INCLUDE_DIR
27   NAMES
28     gnutls/gnutls.h
29   HINTS
30     "${GNUTLS_INCLUDEDIR}"
31     "${GNUTLS_HINTS}/include"
34 find_library(GNUTLS_LIBRARY
35   NAMES
36     gnutls libgnutls-28 libgnutls-30
37   HINTS
38     "${GNUTLS_LIBDIR}"
39     "${GNUTLS_HINTS}/lib"
42 # On systems without pkg-config (e.g. Windows), search its header
43 # (available since GnuTLS 0.1.3)
44 if(NOT GNUTLS_VERSION)
45   if(GNUTLS_INCLUDE_DIR)
46     set(_version_regex "^#define[ \t]+GNUTLS_VERSION[ \t]+\"([^\"]+)\".*")
47     file(STRINGS "${GNUTLS_INCLUDE_DIR}/gnutls/gnutls.h" GNUTLS_VERSION REGEX "${_version_regex}")
48     string(REGEX REPLACE "${_version_regex}" "\\1" GNUTLS_VERSION "${GNUTLS_VERSION}")
49     unset(_version_regex)
50   endif()
51 endif()
53 include(FindPackageHandleStandardArgs)
54 find_package_handle_standard_args(GNUTLS
55   REQUIRED_VARS   GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR
56   VERSION_VAR     GNUTLS_VERSION)
58 if(GNUTLS_FOUND)
59   set(GNUTLS_LIBRARIES ${GNUTLS_LIBRARY})
60   set(GNUTLS_INCLUDE_DIRS ${GNUTLS_INCLUDE_DIR})
61   if(WIN32)
62     set(GNUTLS_DLL_DIR "${GNUTLS_HINTS}/bin"
63       CACHE PATH "Path to the GnuTLS DLLs"
64     )
65     # Note: 32-bit glib2-2.52.2-1.34-win32ws needs libgcc_s_sjlj-1.dll too.
66     file(GLOB _gnutls_dlls RELATIVE "${GNUTLS_DLL_DIR}"
67       "${GNUTLS_DLL_DIR}/libgmp-*.dll"
68       "${GNUTLS_DLL_DIR}/libgcc_s_*.dll"
69       "${GNUTLS_DLL_DIR}/libffi-*.dll"
70       "${GNUTLS_DLL_DIR}/libgnutls-*.dll"
71       "${GNUTLS_DLL_DIR}/libhogweed-*.dll"
72       "${GNUTLS_DLL_DIR}/libiconv-*.dll"
73       "${GNUTLS_DLL_DIR}/libintl-*.dll"
74       "${GNUTLS_DLL_DIR}/libnettle-*.dll"
75       "${GNUTLS_DLL_DIR}/libp11-kit-*.dll"
76       "${GNUTLS_DLL_DIR}/libtasn1-*.dll"
77       "${GNUTLS_DLL_DIR}/libwinpthread-*.dll"
78     )
79     set(GNUTLS_DLLS ${_gnutls_dlls}
80       # We're storing filenames only. Should we use STRING instead?
81       CACHE FILEPATH "GnuTLS DLL list"
82     )
83     mark_as_advanced(GNUTLS_DLL_DIR GNUTLS_DLLS)
84   endif()
85 else()
86   set(GNUTLS_LIBRARIES)
87   set(GNUTLS_INCLUDE_DIRS)
88   set(GNUTLS_DLL_DIR)
89   set(GNUTLS_DLLS)
90 endif()
92 mark_as_advanced(GNUTLS_LIBRARIES GNUTLS_INCLUDE_DIRS)