aboutsummaryrefslogtreecommitdiffstats
path: root/cmake/modules/FindGCRYPT.cmake
blob: 1da7a66fd03d5ab8dcd5d8d4db35b5f4272f1f9e (plain)
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
#
# - Find gcrypt
# Find the native GCRYPT includes and library
#
#  GCRYPT_INCLUDE_DIRS - where to find gcrypt.h, etc.
#  GCRYPT_LIBRARIES    - List of libraries when using gcrypt.
#  GCRYPT_FOUND        - True if gcrypt found.
#  GCRYPT_DLL_DIR      - (Windows) Path to the Libgcrypt DLLs.
#  GCRYPT_DLLS         - (Windows) List of required Libgcrypt DLLs.


if(GCRYPT_INCLUDE_DIRS)
  # Already in cache, be silent
  set(GCRYPT_FIND_QUIETLY TRUE)
endif()

include(FindWSWinLibs)
FindWSWinLibs("libgcrypt-.*" "GCRYPT_HINTS")

find_path(GCRYPT_INCLUDE_DIR
  NAMES gcrypt.h
  PATH_SUFFIXES
    include
  HINTS
    "${GCRYPT_INCLUDEDIR}"
    "${GCRYPT_HINTS}"
)

# libgcrypt-20 is used in libgcrypt-1.8.3-win??ws (from Debian).
# libgcrypt is used in libgcrypt-1.10.1-2-win??ws (from Debian).
find_library(GCRYPT_LIBRARY
  NAMES gcrypt libgcrypt libgcrypt-20
  PATH_SUFFIXES
    lib
  HINTS
    "${GCRYPT_LIBDIR}"
    "${GCRYPT_HINTS}"
)

# libgpg-error6-0 is used in libgcrypt-1.7.6-win??ws (built from source).
# libgpg-error-0 is used in libgcrypt-1.8.3-win??ws (from Debian).
# libgpg-error is used in libgcrypt-1.10.1-2-win??ws (from Debian).
find_library(GCRYPT_ERROR_LIBRARY
  NAMES gpg-error libgpg-error libgpg-error-0 libgpg-error6-0
  PATH_SUFFIXES
    lib
  HINTS
    "${GCRYPT_LIBDIR}"
    "${GCRYPT_HINTS}"
)

# Try to retrieve version from header if found (available since libgcrypt 1.3.0)
if(GCRYPT_INCLUDE_DIR)
  set(_version_regex "^#define[ \t]+GCRYPT_VERSION[ \t]+\"([0-9\.]+\.[0-9]+).*")
  file(STRINGS "${GCRYPT_INCLUDE_DIR}/gcrypt.h" GCRYPT_VERSION REGEX "${_version_regex}")
  string(REGEX REPLACE "${_version_regex}" "\\1" GCRYPT_VERSION "${GCRYPT_VERSION}")
  unset(_version_regex)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GCRYPT
  REQUIRED_VARS   GCRYPT_LIBRARY GCRYPT_INCLUDE_DIR
  VERSION_VAR     GCRYPT_VERSION)

if(GCRYPT_FOUND)
  set(GCRYPT_LIBRARIES ${GCRYPT_LIBRARY} ${GCRYPT_ERROR_LIBRARY})
  set(GCRYPT_INCLUDE_DIRS ${GCRYPT_INCLUDE_DIR})
  if(WIN32)
    set(GCRYPT_DLL_DIR "${GCRYPT_HINTS}/bin"
      CACHE PATH "Path to the Libgcrypt DLLs"
    )
    file(GLOB _gcrypt_dlls RELATIVE "${GCRYPT_DLL_DIR}"
      "${GCRYPT_DLL_DIR}/libgcrypt-*.dll"
      "${GCRYPT_DLL_DIR}/libgpg-error*.dll"
    )
    set(GCRYPT_DLLS ${_gcrypt_dlls}
      # We're storing filenames only. Should we use STRING instead?
      CACHE FILEPATH "Libgcrypt DLL list"
    )
    mark_as_advanced(GCRYPT_DLL_DIR GCRYPT_DLLS)
  endif()
else()
  set(GCRYPT_LIBRARIES)
  set(GCRYPT_INCLUDE_DIRS)
  set(GCRYPT_DLL_DIR)
  set(GCRYPT_DLLS)
endif()

mark_as_advanced(GCRYPT_LIBRARIES GCRYPT_INCLUDE_DIRS)