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