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