FindNettle.cmake (3329B)
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_PC_REQUIRES`: The nettle pkg-config packages. 38 # - `NETTLE_CFLAGS`: Required compiler flags. 39 # - `NETTLE_VERSION`: Version of nettle. 40 41 set(NETTLE_PC_REQUIRES "nettle") 42 43 if(CURL_USE_PKGCONFIG AND 44 NOT DEFINED NETTLE_INCLUDE_DIR AND 45 NOT DEFINED NETTLE_LIBRARY) 46 find_package(PkgConfig QUIET) 47 pkg_check_modules(NETTLE ${NETTLE_PC_REQUIRES}) 48 endif() 49 50 if(NETTLE_FOUND) 51 set(Nettle_FOUND TRUE) 52 string(REPLACE ";" " " NETTLE_CFLAGS "${NETTLE_CFLAGS}") 53 message(STATUS "Found Nettle (via pkg-config): ${NETTLE_INCLUDE_DIRS} (found version \"${NETTLE_VERSION}\")") 54 else() 55 find_path(NETTLE_INCLUDE_DIR NAMES "nettle/sha2.h") 56 find_library(NETTLE_LIBRARY NAMES "nettle") 57 58 unset(NETTLE_VERSION CACHE) 59 if(NETTLE_INCLUDE_DIR AND EXISTS "${NETTLE_INCLUDE_DIR}/nettle/version.h") 60 set(_version_regex1 "#[\t ]*define[ \t]+NETTLE_VERSION_MAJOR[ \t]+([0-9]+).*") 61 set(_version_regex2 "#[\t ]*define[ \t]+NETTLE_VERSION_MINOR[ \t]+([0-9]+).*") 62 file(STRINGS "${NETTLE_INCLUDE_DIR}/nettle/version.h" _version_str1 REGEX "${_version_regex1}") 63 file(STRINGS "${NETTLE_INCLUDE_DIR}/nettle/version.h" _version_str2 REGEX "${_version_regex2}") 64 string(REGEX REPLACE "${_version_regex1}" "\\1" _version_str1 "${_version_str1}") 65 string(REGEX REPLACE "${_version_regex2}" "\\1" _version_str2 "${_version_str2}") 66 set(NETTLE_VERSION "${_version_str1}.${_version_str2}") 67 unset(_version_regex1) 68 unset(_version_regex2) 69 unset(_version_str1) 70 unset(_version_str2) 71 endif() 72 73 include(FindPackageHandleStandardArgs) 74 find_package_handle_standard_args(Nettle 75 REQUIRED_VARS 76 NETTLE_INCLUDE_DIR 77 NETTLE_LIBRARY 78 VERSION_VAR 79 NETTLE_VERSION 80 ) 81 82 if(NETTLE_FOUND) 83 set(NETTLE_INCLUDE_DIRS ${NETTLE_INCLUDE_DIR}) 84 set(NETTLE_LIBRARIES ${NETTLE_LIBRARY}) 85 endif() 86 87 mark_as_advanced(NETTLE_INCLUDE_DIR NETTLE_LIBRARY) 88 endif()