Debian Codegraph @

cmake/Modules/FindGSSAPI.cmake

raw
1 # - Try to find GSSAPI
2 # Once done this will define
3 #
4 # KRB5_CONFIG - Path to krb5-config
5 # GSSAPI_ROOT_DIR - Set this variable to the root installation of GSSAPI
6 #
7 # Read-Only variables:
8 # GSSAPI_FLAVOR_MIT - set to TRUE if MIT Kerberos has been found
9 # GSSAPI_FLAVOR_HEIMDAL - set to TRUE if Heimdal Keberos has been found
10 # GSSAPI_FOUND - system has GSSAPI
11 # GSSAPI_INCLUDE_DIR - the GSSAPI include directory
12 # GSSAPI_LIBRARIES - Link these to use GSSAPI
13 # GSSAPI_DEFINITIONS - Compiler switches required for using GSSAPI
14 # GSSAPI_PC_REQUIRES - pkg-config module name if found, needed for
15 # Requires.private for static linking
16 #
17 #=============================================================================
18 # Copyright (c) 2013 Andreas Schneider <[email protected]>
19 #
20 # Distributed under the OSI-approved BSD License (the "License");
21 # see accompanying file Copyright.txt for details.
22 #
23 # This software is distributed WITHOUT ANY WARRANTY; without even the
24 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25 # See the License for more information.
26 #=============================================================================
27 #
28
29 set(_mit_modname "mit-krb5-gssapi")
30 set(_heimdal_modname "heimdal-gssapi")
31
32 if(NOT _GSSAPI_ROOT_HINTS AND NOT _GSSAPI_ROOT_PATHS)
33 find_package(PkgConfig QUIET)
34 if (PKG_CONFIG_FOUND)
35 pkg_search_module(_GSSAPI ${_mit_modname} ${_heimdal_modname})
36 endif()
37 endif()
38
39 find_path(GSSAPI_ROOT_DIR
40 NAMES
41 include/gssapi.h
42 include/gssapi/gssapi.h
43 HINTS
44 ${_GSSAPI_ROOT_HINTS}
45 "${_GSSAPI_INCLUDEDIR}"
46 PATHS
47 ${_GSSAPI_ROOT_PATHS}
48 )
49 mark_as_advanced(GSSAPI_ROOT_DIR)
50
51 if (UNIX)
52 find_program(KRB5_CONFIG
53 NAMES
54 krb5-config
55 PATHS
56 ${GSSAPI_ROOT_DIR}/bin
57 /opt/local/bin)
58 mark_as_advanced(KRB5_CONFIG)
59
60 if (KRB5_CONFIG)
61 # Check if we have MIT KRB5
62 execute_process(
63 COMMAND
64 ${KRB5_CONFIG} --vendor
65 RESULT_VARIABLE
66 _GSSAPI_VENDOR_RESULT
67 OUTPUT_VARIABLE
68 _GSSAPI_VENDOR_STRING)
69
70 if ((_GSSAPI_VENDOR_STRING MATCHES ".*Massachusetts.*") OR (_GSSAPI_VENDOR_STRING
71 MATCHES ".*MITKerberosShim.*"))
72 set(GSSAPI_FLAVOR_MIT TRUE)
73 else()
74 execute_process(
75 COMMAND
76 ${KRB5_CONFIG} --libs gssapi
77 RESULT_VARIABLE
78 _GSSAPI_LIBS_RESULT
79 OUTPUT_VARIABLE
80 _GSSAPI_LIBS_STRING)
81
82 if (_GSSAPI_LIBS_STRING MATCHES ".*roken.*")
83 set(GSSAPI_FLAVOR_HEIMDAL TRUE)
84 endif()
85 endif()
86
87 # Get the include dir
88 execute_process(
89 COMMAND
90 ${KRB5_CONFIG} --cflags gssapi
91 RESULT_VARIABLE
92 _GSSAPI_INCLUDE_RESULT
93 OUTPUT_VARIABLE
94 _GSSAPI_INCLUDE_STRING)
95 string(REGEX REPLACE "(\r?\n)+$" "" _GSSAPI_INCLUDE_STRING "${_GSSAPI_INCLUDE_STRING}")
96 string(REGEX REPLACE " *-I" "" _GSSAPI_INCLUDEDIR "${_GSSAPI_INCLUDE_STRING}")
97 endif()
98
99 if (NOT GSSAPI_FLAVOR_MIT AND NOT GSSAPI_FLAVOR_HEIMDAL)
100 # Check for HEIMDAL
101 find_package(PkgConfig)
102 if (PKG_CONFIG_FOUND)
103 pkg_check_modules(_GSSAPI heimdal-gssapi)
104 endif (PKG_CONFIG_FOUND)
105
106 if (_GSSAPI_FOUND)
107 set(GSSAPI_FLAVOR_HEIMDAL TRUE)
108 else()
109 find_path(_GSSAPI_ROKEN
110 NAMES
111 roken.h
112 PATHS
113 ${GSSAPI_ROOT_DIR}/include
114 ${_GSSAPI_INCLUDEDIR})
115 if (_GSSAPI_ROKEN)
116 set(GSSAPI_FLAVOR_HEIMDAL TRUE)
117 endif()
118 endif ()
119 endif()
120 endif (UNIX)
121
122 find_path(GSSAPI_INCLUDE_DIR
123 NAMES
124 gssapi.h
125 gssapi/gssapi.h
126 PATHS
127 ${GSSAPI_ROOT_DIR}/include
128 ${_GSSAPI_INCLUDEDIR}
129 )
130
131 if (GSSAPI_FLAVOR_MIT)
132 find_library(GSSAPI_LIBRARY
133 NAMES
134 gssapi_krb5
135 PATHS
136 ${GSSAPI_ROOT_DIR}/lib
137 ${_GSSAPI_LIBDIR}
138 )
139
140 find_library(KRB5_LIBRARY
141 NAMES
142 krb5
143 PATHS
144 ${GSSAPI_ROOT_DIR}/lib
145 ${_GSSAPI_LIBDIR}
146 )
147
148 find_library(K5CRYPTO_LIBRARY
149 NAMES
150 k5crypto
151 PATHS
152 ${GSSAPI_ROOT_DIR}/lib
153 ${_GSSAPI_LIBDIR}
154 )
155
156 find_library(COM_ERR_LIBRARY
157 NAMES
158 com_err
159 PATHS
160 ${GSSAPI_ROOT_DIR}/lib
161 ${_GSSAPI_LIBDIR}
162 )
163
164 if (GSSAPI_LIBRARY)
165 set(GSSAPI_LIBRARIES
166 ${GSSAPI_LIBRARIES}
167 ${GSSAPI_LIBRARY}
168 )
169 endif (GSSAPI_LIBRARY)
170
171 if (KRB5_LIBRARY)
172 set(GSSAPI_LIBRARIES
173 ${GSSAPI_LIBRARIES}
174 ${KRB5_LIBRARY}
175 )
176 endif (KRB5_LIBRARY)
177
178 if (K5CRYPTO_LIBRARY)
179 set(GSSAPI_LIBRARIES
180 ${GSSAPI_LIBRARIES}
181 ${K5CRYPTO_LIBRARY}
182 )
183 endif (K5CRYPTO_LIBRARY)
184
185 if (COM_ERR_LIBRARY)
186 set(GSSAPI_LIBRARIES
187 ${GSSAPI_LIBRARIES}
188 ${COM_ERR_LIBRARY}
189 )
190 endif (COM_ERR_LIBRARY)
191 endif (GSSAPI_FLAVOR_MIT)
192
193 if (GSSAPI_FLAVOR_HEIMDAL)
194 find_library(GSSAPI_LIBRARY
195 NAMES
196 gssapi
197 PATHS
198 ${GSSAPI_ROOT_DIR}/lib
199 ${_GSSAPI_LIBDIR}
200 )
201
202 find_library(KRB5_LIBRARY
203 NAMES
204 krb5
205 PATHS
206 ${GSSAPI_ROOT_DIR}/lib
207 ${_GSSAPI_LIBDIR}
208 )
209
210 find_library(HCRYPTO_LIBRARY
211 NAMES
212 hcrypto
213 PATHS
214 ${GSSAPI_ROOT_DIR}/lib
215 ${_GSSAPI_LIBDIR}
216 )
217
218 find_library(COM_ERR_LIBRARY
219 NAMES
220 com_err
221 PATHS
222 ${GSSAPI_ROOT_DIR}/lib
223 ${_GSSAPI_LIBDIR}
224 )
225
226 find_library(HEIMNTLM_LIBRARY
227 NAMES
228 heimntlm
229 PATHS
230 ${GSSAPI_ROOT_DIR}/lib
231 ${_GSSAPI_LIBDIR}
232 )
233
234 find_library(HX509_LIBRARY
235 NAMES
236 hx509
237 PATHS
238 ${GSSAPI_ROOT_DIR}/lib
239 ${_GSSAPI_LIBDIR}
240 )
241
242 find_library(ASN1_LIBRARY
243 NAMES
244 asn1
245 PATHS
246 ${GSSAPI_ROOT_DIR}/lib
247 ${_GSSAPI_LIBDIR}
248 )
249
250 find_library(WIND_LIBRARY
251 NAMES
252 wind
253 PATHS
254 ${GSSAPI_ROOT_DIR}/lib
255 ${_GSSAPI_LIBDIR}
256 )
257
258 find_library(ROKEN_LIBRARY
259 NAMES
260 roken
261 PATHS
262 ${GSSAPI_ROOT_DIR}/lib
263 ${_GSSAPI_LIBDIR}
264 )
265
266 if (GSSAPI_LIBRARY)
267 set(GSSAPI_LIBRARIES
268 ${GSSAPI_LIBRARIES}
269 ${GSSAPI_LIBRARY}
270 )
271 endif (GSSAPI_LIBRARY)
272
273 if (KRB5_LIBRARY)
274 set(GSSAPI_LIBRARIES
275 ${GSSAPI_LIBRARIES}
276 ${KRB5_LIBRARY}
277 )
278 endif (KRB5_LIBRARY)
279
280 if (HCRYPTO_LIBRARY)
281 set(GSSAPI_LIBRARIES
282 ${GSSAPI_LIBRARIES}
283 ${HCRYPTO_LIBRARY}
284 )
285 endif (HCRYPTO_LIBRARY)
286
287 if (COM_ERR_LIBRARY)
288 set(GSSAPI_LIBRARIES
289 ${GSSAPI_LIBRARIES}
290 ${COM_ERR_LIBRARY}
291 )
292 endif (COM_ERR_LIBRARY)
293
294 if (HEIMNTLM_LIBRARY)
295 set(GSSAPI_LIBRARIES
296 ${GSSAPI_LIBRARIES}
297 ${HEIMNTLM_LIBRARY}
298 )
299 endif (HEIMNTLM_LIBRARY)
300
301 if (HX509_LIBRARY)
302 set(GSSAPI_LIBRARIES
303 ${GSSAPI_LIBRARIES}
304 ${HX509_LIBRARY}
305 )
306 endif (HX509_LIBRARY)
307
308 if (ASN1_LIBRARY)
309 set(GSSAPI_LIBRARIES
310 ${GSSAPI_LIBRARIES}
311 ${ASN1_LIBRARY}
312 )
313 endif (ASN1_LIBRARY)
314
315 if (WIND_LIBRARY)
316 set(GSSAPI_LIBRARIES
317 ${GSSAPI_LIBRARIES}
318 ${WIND_LIBRARY}
319 )
320 endif (WIND_LIBRARY)
321
322 if (ROKEN_LIBRARY)
323 set(GSSAPI_LIBRARIES
324 ${GSSAPI_LIBRARIES}
325 ${WIND_LIBRARY}
326 )
327 endif (ROKEN_LIBRARY)
328 endif (GSSAPI_FLAVOR_HEIMDAL)
329
330 include(FindPackageHandleStandardArgs)
331 find_package_handle_standard_args(GSSAPI DEFAULT_MSG GSSAPI_LIBRARIES GSSAPI_INCLUDE_DIR)
332
333 if(GSSAPI_FOUND)
334 if(_GSSAPI_FOUND) # via pkg-config
335 if (GSSAPI_FLAVOR_MIT)
336 set(GSSAPI_PC_REQUIRES ${_mit_modname})
337 elseif (GSSAPI_FLAVOR_HEIMDAL)
338 set(GSSAPI_PC_REQUIRES ${_heimdal_modname})
339 endif()
340 endif()
341 endif()
342
343 # show the GSSAPI_INCLUDE_DIR and GSSAPI_LIBRARIES variables only in the advanced view
344 mark_as_advanced(GSSAPI_INCLUDE_DIR GSSAPI_LIBRARIES)