Debian Codegraph @

cmake/Modules/FindGCrypt.cmake

raw
1 # - Try to find GCrypt
2 # Once done this will define
3 #
4 # GCRYPT_FOUND - system has GCrypt
5 # GCRYPT_INCLUDE_DIRS - the GCrypt include directory
6 # GCRYPT_LIBRARIES - Link these to use GCrypt
7 # GCRYPT_DEFINITIONS - Compiler switches required for using GCrypt
8 #
9 #=============================================================================
10 # Copyright (c) 2009-2012 Andreas Schneider <[email protected]>
11 #
12 # Distributed under the OSI-approved BSD License (the "License");
13 # see accompanying file Copyright.txt for details.
14 #
15 # This software is distributed WITHOUT ANY WARRANTY; without even the
16 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 # See the License for more information.
18 #=============================================================================
19 #
20
21 set(_GCRYPT_ROOT_HINTS
22 $ENV{GCRYTPT_ROOT_DIR}
23 ${GCRYPT_ROOT_DIR})
24
25 set(_GCRYPT_ROOT_PATHS
26 "$ENV{PROGRAMFILES}/libgcrypt")
27
28 set(_GCRYPT_ROOT_HINTS_AND_PATHS
29 HINTS ${_GCRYPT_ROOT_HINTS}
30 PATHS ${_GCRYPT_ROOT_PATHS})
31
32
33 find_path(GCRYPT_INCLUDE_DIR
34 NAMES
35 gcrypt.h
36 HINTS
37 ${_GCRYPT_ROOT_HINTS_AND_PATHS}
38 PATH_SUFFIXES
39 include
40 )
41
42 find_path(GCRYPT_ERROR_INCLUDE_DIR
43 NAMES
44 gpg-error.h
45 HINTS
46 ${_GCRYPT_ROOT_HINTS_AND_PATHS}
47 PATH_SUFFIXES
48 include
49 )
50
51 find_library(GCRYPT_LIBRARY
52 NAMES
53 gcrypt
54 gcrypt11
55 libgcrypt-11
56 HINTS
57 ${_GCRYPT_ROOT_HINTS_AND_PATHS}
58 PATH_SUFFIXES
59 lib
60 )
61 find_library(GCRYPT_ERROR_LIBRARY
62 NAMES
63 gpg-error
64 libgpg-error-0
65 libgpg-error6-0
66 HINTS
67 ${_GCRYPT_ROOT_HINTS_AND_PATHS}
68 PATH_SUFFIXES
69 lib
70 )
71 set(GCRYPT_LIBRARIES ${GCRYPT_ERROR_LIBRARY} ${GCRYPT_LIBRARY})
72
73 if (GCRYPT_INCLUDE_DIR)
74 file(STRINGS "${GCRYPT_INCLUDE_DIR}/gcrypt.h" _gcrypt_version_str REGEX "^#define GCRYPT_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]")
75
76 string(REGEX REPLACE "^.*GCRYPT_VERSION.*([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" GCRYPT_VERSION "${_gcrypt_version_str}")
77 endif (GCRYPT_INCLUDE_DIR)
78
79 include(FindPackageHandleStandardArgs)
80 if (GCRYPT_VERSION)
81 find_package_handle_standard_args(GCrypt
82 REQUIRED_VARS
83 GCRYPT_INCLUDE_DIR
84 GCRYPT_LIBRARIES
85 VERSION_VAR
86 GCRYPT_VERSION
87 FAIL_MESSAGE
88 "Could NOT find GCrypt, try to set the path to GCrypt root folder in the system variable GCRYPT_ROOT_DIR"
89 )
90 else (GCRYPT_VERSION)
91 find_package_handle_standard_args(GCrypt
92 "Could NOT find GCrypt, try to set the path to GCrypt root folder in the system variable GCRYPT_ROOT_DIR"
93 GCRYPT_INCLUDE_DIR
94 GCRYPT_LIBRARIES)
95 endif (GCRYPT_VERSION)
96
97 # show the GCRYPT_INCLUDE_DIRS, GCRYPT_LIBRARIES and GCRYPT_ERROR_INCLUDE_DIR variables only in the advanced view
98 mark_as_advanced(GCRYPT_INCLUDE_DIR GCRYPT_ERROR_INCLUDE_DIR GCRYPT_LIBRARIES)
99
100 if(GCRYPT_FOUND)
101 if(NOT TARGET libgcrypt::libgcrypt)
102 add_library(libgcrypt::libgcrypt UNKNOWN IMPORTED)
103 set_target_properties(libgcrypt::libgcrypt PROPERTIES
104 INTERFACE_INCLUDE_DIRECTORIES "${GCRYPT_INCLUDE_DIR}"
105 INTERFACE_LINK_LIBRARIES libgcrypt::libgcrypt
106 IMPORTED_LINK_INTERFACE_LANGUAGES "C"
107 IMPORTED_LOCATION "${GCRYPT_LIBRARY}")
108 endif()
109
110 if(NOT TARGET libgpg-error::libgpg-error)
111 add_library(libgpg-error::libgpg-error UNKNOWN IMPORTED)
112 set_target_properties(libgpg-error::libgpg-error PROPERTIES
113 INTERFACE_INCLUDE_DIRECTORIES "${GCRYPT_ERROR_INCLUDE_DIR}"
114 INTERFACE_LINK_LIBRARIES libgpg-error::libgpg-error
115 IMPORTED_LINK_INTERFACE_LANGUAGES "C"
116 IMPORTED_LOCATION "${GCRYPT_ERROR_LIBRARY}")
117 endif()
118 endif()