1#*************************************************************************** 2# _ _ ____ _ 3# Project ___| | | | _ \| | 4# / __| | | | |_) | | 5# | (__| |_| | _ <| |___ 6# \___|\___/|_| \_\_____| 7# 8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 9# 10# This software is licensed as described in the file COPYING, which 11# you should have received as part of this distribution. The terms 12# are also available at https://curl.se/docs/copyright.html. 13# 14# You may opt to use, copy, modify, merge, publish, distribute and/or sell 15# copies of the Software, and permit persons to whom the Software is 16# furnished to do so, under the terms of the COPYING file. 17# 18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19# KIND, either express or implied. 20# 21# SPDX-License-Identifier: curl 22# 23########################################################################### 24# Find the nettle library 25# 26# Input variables: 27# 28# - `NETTLE_INCLUDE_DIR`: The nettle include directory. 29# - `NETTLE_LIBRARY`: Path to `nettle` library. 30# 31# Result variables: 32# 33# - `NETTLE_FOUND`: System has nettle. 34# - `NETTLE_INCLUDE_DIRS`: The nettle include directories. 35# - `NETTLE_LIBRARIES`: The nettle library names. 36# - `NETTLE_LIBRARY_DIRS`: The nettle library directories. 37# - `NETTLE_CFLAGS`: Required compiler flags. 38# - `NETTLE_VERSION`: Version of nettle. 39 40if(CURL_USE_PKGCONFIG AND 41 NOT DEFINED NETTLE_INCLUDE_DIR AND 42 NOT DEFINED NETTLE_LIBRARY) 43 find_package(PkgConfig QUIET) 44 pkg_check_modules(NETTLE "nettle") 45endif() 46 47if(NETTLE_FOUND) 48 string(REPLACE ";" " " NETTLE_CFLAGS "${NETTLE_CFLAGS}") 49 message(STATUS "Found Nettle (via pkg-config): ${NETTLE_INCLUDE_DIRS} (found version \"${NETTLE_VERSION}\")") 50else() 51 find_path(NETTLE_INCLUDE_DIR NAMES "nettle/sha2.h") 52 find_library(NETTLE_LIBRARY NAMES "nettle") 53 54 unset(NETTLE_VERSION CACHE) 55 if(NETTLE_INCLUDE_DIR AND EXISTS "${NETTLE_INCLUDE_DIR}/nettle/version.h") 56 set(_version_regex1 "#[\t ]*define[ \t]+NETTLE_VERSION_MAJOR[ \t]+([0-9]+).*") 57 set(_version_regex2 "#[\t ]*define[ \t]+NETTLE_VERSION_MINOR[ \t]+([0-9]+).*") 58 file(STRINGS "${NETTLE_INCLUDE_DIR}/nettle/version.h" _version_str1 REGEX "${_version_regex1}") 59 file(STRINGS "${NETTLE_INCLUDE_DIR}/nettle/version.h" _version_str2 REGEX "${_version_regex2}") 60 string(REGEX REPLACE "${_version_regex1}" "\\1" _version_str1 "${_version_str1}") 61 string(REGEX REPLACE "${_version_regex2}" "\\1" _version_str2 "${_version_str2}") 62 set(NETTLE_VERSION "${_version_str1}.${_version_str2}") 63 unset(_version_regex1) 64 unset(_version_regex2) 65 unset(_version_str1) 66 unset(_version_str2) 67 endif() 68 69 include(FindPackageHandleStandardArgs) 70 find_package_handle_standard_args(Nettle 71 REQUIRED_VARS 72 NETTLE_INCLUDE_DIR 73 NETTLE_LIBRARY 74 VERSION_VAR 75 NETTLE_VERSION 76 ) 77 78 if(NETTLE_FOUND) 79 set(NETTLE_INCLUDE_DIRS ${NETTLE_INCLUDE_DIR}) 80 set(NETTLE_LIBRARIES ${NETTLE_LIBRARY}) 81 endif() 82 83 mark_as_advanced(NETTLE_INCLUDE_DIR NETTLE_LIBRARY) 84endif() 85