1 # Copyright (C) 2020 Dieter Baron and Thomas Klausner
3 # The authors can be contacted at <libzip@nih.at>
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in
14 # the documentation and/or other materials provided with the
17 # 3. The names of the authors may not be used to endorse or promote
18 # products derived from this software without specific prior
21 # THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
22 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
25 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
29 # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
31 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #[=======================================================================[.rst:
37 Finds the Zstandard (zstd) library.
42 This module provides the following imported targets, if found:
50 This will define the following variables:
53 True if the system has the Zstandard library.
55 The version of the Zstandard library which was found.
57 Include directories needed to use Zstandard.
59 Libraries needed to link to Zstandard.
64 The following cache variables may also be set:
67 The directory containing ``zstd.h``.
69 The path to the Zstandard library.
71 #]=======================================================================]
73 find_package(PkgConfig)
74 pkg_check_modules(PC_Zstd QUIET zstd)
76 find_path(Zstd_INCLUDE_DIR
78 PATHS ${PC_Zstd_INCLUDE_DIRS}
80 find_library(Zstd_LIBRARY
82 PATHS ${PC_Zstd_LIBRARY_DIRS}
85 # Extract version information from the header file
87 file(STRINGS ${Zstd_INCLUDE_DIR}/zstd.h _ver_major_line
88 REGEX "^#define ZSTD_VERSION_MAJOR *[0-9]+"
90 string(REGEX MATCH "[0-9]+"
91 Zstd_MAJOR_VERSION "${_ver_major_line}")
92 file(STRINGS ${Zstd_INCLUDE_DIR}/zstd.h _ver_minor_line
93 REGEX "^#define ZSTD_VERSION_MINOR *[0-9]+"
95 string(REGEX MATCH "[0-9]+"
96 Zstd_MINOR_VERSION "${_ver_minor_line}")
97 file(STRINGS ${Zstd_INCLUDE_DIR}/zstd.h _ver_release_line
98 REGEX "^#define ZSTD_VERSION_RELEASE *[0-9]+"
100 string(REGEX MATCH "[0-9]+"
101 Zstd_RELEASE_VERSION "${_ver_release_line}")
102 set(Zstd_VERSION "${Zstd_MAJOR_VERSION}.${Zstd_MINOR_VERSION}.${Zstd_RELEASE_VERSION}")
103 unset(_ver_major_line)
104 unset(_ver_minor_line)
105 unset(_ver_release_line)
108 include(FindPackageHandleStandardArgs)
109 find_package_handle_standard_args(Zstd
114 VERSION_VAR Zstd_VERSION
118 set(Zstd_LIBRARIES ${Zstd_LIBRARY})
119 set(Zstd_INCLUDE_DIRS ${Zstd_INCLUDE_DIR})
120 set(Zstd_DEFINITIONS ${PC_Zstd_CFLAGS_OTHER})
123 if(Zstd_FOUND AND NOT TARGET Zstd::Zstd)
124 add_library(Zstd::Zstd UNKNOWN IMPORTED)
125 set_target_properties(Zstd::Zstd PROPERTIES
126 IMPORTED_LOCATION "${Zstd_LIBRARY}"
127 INTERFACE_COMPILE_OPTIONS "${PC_Zstd_CFLAGS_OTHER}"
128 INTERFACE_INCLUDE_DIRECTORIES "${Zstd_INCLUDE_DIR}"