1 # Copyright (C) 2020 Dieter Baron and Thomas Klausner
3 # The authors can be contacted at <libzip@nih.at>
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in
14 # the documentation and/or other materials provided with the
17 # 3. The names of the authors may not be used to endorse or promote
18 # products derived from this software without specific prior
21 # THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
22 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
25 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
29 # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
31 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #[=======================================================================[.rst:
37 Finds the Nettle library.
42 This module provides the following imported targets, if found:
50 This will define the following variables:
53 True if the system has the Nettle library.
55 The version of the Nettle library which was found.
56 ``Nettle_INCLUDE_DIRS``
57 Include directories needed to use Nettle.
59 Libraries needed to link to Nettle.
64 The following cache variables may also be set:
66 ``Nettle_INCLUDE_DIR``
67 The directory containing ``nettle/aes.h``.
69 The path to the Nettle library.
71 #]=======================================================================]
73 find_package(PkgConfig)
74 pkg_check_modules(PC_Nettle QUIET nettle)
76 find_path(Nettle_INCLUDE_DIR
77 NAMES nettle/aes.h nettle/md5.h nettle/pbkdf2.h nettle/ripemd160.h nettle/sha.h
78 PATHS ${PC_Nettle_INCLUDE_DIRS}
80 find_library(Nettle_LIBRARY
82 PATHS ${PC_Nettle_LIBRARY_DIRS}
85 # Extract version information from the header file
86 if(Nettle_INCLUDE_DIR)
87 # This file only exists in nettle>=3.0
88 if(EXISTS ${Nettle_INCLUDE_DIR}/nettle/version.h)
89 file(STRINGS ${Nettle_INCLUDE_DIR}/nettle/version.h _ver_major_line
90 REGEX "^#define NETTLE_VERSION_MAJOR *[0-9]+"
92 string(REGEX MATCH "[0-9]+"
93 Nettle_MAJOR_VERSION "${_ver_major_line}")
94 file(STRINGS ${Nettle_INCLUDE_DIR}/nettle/version.h _ver_minor_line
95 REGEX "^#define NETTLE_VERSION_MINOR *[0-9]+"
97 string(REGEX MATCH "[0-9]+"
98 Nettle_MINOR_VERSION "${_ver_minor_line}")
99 set(Nettle_VERSION "${Nettle_MAJOR_VERSION}.${Nettle_MINOR_VERSION}")
100 unset(_ver_major_line)
101 unset(_ver_minor_line)
103 if(PC_Nettle_VERSION)
104 set(Nettle_VERSION ${PC_Nettle_VERSION})
106 set(Nettle_VERSION "1.0")
111 include(FindPackageHandleStandardArgs)
112 find_package_handle_standard_args(Nettle
113 FOUND_VAR Nettle_FOUND
117 VERSION_VAR Nettle_VERSION
121 set(Nettle_LIBRARIES ${Nettle_LIBRARY})
122 set(Nettle_INCLUDE_DIRS ${Nettle_INCLUDE_DIR})
123 set(Nettle_DEFINITIONS ${PC_Nettle_CFLAGS_OTHER})
126 if(Nettle_FOUND AND NOT TARGET Nettle::Nettle)
127 add_library(Nettle::Nettle UNKNOWN IMPORTED)
128 set_target_properties(Nettle::Nettle PROPERTIES
129 IMPORTED_LOCATION "${Nettle_LIBRARY}"
130 INTERFACE_COMPILE_OPTIONS "${PC_Nettle_CFLAGS_OTHER}"
131 INTERFACE_INCLUDE_DIRECTORIES "${Nettle_INCLUDE_DIR}"
140 # compatibility variables
141 set(Nettle_VERSION_STRING ${Nettle_VERSION})