Warning, /utilities/basket/cmake/Modules/FindGpgme.cmake is written in an unsupported language. File is not indexed.
0001 # - Try to find the gpgme library 0002 # 0003 # Algorithm: 0004 # - Windows: 0005 # On Windows, there's three gpgme variants: gpgme{,-glib,-qt}. 0006 # - The variant used determines the event loop integration possible: 0007 # - gpgme: no event loop integration possible, only synchronous operations supported 0008 # - gpgme-glib: glib event loop integration possible, only asynchronous operations supported 0009 # - gpgme-qt: qt event loop integration possible, only asynchronous operations supported 0010 # - GPGME_{VANILLA,GLIB,QT}_{FOUND,LIBRARIES} will be set for each of the above 0011 # - GPGME_INCLUDES is the same for all of the above 0012 # - GPGME_FOUND is set if any of the above was found 0013 # - *nix: 0014 # There's also three variants: gpgme{,-pthread,-pth}. 0015 # - The variant used determines the multithreaded use possible: 0016 # - gpgme: no multithreading support available 0017 # - gpgme-pthread: multithreading available using POSIX threads 0018 # - gpgme-pth: multithreading available using GNU PTH (cooperative multithreading) 0019 # - GPGME_{VANILLA,PTH,PTHREAD}_{FOUND,LIBRARIES} will be set for each of the above 0020 # - GPGME_INCLUDES is the same for all of the above 0021 # - GPGME_FOUND is set if any of the above was found 0022 # 0023 # GPGME_LIBRARY_DIR - the directory where the libraries are located 0024 0025 # 0026 # THIS IS ALMOST A 1:1 COPY OF FindAssuan.cmake in kdepim. 0027 # Any changes here likely apply there, too. 0028 # 0029 0030 # do away with crappy condition repetition on else/endfoo 0031 set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS_gpgme_saved ${CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS} ) 0032 set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true ) 0033 0034 #if this is built-in, please replace, if it isn't, export into a MacroToBool.cmake of it's own 0035 macro( macro_bool_to_bool FOUND_VAR ) 0036 foreach( _current_VAR ${ARGN} ) 0037 if ( ${FOUND_VAR} ) 0038 set( ${_current_VAR} TRUE ) 0039 else() 0040 set( ${_current_VAR} FALSE ) 0041 endif() 0042 endforeach() 0043 endmacro() 0044 0045 #HACK: local copy... 0046 MACRO(MACRO_BOOL_TO_01 FOUND_VAR ) 0047 FOREACH (_current_VAR ${ARGN}) 0048 IF(${FOUND_VAR}) 0049 SET(${_current_VAR} 1) 0050 ELSE(${FOUND_VAR}) 0051 SET(${_current_VAR} 0) 0052 ENDIF(${FOUND_VAR}) 0053 ENDFOREACH(_current_VAR) 0054 ENDMACRO(MACRO_BOOL_TO_01) 0055 0056 0057 if ( WIN32 ) 0058 0059 # On Windows, we don't have a gpgme-config script, so we need to 0060 # look for the stuff ourselves: 0061 0062 # in cmake, AND and OR have the same precedence, there's no 0063 # subexpressions, and expressions are evaluated short-circuit'ed 0064 # IOW: CMake if() suxx. 0065 # Starting with CMake 2.6.3 you can group if expressions with (), but we 0066 # don't require 2.6.3 but 2.6.2, we can't use it. Alex 0067 set( _seem_to_have_cached_gpgme false ) 0068 if ( GPGME_INCLUDES ) 0069 if ( GPGME_VANILLA_LIBRARIES OR GPGME_QT_LIBRARIES OR GPGME_GLIB_LIBRARIES ) 0070 set( _seem_to_have_cached_gpgme true ) 0071 endif() 0072 endif() 0073 0074 if ( _seem_to_have_cached_gpgme ) 0075 0076 macro_bool_to_bool( GPGME_VANILLA_LIBRARIES GPGME_VANILLA_FOUND ) 0077 macro_bool_to_bool( GPGME_GLIB_LIBRARIES GPGME_GLIB_FOUND ) 0078 macro_bool_to_bool( GPGME_QT_LIBRARIES GPGME_QT_FOUND ) 0079 # this would have been preferred: 0080 #set( GPGME_*_FOUND macro_bool_to_bool(GPGME_*_LIBRARIES) ) 0081 0082 if ( GPGME_VANILLA_FOUND OR GPGME_GLIB_FOUND OR GPGME_QT_FOUND ) 0083 set( GPGME_FOUND true ) 0084 else() 0085 set( GPGME_FOUND false ) 0086 endif() 0087 0088 else() 0089 0090 set( GPGME_FOUND false ) 0091 set( GPGME_VANILLA_FOUND false ) 0092 set( GPGME_GLIB_FOUND false ) 0093 set( GPGME_QT_FOUND false ) 0094 0095 find_path( GPGME_INCLUDES gpgme.h 0096 ${CMAKE_INCLUDE_PATH} 0097 ${CMAKE_INSTALL_PREFIX}/include 0098 ) 0099 0100 find_library( _gpgme_vanilla_library NAMES gpgme libgpgme gpgme-11 libgpgme-11 0101 PATHS 0102 ${CMAKE_LIBRARY_PATH} 0103 ${CMAKE_INSTALL_PREFIX}/lib 0104 ) 0105 0106 find_library( _gpgme_glib_library NAMES gpgme-glib libgpgme-glib gpgme-glib-11 libgpgme-glib-11 0107 PATHS 0108 ${CMAKE_LIBRARY_PATH} 0109 ${CMAKE_INSTALL_PREFIX}/lib 0110 ) 0111 0112 find_library( _gpgme_qt_library NAMES gpgme-qt libgpgme-qt gpgme-qt-11 libgpgme-qt-11 0113 PATHS 0114 ${CMAKE_LIBRARY_PATH} 0115 ${CMAKE_INSTALL_PREFIX}/lib 0116 ) 0117 0118 find_library( _gpg_error_library NAMES gpg-error libgpg-error gpg-error-0 libgpg-error-0 0119 PATHS 0120 ${CMAKE_LIBRARY_PATH} 0121 ${CMAKE_INSTALL_PREFIX}/lib 0122 ) 0123 0124 set( GPGME_INCLUDES ${GPGME_INCLUDES} ) 0125 0126 if ( _gpgme_vanilla_library AND _gpg_error_library ) 0127 set( GPGME_VANILLA_LIBRARIES ${_gpgme_vanilla_library} ${_gpg_error_library} ) 0128 set( GPGME_VANILLA_FOUND true ) 0129 set( GPGME_FOUND true ) 0130 endif() 0131 0132 if ( _gpgme_glib_library AND _gpg_error_library ) 0133 set( GPGME_GLIB_LIBRARIES ${_gpgme_glib_library} ${_gpg_error_library} ) 0134 set( GPGME_GLIB_FOUND true ) 0135 set( GPGME_FOUND true ) 0136 endif() 0137 0138 if ( _gpgme_qt_library AND _gpg_error_library ) 0139 set( GPGME_QT_LIBRARIES ${_gpgme_qt_library} ${_gpg_error_library} ) 0140 set( GPGME_QT_FOUND true ) 0141 set( GPGME_FOUND true ) 0142 endif() 0143 0144 endif() 0145 0146 # these are Unix-only: 0147 set( GPGME_PTHREAD_FOUND false ) 0148 set( GPGME_PTH_FOUND false ) 0149 set( HAVE_GPGME_PTHREAD 0 ) 0150 set( HAVE_GPGME_PTH 0 ) 0151 0152 macro_bool_to_01( GPGME_FOUND HAVE_GPGME ) 0153 macro_bool_to_01( GPGME_VANILLA_FOUND HAVE_GPGME_VANILLA ) 0154 macro_bool_to_01( GPGME_GLIB_FOUND HAVE_GPGME_GLIB ) 0155 macro_bool_to_01( GPGME_QT_FOUND HAVE_GPGME_QT ) 0156 0157 else() # not WIN32 0158 0159 # On *nix, we have the gpgme-config script which can tell us all we 0160 # need to know: 0161 0162 # see WIN32 case for an explanation of what this does: 0163 set( _seem_to_have_cached_gpgme false ) 0164 if ( GPGME_INCLUDES ) 0165 if ( GPGME_VANILLA_LIBRARIES OR GPGME_PTHREAD_LIBRARIES OR GPGME_PTH_LIBRARIES ) 0166 set( _seem_to_have_cached_gpgme true ) 0167 endif() 0168 endif() 0169 0170 if ( _seem_to_have_cached_gpgme ) 0171 0172 macro_bool_to_bool( GPGME_VANILLA_LIBRARIES GPGME_VANILLA_FOUND ) 0173 macro_bool_to_bool( GPGME_PTHREAD_LIBRARIES GPGME_PTHREAD_FOUND ) 0174 macro_bool_to_bool( GPGME_PTH_LIBRARIES GPGME_PTH_FOUND ) 0175 0176 if ( GPGME_VANILLA_FOUND OR GPGME_PTHREAD_FOUND OR GPGME_PTH_FOUND ) 0177 set( GPGME_FOUND true ) 0178 else() 0179 set( GPGME_FOUND false ) 0180 endif() 0181 0182 else() 0183 0184 set( GPGME_FOUND false ) 0185 set( GPGME_VANILLA_FOUND false ) 0186 set( GPGME_PTHREAD_FOUND false ) 0187 set( GPGME_PTH_FOUND false ) 0188 0189 find_program( _GPGMECONFIG_EXECUTABLE NAMES gpgme-config ) 0190 0191 # if gpgme-config has been found 0192 if ( _GPGMECONFIG_EXECUTABLE ) 0193 0194 message( STATUS "Found gpgme-config at ${_GPGMECONFIG_EXECUTABLE}" ) 0195 0196 exec_program( ${_GPGMECONFIG_EXECUTABLE} ARGS --version OUTPUT_VARIABLE GPGME_VERSION ) 0197 0198 set( _GPGME_MIN_VERSION "1.1.7" ) 0199 0200 if ( ${GPGME_VERSION} VERSION_LESS ${_GPGME_MIN_VERSION} ) 0201 0202 message( STATUS "The installed version of gpgme is too old: ${GPGME_VERSION} (required: >= ${_GPGME_MIN_VERSION})" ) 0203 0204 else() 0205 0206 message( STATUS "Found gpgme v${GPGME_VERSION}, checking for flavours..." ) 0207 0208 exec_program( ${_GPGMECONFIG_EXECUTABLE} ARGS --libs OUTPUT_VARIABLE _gpgme_config_vanilla_libs RETURN_VALUE _ret ) 0209 if ( _ret ) 0210 set( _gpgme_config_vanilla_libs ) 0211 endif() 0212 0213 exec_program( ${_GPGMECONFIG_EXECUTABLE} ARGS --thread=pthread --libs OUTPUT_VARIABLE _gpgme_config_pthread_libs RETURN_VALUE _ret ) 0214 if ( _ret ) 0215 set( _gpgme_config_pthread_libs ) 0216 endif() 0217 0218 exec_program( ${_GPGMECONFIG_EXECUTABLE} ARGS --thread=pth --libs OUTPUT_VARIABLE _gpgme_config_pth_libs RETURN_VALUE _ret ) 0219 if ( _ret ) 0220 set( _gpgme_config_pth_libs ) 0221 endif() 0222 0223 # append -lgpg-error to the list of libraries, if necessary 0224 foreach ( _flavour vanilla pthread pth ) 0225 if ( _gpgme_config_${_flavour}_libs AND NOT _gpgme_config_${_flavour}_libs MATCHES "lgpg-error" ) 0226 set( _gpgme_config_${_flavour}_libs "${_gpgme_config_${_flavour}_libs} -lgpg-error" ) 0227 endif() 0228 endforeach() 0229 0230 if ( _gpgme_config_vanilla_libs OR _gpgme_config_pthread_libs OR _gpgme_config_pth_libs ) 0231 0232 exec_program( ${_GPGMECONFIG_EXECUTABLE} ARGS --cflags OUTPUT_VARIABLE _GPGME_CFLAGS ) 0233 0234 if ( _GPGME_CFLAGS ) 0235 string( REGEX REPLACE "(\r?\n)+$" " " _GPGME_CFLAGS "${_GPGME_CFLAGS}" ) 0236 string( REGEX REPLACE " *-I" ";" GPGME_INCLUDES "${_GPGME_CFLAGS}" ) 0237 endif() 0238 0239 foreach ( _flavour vanilla pthread pth ) 0240 if ( _gpgme_config_${_flavour}_libs ) 0241 0242 set( _gpgme_library_dirs ) 0243 set( _gpgme_library_names ) 0244 string( TOUPPER "${_flavour}" _FLAVOUR ) 0245 0246 string( REGEX REPLACE " +" ";" _gpgme_config_${_flavour}_libs "${_gpgme_config_${_flavour}_libs}" ) 0247 0248 foreach( _flag ${_gpgme_config_${_flavour}_libs} ) 0249 if ( "${_flag}" MATCHES "^-L" ) 0250 string( REGEX REPLACE "^-L" "" _dir "${_flag}" ) 0251 file( TO_CMAKE_PATH "${_dir}" _dir ) 0252 set( _gpgme_library_dirs ${_gpgme_library_dirs} "${_dir}" ) 0253 elseif( "${_flag}" MATCHES "^-l" ) 0254 string( REGEX REPLACE "^-l" "" _name "${_flag}" ) 0255 set( _gpgme_library_names ${_gpgme_library_names} "${_name}" ) 0256 endif() 0257 endforeach() 0258 0259 set( GPGME_${_FLAVOUR}_FOUND true ) 0260 0261 foreach( _name ${_gpgme_library_names} ) 0262 set( _gpgme_${_name}_lib ) 0263 0264 # if -L options were given, look only there 0265 if ( _gpgme_library_dirs ) 0266 find_library( _gpgme_${_name}_lib NAMES ${_name} PATHS ${_gpgme_library_dirs} NO_DEFAULT_PATH ) 0267 endif() 0268 0269 # if not found there, look in system directories 0270 if ( NOT _gpgme_${_name}_lib ) 0271 find_library( _gpgme_${_name}_lib NAMES ${_name} ) 0272 endif() 0273 0274 # if still not found, then the whole flavour isn't found 0275 if ( NOT _gpgme_${_name}_lib ) 0276 if ( GPGME_${_FLAVOUR}_FOUND ) 0277 set( GPGME_${_FLAVOUR}_FOUND false ) 0278 set( _not_found_reason "dependent library ${_name} wasn't found" ) 0279 endif() 0280 endif() 0281 0282 set( GPGME_${_FLAVOUR}_LIBRARIES ${GPGME_${_FLAVOUR}_LIBRARIES} "${_gpgme_${_name}_lib}" ) 0283 endforeach() 0284 0285 #check_c_library_exists_explicit( gpgme gpgme_check_version "${_GPGME_CFLAGS}" "${GPGME_LIBRARIES}" GPGME_FOUND ) 0286 if ( GPGME_${_FLAVOUR}_FOUND ) 0287 message( STATUS " Found flavour '${_flavour}', checking whether it's usable...yes" ) 0288 else() 0289 message( STATUS " Found flavour '${_flavour}', checking whether it's usable...no" ) 0290 message( STATUS " (${_not_found_reason})" ) 0291 endif() 0292 endif() 0293 0294 endforeach( _flavour ) 0295 0296 # ensure that they are cached 0297 # This comment above doesn't make sense, the four following lines seem to do nothing. Alex 0298 set( GPGME_INCLUDES ${GPGME_INCLUDES} ) 0299 set( GPGME_VANILLA_LIBRARIES ${GPGME_VANILLA_LIBRARIES} ) 0300 set( GPGME_PTHREAD_LIBRARIES ${GPGME_PTHREAD_LIBRARIES} ) 0301 set( GPGME_PTH_LIBRARIES ${GPGME_PTH_LIBRARIES} ) 0302 0303 if ( GPGME_VANILLA_FOUND OR GPGME_PTHREAD_FOUND OR GPGME_PTH_FOUND ) 0304 set( GPGME_FOUND true ) 0305 else() 0306 set( GPGME_FOUND false ) 0307 endif() 0308 0309 endif() 0310 0311 endif() 0312 0313 endif() 0314 0315 endif() 0316 0317 # these are Windows-only: 0318 set( GPGME_GLIB_FOUND false ) 0319 set( GPGME_QT_FOUND false ) 0320 set( HAVE_GPGME_GLIB 0 ) 0321 set( HAVE_GPGME_QT 0 ) 0322 0323 macro_bool_to_01( GPGME_FOUND HAVE_GPGME ) 0324 macro_bool_to_01( GPGME_VANILLA_FOUND HAVE_GPGME_VANILLA ) 0325 macro_bool_to_01( GPGME_PTHREAD_FOUND HAVE_GPGME_PTHREAD ) 0326 macro_bool_to_01( GPGME_PTH_FOUND HAVE_GPGME_PTH ) 0327 0328 endif() # WIN32 | Unix 0329 0330 0331 set( _gpgme_flavours "" ) 0332 0333 if ( GPGME_VANILLA_FOUND ) 0334 set( _gpgme_flavours "${_gpgme_flavours} vanilla" ) 0335 endif() 0336 0337 if ( GPGME_GLIB_FOUND ) 0338 set( _gpgme_flavours "${_gpgme_flavours} Glib" ) 0339 endif() 0340 0341 if ( GPGME_QT_FOUND ) 0342 set( _gpgme_flavours "${_gpgme_flavours} Qt" ) 0343 endif() 0344 0345 if ( GPGME_PTHREAD_FOUND ) 0346 set( _gpgme_flavours "${_gpgme_flavours} pthread" ) 0347 endif() 0348 0349 if ( GPGME_PTH_FOUND ) 0350 set( _gpgme_flavours "${_gpgme_flavours} pth" ) 0351 endif() 0352 0353 # determine the library in one of the found flavours, can be reused e.g. by FindQgpgme.cmake, Alex 0354 foreach(_currentFlavour vanilla glib qt pth pthread) 0355 if(NOT GPGME_LIBRARY_DIR) 0356 get_filename_component(GPGME_LIBRARY_DIR "${_gpgme_${_currentFlavour}_lib}" PATH) 0357 endif() 0358 endforeach() 0359 0360 if ( NOT Gpgme_FIND_QUIETLY ) 0361 0362 if ( GPGME_FOUND ) 0363 message( STATUS "Usable gpgme flavours found: ${_gpgme_flavours}" ) 0364 else() 0365 message( STATUS "No usable gpgme flavours found." ) 0366 endif() 0367 0368 endif() 0369 0370 if ( Gpgme_FIND_REQUIRED AND NOT GPGME_FOUND ) 0371 message( FATAL_ERROR "Did not find GPGME" ) 0372 endif() 0373 0374 0375 if ( WIN32 ) 0376 set( _gpgme_homepage "http://www.gpg4win.org" ) 0377 else() 0378 set( _gpgme_homepage "http://www.gnupg.org/related_software/gpgme" ) 0379 endif() 0380 0381 set_package_properties(Gpgme PROPERTIES 0382 DESCRIPTION "The GnuPG Made Easy (GPGME) library)" 0383 URL ${_gpgme_homepage}) 0384 0385 set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS_gpgme_saved )