Brian Waters | 13d9601 | 2017-12-08 16:53:31 -0600 | [diff] [blame] | 1 | # - Find gnutls |
| 2 | # Find the native GNUTLS includes and library |
| 3 | # |
| 4 | # GNUTLS_FOUND - True if gnutls found. |
| 5 | # GNUTLS_INCLUDE_DIR - where to find gnutls.h, etc. |
| 6 | # GNUTLS_LIBRARIES - List of libraries when using gnutls. |
| 7 | # GNUTLS_VERSION_210 - true if GnuTLS version is >= 2.10.0 (does not require additional separate gcrypt initialization) |
| 8 | # GNUTLS_VERSION_212 - true if GnuTLS version is >= 2.12.0 (supports gnutls_transport_set_vec_push_function) |
| 9 | # GNUTLS_VERSION_300 - true if GnuTLS version is >= 3.00.0 (x509 verification functions changed) |
| 10 | # GNUTLS_VERSION_310 - true if GnuTLS version is >= 3.01.0 (stabilization branch with new APIs) |
| 11 | |
| 12 | if (GNUTLS_INCLUDE_DIR AND GNUTLS_LIBRARIES) |
| 13 | set(GNUTLS_FIND_QUIETLY TRUE) |
| 14 | endif (GNUTLS_INCLUDE_DIR AND GNUTLS_LIBRARIES) |
| 15 | |
| 16 | # Include dir |
| 17 | find_path(GNUTLS_INCLUDE_DIR |
| 18 | NAMES |
| 19 | gnutls.h |
| 20 | gnutls/gnutls.h |
| 21 | ) |
| 22 | |
| 23 | # Library |
| 24 | find_library(GNUTLS_LIBRARY |
| 25 | NAMES gnutls |
| 26 | ) |
| 27 | |
| 28 | # handle the QUIETLY and REQUIRED arguments and set GNUTLS_FOUND to TRUE if |
| 29 | # all listed variables are TRUE |
| 30 | INCLUDE(FindPackageHandleStandardArgs) |
| 31 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(GNUTLS DEFAULT_MSG GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR) |
| 32 | |
| 33 | IF(GNUTLS_FOUND) |
| 34 | SET( GNUTLS_LIBRARIES ${GNUTLS_LIBRARY} ) |
| 35 | ELSE(GNUTLS_FOUND) |
| 36 | SET( GNUTLS_LIBRARIES ) |
| 37 | ENDIF(GNUTLS_FOUND) |
| 38 | |
| 39 | # Lastly make it so that the GNUTLS_LIBRARY and GNUTLS_INCLUDE_DIR variables |
| 40 | # only show up under the advanced options in the gui cmake applications. |
| 41 | MARK_AS_ADVANCED( GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR ) |
| 42 | |
| 43 | # Now check if the library is recent. gnutls_hash was added in 2.10.0. |
| 44 | # Also test library is even more recent. gnutls_x509_trust_list_verify_crt was added in 3.00.0. |
| 45 | IF(GNUTLS_FOUND) |
| 46 | IF( NOT( "${GNUTLS_VERSION_TEST_FOR}" STREQUAL "${GNUTLS_LIBRARY}" )) |
| 47 | INCLUDE (CheckLibraryExists) |
| 48 | MESSAGE(STATUS "Checking GNUTLS version") |
| 49 | UNSET(GNUTLS_VERSION_210) |
| 50 | UNSET(GNUTLS_VERSION_210 CACHE) |
| 51 | UNSET(GNUTLS_VERSION_212) |
| 52 | UNSET(GNUTLS_VERSION_212 CACHE) |
| 53 | UNSET(GNUTLS_VERSION_300) |
| 54 | UNSET(GNUTLS_VERSION_300 CACHE) |
| 55 | UNSET(GNUTLS_VERSION_310) |
| 56 | UNSET(GNUTLS_VERSION_310 CACHE) |
| 57 | GET_FILENAME_COMPONENT(GNUTLS_PATH ${GNUTLS_LIBRARY} PATH) |
| 58 | CHECK_LIBRARY_EXISTS(gnutls gnutls_hash ${GNUTLS_PATH} GNUTLS_VERSION_210) |
| 59 | CHECK_LIBRARY_EXISTS(gnutls gnutls_transport_set_vec_push_function ${GNUTLS_PATH} GNUTLS_VERSION_212) |
| 60 | CHECK_LIBRARY_EXISTS(gnutls gnutls_x509_trust_list_verify_crt ${GNUTLS_PATH} GNUTLS_VERSION_300) |
| 61 | CHECK_LIBRARY_EXISTS(gnutls gnutls_handshake_set_timeout ${GNUTLS_PATH} GNUTLS_VERSION_310) |
| 62 | SET( GNUTLS_VERSION_TEST_FOR ${GNUTLS_LIBRARY} CACHE INTERNAL "Version the test was made against" ) |
| 63 | ENDIF (NOT( "${GNUTLS_VERSION_TEST_FOR}" STREQUAL "${GNUTLS_LIBRARY}" )) |
| 64 | ENDIF(GNUTLS_FOUND) |