|
| 1 | +# Copyright (C) 2020 Dieter Baron and Thomas Klausner |
| 2 | +# |
| 3 | +# The authors can be contacted at <info@libzip.org> |
| 4 | +# |
| 5 | +# Redistribution and use in source and binary forms, with or without |
| 6 | +# modification, are permitted provided that the following conditions |
| 7 | +# are met: |
| 8 | +# |
| 9 | +# 1. Redistributions of source code must retain the above copyright |
| 10 | +# notice, this list of conditions and the following disclaimer. |
| 11 | +# |
| 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 |
| 15 | +# distribution. |
| 16 | +# |
| 17 | +# 3. The names of the authors may not be used to endorse or promote |
| 18 | +# products derived from this software without specific prior |
| 19 | +# written permission. |
| 20 | +# |
| 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. |
| 32 | + |
| 33 | +#[=======================================================================[.rst: |
| 34 | +FindNettle |
| 35 | +------- |
| 36 | +
|
| 37 | +Finds the Nettle library. |
| 38 | +
|
| 39 | +Imported Targets |
| 40 | +^^^^^^^^^^^^^^^^ |
| 41 | +
|
| 42 | +This module provides the following imported targets, if found: |
| 43 | +
|
| 44 | +``Nettle::Nettle`` |
| 45 | + The Nettle library |
| 46 | +
|
| 47 | +Result Variables |
| 48 | +^^^^^^^^^^^^^^^^ |
| 49 | +
|
| 50 | +This will define the following variables: |
| 51 | +
|
| 52 | +``Nettle_FOUND`` |
| 53 | + True if the system has the Nettle library. |
| 54 | +``Nettle_VERSION`` |
| 55 | + The version of the Nettle library which was found. |
| 56 | +``Nettle_INCLUDE_DIRS`` |
| 57 | + Include directories needed to use Nettle. |
| 58 | +``Nettle_LIBRARIES`` |
| 59 | + Libraries needed to link to Nettle. |
| 60 | +
|
| 61 | +Cache Variables |
| 62 | +^^^^^^^^^^^^^^^ |
| 63 | +
|
| 64 | +The following cache variables may also be set: |
| 65 | +
|
| 66 | +``Nettle_INCLUDE_DIR`` |
| 67 | + The directory containing ``nettle/aes.h``. |
| 68 | +``Nettle_LIBRARY`` |
| 69 | + The path to the Nettle library. |
| 70 | +
|
| 71 | +#]=======================================================================] |
| 72 | + |
| 73 | +find_package(PkgConfig) |
| 74 | +pkg_check_modules(PC_Nettle QUIET nettle) |
| 75 | + |
| 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} |
| 79 | +) |
| 80 | +find_library(Nettle_LIBRARY |
| 81 | + NAMES nettle |
| 82 | + PATHS ${PC_Nettle_LIBRARY_DIRS} |
| 83 | +) |
| 84 | + |
| 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]+" |
| 91 | + LIMIT_COUNT 1) |
| 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]+" |
| 96 | + LIMIT_COUNT 1) |
| 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) |
| 102 | + else() |
| 103 | + if(PC_Nettle_VERSION) |
| 104 | + set(Nettle_VERSION ${PC_Nettle_VERSION}) |
| 105 | + else() |
| 106 | + set(Nettle_VERSION "1.0") |
| 107 | + endif() |
| 108 | + endif() |
| 109 | +endif() |
| 110 | + |
| 111 | +include(FindPackageHandleStandardArgs) |
| 112 | +find_package_handle_standard_args(Nettle |
| 113 | + FOUND_VAR Nettle_FOUND |
| 114 | + REQUIRED_VARS |
| 115 | + Nettle_LIBRARY |
| 116 | + Nettle_INCLUDE_DIR |
| 117 | + VERSION_VAR Nettle_VERSION |
| 118 | +) |
| 119 | + |
| 120 | +if(Nettle_FOUND) |
| 121 | + set(Nettle_LIBRARIES ${Nettle_LIBRARY}) |
| 122 | + set(Nettle_INCLUDE_DIRS ${Nettle_INCLUDE_DIR}) |
| 123 | + set(Nettle_DEFINITIONS ${PC_Nettle_CFLAGS_OTHER}) |
| 124 | +endif() |
| 125 | + |
| 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}" |
| 132 | + ) |
| 133 | +endif() |
| 134 | + |
| 135 | +mark_as_advanced( |
| 136 | + Nettle_INCLUDE_DIR |
| 137 | + Nettle_LIBRARY |
| 138 | +) |
| 139 | + |
| 140 | +# compatibility variables |
| 141 | +set(Nettle_VERSION_STRING ${Nettle_VERSION}) |
0 commit comments