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