FindZstd.cmake 3.4 KB

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