FindNettle.cmake 3.1 KB

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