summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake')
-rw-r--r--cmake/modules/FindGpgme.cmake411
1 files changed, 4 insertions, 407 deletions
diff --git a/cmake/modules/FindGpgme.cmake b/cmake/modules/FindGpgme.cmake
index a563c568..ea4a750d 100644
--- a/cmake/modules/FindGpgme.cmake
+++ b/cmake/modules/FindGpgme.cmake
@@ -1,408 +1,5 @@
1# Code is taken from KDE project: 1find_path(GPGME_INCLUDE_DIR NAMES gpgme.h)
2# http://code.metager.de/source/xref/kde/kdepimlibs/cmake/modules/FindGpgme.cmake 2find_library(GPGME_LIBRARIES NAMES gpgme)
3#
4# - Try to find the gpgme library
5#
6# Algorithm:
7# - Windows:
8# On Windows, there's three gpgme variants: gpgme{,-glib,-qt}.
9# - The variant used determines the event loop integration possible:
10# - gpgme: no event loop integration possible, only synchronous operations supported
11# - gpgme-glib: glib event loop integration possible, only asynchronous operations supported
12# - gpgme-qt: qt event loop integration possible, only asynchronous operations supported
13# - GPGME_{VANILLA,GLIB,QT}_{FOUND,LIBRARIES} will be set for each of the above
14# - GPGME_INCLUDES is the same for all of the above
15# - GPGME_FOUND is set if any of the above was found
16# - *nix:
17# There's also three variants: gpgme{,-pthread,-pth}.
18# - The variant used determines the multithreaded use possible:
19# - gpgme: no multithreading support available
20# - gpgme-pthread: multithreading available using POSIX threads
21# - gpgme-pth: multithreading available using GNU PTH (cooperative multithreading)
22# - GPGME_{VANILLA,PTH,PTHREAD}_{FOUND,LIBRARIES} will be set for each of the above
23# - GPGME_INCLUDES is the same for all of the above
24# - GPGME_FOUND is set if any of the above was found
25#
26# GPGME_LIBRARY_DIR - the directory where the libraries are located
27 3
28# 4include(FindPackageHandleStandardArgs)
29# THIS IS ALMOST A 1:1 COPY OF FindAssuan.cmake in kdepim. 5find_package_handle_standard_args(GPGME DEFAULT_MSG GPGME_INCLUDE_DIR GPGME_LIBRARIES)
30# Any changes here likely apply there, too.
31#
32
33# do away with crappy condition repetition on else/endfoo
34set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS_gpgme_saved ${CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS} )
35set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true )
36
37#if this is built-in, please replace, if it isn't, export into a MacroToBool.cmake of it's own
38macro( macro_bool_to_bool FOUND_VAR )
39 foreach( _current_VAR ${ARGN} )
40 if ( ${FOUND_VAR} )
41 set( ${_current_VAR} TRUE )
42 else()
43 set( ${_current_VAR} FALSE )
44 endif()
45 endforeach()
46endmacro()
47
48#include (MacroEnsureVersion)
49
50
51
52if ( WIN32 )
53
54 # On Windows, we don't have a gpgme-config script, so we need to
55 # look for the stuff ourselves:
56
57 # in cmake, AND and OR have the same precedence, there's no
58 # subexpressions, and expressions are evaluated short-circuit'ed
59 # IOW: CMake if() suxx.
60 # Starting with CMake 2.6.3 you can group if expressions with (), but we
61 # don't require 2.6.3 but 2.6.2, we can't use it. Alex
62 set( _seem_to_have_cached_gpgme false )
63 if ( GPGME_INCLUDES )
64 if ( GPGME_VANILLA_LIBRARIES OR GPGME_QT_LIBRARIES OR GPGME_GLIB_LIBRARIES )
65 set( _seem_to_have_cached_gpgme true )
66 endif()
67 endif()
68
69 if ( _seem_to_have_cached_gpgme )
70
71 macro_bool_to_bool( GPGME_VANILLA_LIBRARIES GPGME_VANILLA_FOUND )
72 macro_bool_to_bool( GPGME_GLIB_LIBRARIES GPGME_GLIB_FOUND )
73 macro_bool_to_bool( GPGME_QT_LIBRARIES GPGME_QT_FOUND )
74 # this would have been preferred:
75 #set( GPGME_*_FOUND macro_bool_to_bool(GPGME_*_LIBRARIES) )
76
77 if ( GPGME_VANILLA_FOUND OR GPGME_GLIB_FOUND OR GPGME_QT_FOUND )
78 set( GPGME_FOUND true )
79 else()
80 set( GPGME_FOUND false )
81 endif()
82
83 else()
84
85 # is this needed, of just unreflected cut'n'paste?
86 # this isn't a KDE library, after all!
87 if( NOT KDEWIN_FOUND )
88 find_package( KDEWIN REQUIRED )
89 endif()
90
91 set( GPGME_FOUND false )
92 set( GPGME_VANILLA_FOUND false )
93 set( GPGME_GLIB_FOUND false )
94 set( GPGME_QT_FOUND false )
95
96 find_path( GPGME_INCLUDES gpgme.h
97 ${CMAKE_INCLUDE_PATH}
98 ${CMAKE_INSTALL_PREFIX}/include
99 )
100
101 if (NOT WINCE)
102 find_library( _gpgme_vanilla_library NAMES gpgme libgpgme gpgme-11 libgpgme-11
103 PATHS
104 ${CMAKE_LIBRARY_PATH}
105 ${CMAKE_INSTALL_PREFIX}/lib
106 )
107 else (NOT WINCE)
108 find_library( _gpgme_vanilla_library NAMES libgpgme-11-msc
109 PATHS
110 ${CMAKE_LIBRARY_PATH}
111 ${CMAKE_INSTALL_PREFIX}/lib
112 )
113 endif()
114
115 find_library( _gpgme_glib_library NAMES gpgme-glib libgpgme-glib gpgme-glib-11 libgpgme-glib-11
116 PATHS
117 ${CMAKE_LIBRARY_PATH}
118 ${CMAKE_INSTALL_PREFIX}/lib
119 )
120
121 find_library( _gpgme_qt_library NAMES gpgme-qt libgpgme-qt gpgme-qt-11 libgpgme-qt-11
122 PATHS
123 ${CMAKE_LIBRARY_PATH}
124 ${CMAKE_INSTALL_PREFIX}/lib
125 )
126
127 if ( WINCE )
128 set( _gpg_error_library )
129 else()
130 find_library( _gpg_error_library NAMES gpg-error libgpg-error gpg-error-0 libgpg-error-0
131 PATHS
132 ${CMAKE_LIBRARY_PATH}
133 ${CMAKE_INSTALL_PREFIX}/lib
134 )
135 endif()
136
137 set( GPGME_INCLUDES ${GPGME_INCLUDES} )
138
139 if ( _gpgme_vanilla_library AND ( _gpg_error_library OR WINCE ) )
140 set( GPGME_VANILLA_LIBRARIES ${_gpgme_vanilla_library} ${_gpg_error_library} )
141 set( GPGME_VANILLA_FOUND true )
142 set( GPGME_FOUND true )
143 endif()
144
145 if ( _gpgme_glib_library AND ( _gpg_error_library OR WINCE ) )
146 set( GPGME_GLIB_LIBRARIES ${_gpgme_glib_library} ${_gpg_error_library} )
147 set( GPGME_GLIB_FOUND true )
148 set( GPGME_FOUND true )
149 endif()
150
151 if ( _gpgme_qt_library AND ( _gpg_error_library OR WINCE ) )
152 set( GPGME_QT_LIBRARIES ${_gpgme_qt_library} ${_gpg_error_library} )
153 set( GPGME_QT_FOUND true )
154 set( GPGME_FOUND true )
155 endif()
156
157 endif()
158
159 # these are Unix-only:
160 set( GPGME_PTHREAD_FOUND false )
161 set( GPGME_PTH_FOUND false )
162 set( HAVE_GPGME_PTHREAD 0 )
163 set( HAVE_GPGME_PTH 0 )
164
165 macro_bool_to_01( GPGME_FOUND HAVE_GPGME )
166 macro_bool_to_01( GPGME_VANILLA_FOUND HAVE_GPGME_VANILLA )
167 macro_bool_to_01( GPGME_GLIB_FOUND HAVE_GPGME_GLIB )
168 macro_bool_to_01( GPGME_QT_FOUND HAVE_GPGME_QT )
169
170else() # not WIN32
171
172 # On *nix, we have the gpgme-config script which can tell us all we
173 # need to know:
174
175 # see WIN32 case for an explanation of what this does:
176 set( _seem_to_have_cached_gpgme false )
177 if ( GPGME_INCLUDES )
178 if ( GPGME_VANILLA_LIBRARIES OR GPGME_PTHREAD_LIBRARIES OR GPGME_PTH_LIBRARIES )
179 set( _seem_to_have_cached_gpgme true )
180 endif()
181 endif()
182
183 if ( _seem_to_have_cached_gpgme )
184
185 macro_bool_to_bool( GPGME_VANILLA_LIBRARIES GPGME_VANILLA_FOUND )
186 macro_bool_to_bool( GPGME_PTHREAD_LIBRARIES GPGME_PTHREAD_FOUND )
187 macro_bool_to_bool( GPGME_PTH_LIBRARIES GPGME_PTH_FOUND )
188
189 if ( GPGME_VANILLA_FOUND OR GPGME_PTHREAD_FOUND OR GPGME_PTH_FOUND )
190 set( GPGME_FOUND true )
191 else()
192 set( GPGME_FOUND false )
193 endif()
194
195 else()
196
197 set( GPGME_FOUND false )
198 set( GPGME_VANILLA_FOUND false )
199 set( GPGME_PTHREAD_FOUND false )
200 set( GPGME_PTH_FOUND false )
201
202 find_program( _GPGMECONFIG_EXECUTABLE NAMES gpgme-config )
203
204 # if gpgme-config has been found
205 if ( _GPGMECONFIG_EXECUTABLE )
206
207 message( STATUS "Found gpgme-config at ${_GPGMECONFIG_EXECUTABLE}" )
208
209 exec_program( ${_GPGMECONFIG_EXECUTABLE} ARGS --version OUTPUT_VARIABLE GPGME_VERSION )
210
211# set( _GPGME_MIN_VERSION "1.1.7" )
212# macro_ensure_version( ${_GPGME_MIN_VERSION} ${GPGME_VERSION} _GPGME_INSTALLED_VERSION_OK )
213
214# if ( NOT _GPGME_INSTALLED_VERSION_OK )
215
216# message( STATUS "The installed version of gpgme is too old: ${GPGME_VERSION} (required: >= ${_GPGME_MIN_VERSION})" )
217
218# else()
219
220 message( STATUS "Found gpgme v${GPGME_VERSION}, checking for flavours..." )
221
222 exec_program( ${_GPGMECONFIG_EXECUTABLE} ARGS --libs OUTPUT_VARIABLE _gpgme_config_vanilla_libs RETURN_VALUE _ret )
223 if ( _ret )
224 set( _gpgme_config_vanilla_libs )
225 endif()
226
227 exec_program( ${_GPGMECONFIG_EXECUTABLE} ARGS --thread=pthread --libs OUTPUT_VARIABLE _gpgme_config_pthread_libs RETURN_VALUE _ret )
228 if ( _ret )
229 set( _gpgme_config_pthread_libs )
230 endif()
231
232 exec_program( ${_GPGMECONFIG_EXECUTABLE} ARGS --thread=pth --libs OUTPUT_VARIABLE _gpgme_config_pth_libs RETURN_VALUE _ret )
233 if ( _ret )
234 set( _gpgme_config_pth_libs )
235 endif()
236
237 # append -lgpg-error to the list of libraries, if necessary
238 foreach ( _flavour vanilla pthread pth )
239 if ( _gpgme_config_${_flavour}_libs AND NOT _gpgme_config_${_flavour}_libs MATCHES "lgpg-error" )
240 set( _gpgme_config_${_flavour}_libs "${_gpgme_config_${_flavour}_libs} -lgpg-error" )
241 endif()
242 endforeach()
243
244 if ( _gpgme_config_vanilla_libs OR _gpgme_config_pthread_libs OR _gpgme_config_pth_libs )
245
246 exec_program( ${_GPGMECONFIG_EXECUTABLE} ARGS --cflags OUTPUT_VARIABLE _GPGME_CFLAGS )
247
248 if ( _GPGME_CFLAGS )
249 string( REGEX REPLACE "(\r?\n)+$" " " _GPGME_CFLAGS "${_GPGME_CFLAGS}" )
250 string( REGEX REPLACE " *-I" ";" GPGME_INCLUDES "${_GPGME_CFLAGS}" )
251 endif()
252
253 foreach ( _flavour vanilla pthread pth )
254 if ( _gpgme_config_${_flavour}_libs )
255
256 set( _gpgme_library_dirs )
257 set( _gpgme_library_names )
258 string( TOUPPER "${_flavour}" _FLAVOUR )
259
260 string( REGEX REPLACE " +" ";" _gpgme_config_${_flavour}_libs "${_gpgme_config_${_flavour}_libs}" )
261
262 foreach( _flag ${_gpgme_config_${_flavour}_libs} )
263 if ( "${_flag}" MATCHES "^-L" )
264 string( REGEX REPLACE "^-L" "" _dir "${_flag}" )
265 file( TO_CMAKE_PATH "${_dir}" _dir )
266 set( _gpgme_library_dirs ${_gpgme_library_dirs} "${_dir}" )
267 elseif( "${_flag}" MATCHES "^-l" )
268 string( REGEX REPLACE "^-l" "" _name "${_flag}" )
269 set( _gpgme_library_names ${_gpgme_library_names} "${_name}" )
270 endif()
271 endforeach()
272
273 set( GPGME_${_FLAVOUR}_FOUND true )
274
275 foreach( _name ${_gpgme_library_names} )
276 set( _gpgme_${_name}_lib )
277
278 # if -L options were given, look only there
279 if ( _gpgme_library_dirs )
280 find_library( _gpgme_${_name}_lib NAMES ${_name} PATHS ${_gpgme_library_dirs} NO_DEFAULT_PATH )
281 endif()
282
283 # if not found there, look in system directories
284 if ( NOT _gpgme_${_name}_lib )
285 find_library( _gpgme_${_name}_lib NAMES ${_name} )
286 endif()
287
288 # if still not found, then the whole flavour isn't found
289 if ( NOT _gpgme_${_name}_lib )
290 if ( GPGME_${_FLAVOUR}_FOUND )
291 set( GPGME_${_FLAVOUR}_FOUND false )
292 set( _not_found_reason "dependent library ${_name} wasn't found" )
293 endif()
294 endif()
295
296 set( GPGME_${_FLAVOUR}_LIBRARIES ${GPGME_${_FLAVOUR}_LIBRARIES} "${_gpgme_${_name}_lib}" )
297 endforeach()
298
299 #check_c_library_exists_explicit( gpgme gpgme_check_version "${_GPGME_CFLAGS}" "${GPGME_LIBRARIES}" GPGME_FOUND )
300 if ( GPGME_${_FLAVOUR}_FOUND )
301 message( STATUS " Found flavour '${_flavour}', checking whether it's usable...yes" )
302 else()
303 message( STATUS " Found flavour '${_flavour}', checking whether it's usable...no" )
304 message( STATUS " (${_not_found_reason})" )
305 endif()
306 endif()
307
308 endforeach( _flavour )
309
310 # ensure that they are cached
311 # This comment above doesn't make sense, the four following lines seem to do nothing. Alex
312 set( GPGME_INCLUDES ${GPGME_INCLUDES} )
313 set( GPGME_VANILLA_LIBRARIES ${GPGME_VANILLA_LIBRARIES} )
314 set( GPGME_PTHREAD_LIBRARIES ${GPGME_PTHREAD_LIBRARIES} )
315 set( GPGME_PTH_LIBRARIES ${GPGME_PTH_LIBRARIES} )
316
317 if ( GPGME_VANILLA_FOUND OR GPGME_PTHREAD_FOUND OR GPGME_PTH_FOUND )
318 set( GPGME_FOUND true )
319 else()
320 set( GPGME_FOUND false )
321 endif()
322
323# endif()
324
325 endif()
326
327 endif()
328
329 endif()
330
331 # these are Windows-only:
332 set( GPGME_GLIB_FOUND false )
333 set( GPGME_QT_FOUND false )
334 set( HAVE_GPGME_GLIB 0 )
335 set( HAVE_GPGME_QT 0 )
336
337 # macro_bool_to_01( GPGME_FOUND HAVE_GPGME )
338 # macro_bool_to_01( GPGME_VANILLA_FOUND HAVE_GPGME_VANILLA )
339 # macro_bool_to_01( GPGME_PTHREAD_FOUND HAVE_GPGME_PTHREAD )
340 # macro_bool_to_01( GPGME_PTH_FOUND HAVE_GPGME_PTH )
341
342endif() # WIN32 | Unix
343
344
345set( _gpgme_flavours "" )
346
347if ( GPGME_VANILLA_FOUND )
348 set( _gpgme_flavours "${_gpgme_flavours} vanilla" )
349endif()
350
351if ( GPGME_GLIB_FOUND )
352 set( _gpgme_flavours "${_gpgme_flavours} Glib" )
353endif()
354
355if ( GPGME_QT_FOUND )
356 set( _gpgme_flavours "${_gpgme_flavours} Qt" )
357endif()
358
359if ( GPGME_PTHREAD_FOUND )
360 set( _gpgme_flavours "${_gpgme_flavours} pthread" )
361endif()
362
363if ( GPGME_PTH_FOUND )
364 set( _gpgme_flavours "${_gpgme_flavours} pth" )
365endif()
366
367# determine the library in one of the found flavours, can be reused e.g. by FindQgpgme.cmake, Alex
368foreach(_currentFlavour vanilla glib qt pth pthread)
369 if(NOT GPGME_LIBRARY_DIR)
370 get_filename_component(GPGME_LIBRARY_DIR "${_gpgme_${_currentFlavour}_lib}" PATH)
371 endif()
372endforeach()
373
374if ( NOT Gpgme_FIND_QUIETLY )
375
376 if ( GPGME_FOUND )
377 message( STATUS "Usable gpgme flavours found: ${_gpgme_flavours}" )
378 else()
379 message( STATUS "No usable gpgme flavours found." )
380 endif()
381
382 macro_bool_to_bool( Gpgme_FIND_REQUIRED _req )
383
384 if ( WIN32 )
385 set( _gpgme_homepage "http://www.gpg4win.org" )
386 else()
387 set( _gpgme_homepage "http://www.gnupg.org/related_software/gpgme" )
388 endif()
389
390 # macro_log_feature(
391 # GPGME_FOUND
392 # "gpgme"
393 # "GNU Privacy Guard (GPG/PGP) support"
394 # ${_gpgme_homepage}
395 # ${_req}
396 # "${_GPGME_MIN_VERSION} or greater"
397 # "Necessary to compile many PIM applications, including KMail"
398 #)
399
400else()
401
402 if ( Gpgme_FIND_REQUIRED AND NOT GPGME_FOUND )
403 message( FATAL_ERROR "Did not find GPGME" )
404 endif()
405
406endif()
407
408set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS_gpgme_saved )