FindNettle.cmake 3.0 KB

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