Changeset View
Changeset View
Standalone View
Standalone View
cmake/modules/FindKSBA.cmake
- This file was added.
| 1 | # - Try :to find the KSBA library | ||||
|---|---|---|---|---|---|
| 2 | | ||||
| 3 | # Variables set: | ||||
| 4 | # KSBA_{INCLUDES,FOUND,LIBRARIES} will be set for each of the above | ||||
| 5 | | ||||
| 6 | | ||||
| 7 | #if this is built-in, please replace, if it isn't, export into a MacroToBool.cmake of it's own | ||||
| 8 | macro( macro_bool_to_bool FOUND_VAR ) | ||||
| 9 | foreach( _current_VAR ${ARGN} ) | ||||
| 10 | if ( ${FOUND_VAR} ) | ||||
| 11 | set( ${_current_VAR} TRUE ) | ||||
| 12 | else() | ||||
| 13 | set( ${_current_VAR} FALSE ) | ||||
| 14 | endif() | ||||
| 15 | endforeach() | ||||
| 16 | endmacro() | ||||
| 17 | | ||||
| 18 | | ||||
| 19 | if ( WIN32 ) | ||||
| 20 | # On Windows, we don't have a ksba-config script, so we need to | ||||
| 21 | # look for the stuff ourselves: | ||||
| 22 | | ||||
| 23 | # in cmake, AND and OR have the same precedence, there's no | ||||
| 24 | # subexpressions, and expressions are evaluated short-circuit'ed | ||||
| 25 | # IOW: CMake if() suxx. | ||||
| 26 | set( _seem_to_have_cached_ksba false ) | ||||
| 27 | if ( KSBA_INCLUDES ) | ||||
| 28 | if ( KSBA_LIBRARIES ) | ||||
| 29 | set( _seem_to_have_cached_ksba true ) | ||||
| 30 | endif() | ||||
| 31 | endif() | ||||
| 32 | | ||||
| 33 | if ( _seem_to_have_cached_ksba ) | ||||
| 34 | macro_bool_to_bool( KSBA_LIBRARIES KSBA_FOUND ) | ||||
| 35 | else() | ||||
| 36 | set( KSBA_FOUND false ) | ||||
| 37 | | ||||
| 38 | find_path( KSBA_INCLUDES ksba.h | ||||
| 39 | ${CMAKE_INCLUDE_PATH} | ||||
| 40 | ${CMAKE_INSTALL_PREFIX}/include | ||||
| 41 | ) | ||||
| 42 | | ||||
| 43 | find_library( _ksba_library NAMES ksba libksba | ||||
| 44 | PATHS | ||||
| 45 | ${CMAKE_LIBRARY_PATH} | ||||
| 46 | ${CMAKE_INSTALL_PREFIX}/lib | ||||
| 47 | ) | ||||
| 48 | | ||||
| 49 | find_library( _gpg_error_library NAMES gpg-error libgpg-error gpg-error-0 libgpg-error-0 | ||||
| 50 | PATHS | ||||
| 51 | ${CMAKE_LIBRARY_PATH} | ||||
| 52 | ${CMAKE_INSTALL_PREFIX}/lib | ||||
| 53 | ) | ||||
| 54 | | ||||
| 55 | set( KSBA_INCLUDES ${KSBA_INCLUDES} ) | ||||
| 56 | | ||||
| 57 | if ( _ksba_library AND _gpg_error_library ) | ||||
| 58 | set( KSBA_LIBRARIES ${_ksba_library} ${_gpg_error_library} ws2_32 ) | ||||
| 59 | set( KSBA_FOUND true ) | ||||
| 60 | endif() | ||||
| 61 | | ||||
| 62 | endif() | ||||
| 63 | | ||||
| 64 | if (KSBA_FOUND) | ||||
| 65 | set (HAVE_KSBA 1) | ||||
| 66 | else() | ||||
| 67 | set (HAVE_KSBA 0) | ||||
| 68 | endif() | ||||
| 69 | | ||||
| 70 | else() # not WIN32 | ||||
| 71 | | ||||
| 72 | # On *nix, we have the ksba-config script which can tell us all we | ||||
| 73 | # need to know: | ||||
| 74 | | ||||
| 75 | # see WIN32 case for an explanation of what this does: | ||||
| 76 | set( _seem_to_have_cached_ksba false ) | ||||
| 77 | if ( KSBA_INCLUDES AND KSBA_LIBRARIES ) | ||||
| 78 | set( _seem_to_have_cached_ksba true ) | ||||
| 79 | endif() | ||||
| 80 | | ||||
| 81 | if ( _seem_to_have_cached_ksba ) | ||||
| 82 | | ||||
| 83 | set( KSBA_FOUND true ) | ||||
| 84 | | ||||
| 85 | else() | ||||
| 86 | | ||||
| 87 | set( KSBA_FOUND false ) | ||||
| 88 | | ||||
| 89 | find_program( _KSBACONFIG_EXECUTABLE NAMES ksba-config ) | ||||
| 90 | | ||||
| 91 | # if ksba-config has been found | ||||
| 92 | if ( _KSBACONFIG_EXECUTABLE ) | ||||
| 93 | | ||||
| 94 | message( STATUS "Found ksba-config at ${_KSBACONFIG_EXECUTABLE}" ) | ||||
| 95 | | ||||
| 96 | exec_program( ${_KSBACONFIG_EXECUTABLE} ARGS --version OUTPUT_VARIABLE KSBA_VERSION ) | ||||
| 97 | | ||||
| 98 | set( _KSBA_MIN_VERSION "1.0.0" ) | ||||
| 99 | if( KSBA_VERSION VERSION_GREATER ${_KSBA_MIN_VERSION} ) | ||||
| 100 | set( _KSBA_INSTALLED_VERSION_OK TRUE ) | ||||
| 101 | endif() | ||||
| 102 | | ||||
| 103 | if ( NOT _KSBA_INSTALLED_VERSION_OK ) | ||||
| 104 | | ||||
| 105 | message( STATUS "The installed version of KSBA is too old: ${KSBA_VERSION} (required: >= ${_KSBA_MIN_VERSION})" ) | ||||
| 106 | | ||||
| 107 | else() | ||||
| 108 | | ||||
| 109 | message( STATUS "Found KSBA v${KSBA_VERSION}" ) | ||||
| 110 | | ||||
| 111 | exec_program( ${_KSBACONFIG_EXECUTABLE} ARGS --libs OUTPUT_VARIABLE _ksba_config_libs RETURN_VALUE _ret ) | ||||
| 112 | if ( _ret ) | ||||
| 113 | set( _ksba_config_libs ) | ||||
| 114 | endif() | ||||
| 115 | | ||||
| 116 | # append -lgpg-error to the list of libraries, if necessary | ||||
| 117 | if ( _ksba_config_libs AND NOT _ksba_config_libs MATCHES "lgpg-error" ) | ||||
| 118 | set( _ksba_config_libs "${_ksba_config_libs} -lgpg-error" ) | ||||
| 119 | endif() | ||||
| 120 | | ||||
| 121 | if ( _ksba_config_libs ) | ||||
| 122 | | ||||
| 123 | exec_program( ${_KSBACONFIG_EXECUTABLE} ARGS --cflags OUTPUT_VARIABLE _KSBA_CFLAGS ) | ||||
| 124 | | ||||
| 125 | if ( _KSBA_CFLAGS ) | ||||
| 126 | string( REGEX REPLACE "(\r?\n)+$" " " _KSBA_CFLAGS "${_KSBA_CFLAGS}" ) | ||||
| 127 | string( REGEX REPLACE " *-I" ";" KSBA_INCLUDES "${_KSBA_CFLAGS}" ) | ||||
| 128 | endif() | ||||
| 129 | | ||||
| 130 | if ( _ksba_config_libs ) | ||||
| 131 | | ||||
| 132 | set( _ksba_library_dirs ) | ||||
| 133 | set( _ksba_library_names ) | ||||
| 134 | | ||||
| 135 | string( REGEX REPLACE " +" ";" _ksba_config_libs "${_ksba_config_libs}" ) | ||||
| 136 | | ||||
| 137 | foreach( _flag ${_ksba_config_libs} ) | ||||
| 138 | if ( "${_flag}" MATCHES "^-L" ) | ||||
| 139 | string( REGEX REPLACE "^-L" "" _dir "${_flag}" ) | ||||
| 140 | file( TO_CMAKE_PATH "${_dir}" _dir ) | ||||
| 141 | set( _ksba_library_dirs ${_ksba_library_dirs} "${_dir}" ) | ||||
| 142 | elseif( "${_flag}" MATCHES "^-l" ) | ||||
| 143 | string( REGEX REPLACE "^-l" "" _name "${_flag}" ) | ||||
| 144 | set( _ksba_library_names ${_ksba_library_names} "${_name}" ) | ||||
| 145 | endif() | ||||
| 146 | endforeach() | ||||
| 147 | | ||||
| 148 | set( KSBA_FOUND true ) | ||||
| 149 | | ||||
| 150 | foreach( _name ${_ksba_library_names} ) | ||||
| 151 | set( _ksba_${_name}_lib ) | ||||
| 152 | | ||||
| 153 | # if -L options were given, look only there | ||||
| 154 | if ( _ksba_library_dirs ) | ||||
| 155 | find_library( _ksba_${_name}_lib NAMES ${_name} PATHS ${_ksba_library_dirs} NO_DEFAULT_PATH ) | ||||
| 156 | endif() | ||||
| 157 | | ||||
| 158 | # if not found there, look in system directories | ||||
| 159 | if ( NOT _ksba_${_name}_lib ) | ||||
| 160 | find_library( _ksba_${_name}_lib NAMES ${_name} ) | ||||
| 161 | endif() | ||||
| 162 | | ||||
| 163 | # if still not found, then the whole flavour isn't found | ||||
| 164 | if ( NOT _ksba_${_name}_lib ) | ||||
| 165 | if ( KSBA_FOUND ) | ||||
| 166 | set( kSBA_FOUND false ) | ||||
| 167 | set( _not_found_reason "dependant library ${_name} wasn't found" ) | ||||
| 168 | endif() | ||||
| 169 | endif() | ||||
| 170 | | ||||
| 171 | set( KSBA_LIBRARIES ${KSBA_LIBRARIES} "${_ksba_${_name}_lib}" ) | ||||
| 172 | endforeach() | ||||
| 173 | | ||||
| 174 | #check_c_library_exists_explicit( ksba ksba_check_version "${_KSBA_CFLAGS}" "${KSBA_LIBRARIES}" KSBA_FOUND ) | ||||
| 175 | if ( KSBA_FOUND ) | ||||
| 176 | message( STATUS " Checking whether KSBA is usable...yes" ) | ||||
| 177 | else() | ||||
| 178 | message( STATUS " Checking whether KSBA is usable...no" ) | ||||
| 179 | message( STATUS " (${_not_found_reason})" ) | ||||
| 180 | endif() | ||||
| 181 | endif() | ||||
| 182 | | ||||
| 183 | # ensure that they are cached | ||||
| 184 | set( KSBA_INCLUDES ${KSBA_INCLUDES} ) | ||||
| 185 | set( KSBA_LIBRARIES ${KSBA_LIBRARIES} ) | ||||
| 186 | | ||||
| 187 | endif() | ||||
| 188 | | ||||
| 189 | endif() | ||||
| 190 | | ||||
| 191 | endif() | ||||
| 192 | | ||||
| 193 | endif() | ||||
| 194 | | ||||
| 195 | if (KSBA_FOUND) | ||||
| 196 | set (HAVE_KSBA 1) | ||||
| 197 | else() | ||||
| 198 | set (HAVE_KSBA 0) | ||||
| 199 | endif() | ||||
| 200 | | ||||
| 201 | endif() # WIN32 | Unix | ||||
| 202 | | ||||
| 203 | | ||||
| 204 | if ( NOT KSBA_FIND_QUIETLY ) | ||||
| 205 | | ||||
| 206 | if ( KSBA_FOUND ) | ||||
| 207 | message( STATUS "Usable KSBA found." ) | ||||
| 208 | message( STATUS " Includes: ${KSBA_INCLUDES}" ) | ||||
| 209 | message( STATUS " Libraries: ${kSBA_LIBRARIES}" ) | ||||
| 210 | else() | ||||
| 211 | message( STATUS "No usable KSBA found." ) | ||||
| 212 | endif() | ||||
| 213 | | ||||
| 214 | if( KSBA_FIND_REQUIRED ) | ||||
| 215 | set( _KSBA_TYPE "REQUIRED" ) | ||||
| 216 | else() | ||||
| 217 | set( _KSBA_TYPE "OPTIONAL" ) | ||||
| 218 | endif() | ||||
| 219 | | ||||
| 220 | if ( WIN32 ) | ||||
| 221 | set( _ksba_homepage "http://www.gpg4win.org" ) | ||||
| 222 | else() | ||||
| 223 | set( _ksba_homepage "http://www.gnupg.org/related_software/libksba" ) | ||||
| 224 | endif() | ||||
| 225 | | ||||
| 226 | set_package_properties(KSBA PROPERTIES DESCRIPTION "KSBA CMS handling library" | ||||
| 227 | URL ${_ksba_homepage} | ||||
| 228 | TYPE ${_KSBA_TYPE} | ||||
| 229 | PURPOSE "Needed for Kleopatra to correctly detect CMS signatures" | ||||
| 230 | ) | ||||
| 231 | | ||||
| 232 | else() | ||||
| 233 | | ||||
| 234 | if ( KSBA_FIND_REQUIRED AND NOT KSBA_FOUND ) | ||||
| 235 | message( FATAL_ERROR "KSBA is required but was not found." ) | ||||
| 236 | endif() | ||||
| 237 | | ||||
| 238 | endif() | ||||
| 239 | | ||||