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 if(NETTLE_INCLUDE_DIR AND EXISTS "${NETTLE_INCLUDE_DIR}/nettle/version.h") 55 set(_version_regex1 "#[\t ]*define[ \t]+NETTLE_VERSION_MAJOR[ \t]+([0-9]+).*") 56 set(_version_regex2 "#[\t ]*define[ \t]+NETTLE_VERSION_MINOR[ \t]+([0-9]+).*") 57 file(STRINGS "${NETTLE_INCLUDE_DIR}/nettle/version.h" _version_str1 REGEX "${_version_regex1}") 58 file(STRINGS "${NETTLE_INCLUDE_DIR}/nettle/version.h" _version_str2 REGEX "${_version_regex2}") 59 string(REGEX REPLACE "${_version_regex1}" "\\1" _version_str1 "${_version_str1}") 60 string(REGEX REPLACE "${_version_regex2}" "\\1" _version_str2 "${_version_str2}") 61 set(NETTLE_VERSION "${_version_str1}.${_version_str2}") 62 unset(_version_regex1) 63 unset(_version_regex2) 64 unset(_version_str1) 65 unset(_version_str2) 66 endif() 67 68 include(FindPackageHandleStandardArgs) 69 find_package_handle_standard_args(Nettle 70 REQUIRED_VARS 71 NETTLE_INCLUDE_DIR 72 NETTLE_LIBRARY 73 VERSION_VAR 74 NETTLE_VERSION 75 ) 76 77 if(NETTLE_FOUND) 78 set(NETTLE_INCLUDE_DIRS ${NETTLE_INCLUDE_DIR}) 79 set(NETTLE_LIBRARIES ${NETTLE_LIBRARY}) 80 endif() 81 82 mark_as_advanced(NETTLE_INCLUDE_DIR NETTLE_LIBRARY) 83endif() 84