decrypt drsuapi attributes
[wireshark-sm.git] / cmake / modules / FindKERBEROS.cmake
blob2884fe37b7c708f5cd37d1d34bb8004e03ae0ebc
2 # - Find Kerberos
3 # Find the native Kerberos includes and library
5 #  KERBEROS_INCLUDE_DIRS  - where to find krb5.h, etc.
6 #  KERBEROS_DEFINITIONS   - -D and other compiler flags to use with krb5.
7 #  KERBEROS_LIBRARIES     - List of libraries when using krb5.
8 #  KERBEROS_LINK_FLAGS    - other linker flags to use with krb5.
9 #  KERBEROS_FOUND         - True if krb5 found.
10 #  KERBEROS_DLL_DIR       - (Windows) Path to the Kerberos DLLs.
11 #  KERBEROS_DLLS          - (Windows) List of required Kerberos DLLs.
12 #  HAVE_HEIMDAL_KERBEROS  - set if the Kerberos vendor is Heimdal
13 #  HAVE_MIT_KERBEROS      - set if the Kerberos vendor is MIT
16 if(KERBEROS_INCLUDE_DIRS)
17   # Already in cache, be silent
18   set(KERBEROS_FIND_QUIETLY TRUE)
19 endif()
21 include(FindWSWinLibs)
22 FindWSWinLibs("krb5-.*" "KERBEROS_HINTS")
24 if(NOT USE_REPOSITORY)
25   find_package(PkgConfig)
26   pkg_search_module(KERBEROS krb5 mit-krb5 heimdal-krb5)
27 endif()
29 if(KERBEROS_FOUND)
30   #
31   # Turn KERBEROS_CFLAGS_OTHER into KERBEROS_DEFINITIONS;
32   # <XPREFIX>_DEFINITIONS really means "flags other than -I,
33   # including both -D and other flags".
34   #
35   set(KERBEROS_DEFINITIONS "${KERBEROS_CFLAGS_OTHER}")
37   #
38   # KERBEROS_LIBRARIES is a list of library names, not library
39   # paths, and KERBEROS_LIBRARY_DIRS is a list of -L flag
40   # arguments.  Turn KERBEROS_LIBRARIES into a list of absolute
41   # paths for libraries, by searching for the libraries in
42   # directories including KERBEROS_LIBRARY_DIRS.
43   #
44   set(_kerberos_libraries "${KERBEROS_LIBRARIES}")
45   set(KERBEROS_LIBRARIES "")
46   foreach(_library ${_kerberos_libraries})
47     #
48     # Search for the library, using the library directories from
49     # pkg_search_module as hints.
50     #
51     find_library(_abspath_${_library} NAMES ${_library}
52                  HINTS ${KERBEROS_LIBDIR} ${KERBEROS_LIBRARY_DIRS})
53     list(APPEND KERBEROS_LIBRARIES ${_abspath_${_library}})
54   endforeach()
55 else()
56   # Fallback detection if pkg-config files are not installed.
57   # Note, this fallback will not add k5crypto and com_err libraries on Linux,
58   # ensure that pkg-config files are installed for full support.
59   find_path(KERBEROS_INCLUDE_DIR krb5.h
60     HINTS
61       "${KERBEROS_HINTS}/include"
62   )
64   set(KERBEROS_NAMES krb5 krb5_32 krb5_64)
65   find_library(KERBEROS_LIBRARY NAMES ${KERBEROS_NAMES}
66     HINTS
67       "${KERBEROS_HINTS}/lib"
68   )
70   # handle the QUIETLY and REQUIRED arguments and set KERBEROS_FOUND to TRUE if
71   # all listed variables are TRUE
72   include(FindPackageHandleStandardArgs)
73   find_package_handle_standard_args(KERBEROS DEFAULT_MSG KERBEROS_LIBRARY KERBEROS_INCLUDE_DIR)
75   if(KERBEROS_FOUND)
76     set(KERBEROS_LIBRARIES ${KERBEROS_LIBRARY})
77     set(KERBEROS_INCLUDE_DIRS ${KERBEROS_INCLUDE_DIR})
78   else()
79     set(KERBEROS_LIBRARIES)
80     set(KERBEROS_INCLUDE_DIRS)
81   endif()
82 endif()
84 # Try to detect the installed Kerberos vendor, assume MIT if it was not Heimdal.
85 if(KERBEROS_FOUND)
86   include(CheckSymbolExists)
87   include(CheckFunctionExists)
88   set(CMAKE_REQUIRED_INCLUDES ${KERBEROS_INCLUDE_DIRS})
89   set(CMAKE_REQUIRED_LIBRARIES ${KERBEROS_LIBRARIES})
90   #see also HAVE_HEIMDAL_KERBEROS in cmakeconfig.h.in
91   check_symbol_exists("heimdal_version" "krb5.h" HAVE_HEIMDAL_KERBEROS)
92   # see also HAVE_KRB5_PAC_VERIFY cmakeconfig.h.in
93   check_symbol_exists("krb5_pac_verify" "krb5.h" HAVE_KRB5_PAC_VERIFY)
94   # see also HAVE_KRB5_C_FX_CF2_SIMPLE in cmakeconfig.h.in
95   check_symbol_exists("krb5_c_fx_cf2_simple" "krb5.h" HAVE_KRB5_C_FX_CF2_SIMPLE)
96   check_function_exists(decode_krb5_enc_tkt_part HAVE_DECODE_KRB5_ENC_TKT_PART)
97   check_function_exists(encode_krb5_enc_tkt_part HAVE_ENCODE_KRB5_ENC_TKT_PART)
98   set(CMAKE_REQUIRED_INCLUDES)
99   set(CMAKE_REQUIRED_LIBRARIES)
100   if(NOT HAVE_HEIMDAL_KERBEROS)
101     set(HAVE_MIT_KERBEROS 1)
102   endif()
103 endif()
105 if(WIN32)
106   if(KERBEROS_FOUND)
107     set(KERBEROS_DLL_DIR "${KERBEROS_HINTS}/bin"
108       CACHE PATH "Path to the Kerberos DLLs"
109     )
110     file(GLOB _kerberos_dlls RELATIVE "${KERBEROS_DLL_DIR}"
111       "${KERBEROS_DLL_DIR}/comerr??.dll"
112       "${KERBEROS_DLL_DIR}/krb5_??.dll"
113       "${KERBEROS_DLL_DIR}/k5sprt??.dll"
114     )
115     set(KERBEROS_DLLS ${_kerberos_dlls}
116       # We're storing filenames only. Should we use STRING instead?
117       CACHE FILEPATH "Kerberos DLL list"
118     )
119     mark_as_advanced(KERBEROS_DLL_DIR KERBEROS_DLLS)
120   else()
121     set(KERBEROS_DLL_DIR)
122     set(KERBEROS_DLLS)
123   endif()
124 endif()
126 mark_as_advanced(KERBEROS_LIBRARIES KERBEROS_INCLUDE_DIRS KERBEROS_DEFINITIONS)