FindNettle.cmake 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. # - Try to find the nettle library
  25. # Once done this will define
  26. #
  27. # NETTLE_FOUND - system has nettle
  28. # NETTLE_INCLUDE_DIRS - nettle include directories
  29. # NETTLE_LIBRARIES - nettle library names
  30. if(UNIX)
  31. find_package(PkgConfig QUIET)
  32. pkg_check_modules(NETTLE "nettle")
  33. endif()
  34. if(NETTLE_FOUND)
  35. set(NETTLE_LIBRARIES ${NETTLE_LINK_LIBRARIES})
  36. else()
  37. find_path(NETTLE_INCLUDE_DIR NAMES "nettle/sha2.h")
  38. find_library(NETTLE_LIBRARY NAMES "nettle")
  39. if(NETTLE_INCLUDE_DIR)
  40. if(EXISTS "${NETTLE_INCLUDE_DIR}/nettle/version.h")
  41. set(_version_regex_major "^#define[ \t]+NETTLE_VERSION_MAJOR[ \t]+([0-9]+).*")
  42. set(_version_regex_minor "^#define[ \t]+NETTLE_VERSION_MINOR[ \t]+([0-9]+).*")
  43. file(STRINGS "${NETTLE_INCLUDE_DIR}/nettle/version.h"
  44. _version_major REGEX "${_version_regex_major}")
  45. file(STRINGS "${NETTLE_INCLUDE_DIR}/nettle/version.h"
  46. _version_minor REGEX "${_version_regex_minor}")
  47. string(REGEX REPLACE "${_version_regex_major}" "\\1" _version_major "${_version_major}")
  48. string(REGEX REPLACE "${_version_regex_minor}" "\\1" _version_minor "${_version_minor}")
  49. unset(_version_regex_major)
  50. unset(_version_regex_minor)
  51. set(NETTLE_VERSION "${_version_major}.${_version_minor}")
  52. unset(_version_major)
  53. unset(_version_minor)
  54. else()
  55. set(NETTLE_VERSION "0.0")
  56. endif()
  57. endif()
  58. include(FindPackageHandleStandardArgs)
  59. find_package_handle_standard_args("nettle"
  60. REQUIRED_VARS
  61. NETTLE_INCLUDE_DIR
  62. NETTLE_LIBRARY
  63. VERSION_VAR NETTLE_VERSION)
  64. if(NETTLE_FOUND)
  65. set(NETTLE_INCLUDE_DIRS ${NETTLE_INCLUDE_DIR})
  66. set(NETTLE_LIBRARIES ${NETTLE_LIBRARY})
  67. endif()
  68. mark_as_advanced(NETTLE_INCLUDE_DIR NETTLE_LIBRARY)
  69. endif()