2
0

FindZstd.cmake 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 zstd library
  25. #
  26. # Input variables:
  27. #
  28. # ZSTD_INCLUDE_DIR The zstd include directory
  29. # Zstd_INCLUDE_DIR The zstd include directory (deprecated)
  30. # ZSTD_LIBRARY Path to zstd library
  31. # Zstd_LIBRARY Path to zstd library (deprecated)
  32. #
  33. # Result variables:
  34. #
  35. # ZSTD_FOUND System has zstd
  36. # ZSTD_INCLUDE_DIRS The zstd include directories
  37. # ZSTD_LIBRARIES The zstd library names
  38. # ZSTD_VERSION Version of zstd
  39. if(DEFINED Zstd_INCLUDE_DIR AND NOT DEFINED ZSTD_INCLUDE_DIR)
  40. message(WARNING "Zstd_INCLUDE_DIR is deprecated, use ZSTD_INCLUDE_DIR instead.")
  41. set(ZSTD_INCLUDE_DIR "${Zstd_INCLUDE_DIR}")
  42. endif()
  43. if(DEFINED Zstd_LIBRARY AND NOT DEFINED ZSTD_LIBRARY)
  44. message(WARNING "Zstd_LIBRARY is deprecated, use ZSTD_LIBRARY instead.")
  45. set(ZSTD_LIBRARY "${Zstd_LIBRARY}")
  46. endif()
  47. if(CURL_USE_PKGCONFIG)
  48. find_package(PkgConfig QUIET)
  49. pkg_check_modules(PC_ZSTD "libzstd")
  50. endif()
  51. find_path(ZSTD_INCLUDE_DIR NAMES "zstd.h"
  52. HINTS
  53. ${PC_ZSTD_INCLUDEDIR}
  54. ${PC_ZSTD_INCLUDE_DIRS}
  55. )
  56. find_library(ZSTD_LIBRARY NAMES "zstd"
  57. HINTS
  58. ${PC_ZSTD_LIBDIR}
  59. ${PC_ZSTD_LIBRARY_DIRS}
  60. )
  61. if(PC_ZSTD_VERSION)
  62. set(ZSTD_VERSION ${PC_ZSTD_VERSION})
  63. elseif(ZSTD_INCLUDE_DIR AND EXISTS "${ZSTD_INCLUDE_DIR}/zstd.h")
  64. set(_version_regex1 "#[\t ]*define[ \t]+ZSTD_VERSION_MAJOR[ \t]+([0-9]+).*")
  65. set(_version_regex2 "#[\t ]*define[ \t]+ZSTD_VERSION_MINOR[ \t]+([0-9]+).*")
  66. set(_version_regex3 "#[\t ]*define[ \t]+ZSTD_VERSION_RELEASE[ \t]+([0-9]+).*")
  67. file(STRINGS "${ZSTD_INCLUDE_DIR}/zstd.h" _version_str1 REGEX "${_version_regex1}")
  68. file(STRINGS "${ZSTD_INCLUDE_DIR}/zstd.h" _version_str2 REGEX "${_version_regex2}")
  69. file(STRINGS "${ZSTD_INCLUDE_DIR}/zstd.h" _version_str3 REGEX "${_version_regex3}")
  70. string(REGEX REPLACE "${_version_regex1}" "\\1" _version_str1 "${_version_str1}")
  71. string(REGEX REPLACE "${_version_regex2}" "\\1" _version_str2 "${_version_str2}")
  72. string(REGEX REPLACE "${_version_regex3}" "\\1" _version_str3 "${_version_str3}")
  73. set(ZSTD_VERSION "${_version_str1}.${_version_str2}.${_version_str3}")
  74. unset(_version_regex1)
  75. unset(_version_regex2)
  76. unset(_version_regex3)
  77. unset(_version_str1)
  78. unset(_version_str2)
  79. unset(_version_str3)
  80. endif()
  81. include(FindPackageHandleStandardArgs)
  82. find_package_handle_standard_args(Zstd
  83. REQUIRED_VARS
  84. ZSTD_INCLUDE_DIR
  85. ZSTD_LIBRARY
  86. VERSION_VAR
  87. ZSTD_VERSION
  88. )
  89. if(ZSTD_FOUND)
  90. set(ZSTD_INCLUDE_DIRS ${ZSTD_INCLUDE_DIR})
  91. set(ZSTD_LIBRARIES ${ZSTD_LIBRARY})
  92. endif()
  93. mark_as_advanced(ZSTD_INCLUDE_DIR ZSTD_LIBRARY)