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