Debian Codegraph @

texk/xdvipsk/thirdparty/libtiff/cmake/FindZSTD.cmake

raw
1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
3
4 #[=======================================================================[.rst:
5 FindZSTD
6 --------
7
8 Find the native ZSTD includes and library.
9
10 IMPORTED Targets
11 ^^^^^^^^^^^^^^^^
12
13 This module defines :prop_tgt:`IMPORTED` target ``ZSTD::ZSTD``, if
14 ZSTD has been found.
15
16 Result Variables
17 ^^^^^^^^^^^^^^^^
18
19 This module defines the following variables:
20
21 ::
22
23 ZSTD_INCLUDE_DIRS - where to find zstd.h, etc.
24 ZSTD_LIBRARIES - List of libraries when using zstd.
25 ZSTD_FOUND - True if zstd found.
26
27 ::
28
29 ZSTD_VERSION_STRING - The version of zstd found (x.y.z)
30 ZSTD_VERSION_MAJOR - The major version of zstd
31 ZSTD_VERSION_MINOR - The minor version of zstd
32
33 Debug and Release variants are found separately.
34 #]=======================================================================]
35
36 # Standard names to search for
37 set(ZSTD_NAMES zstd zstd_static)
38 set(ZSTD_NAMES_DEBUG zstdd zstd_staticd)
39
40 find_path(ZSTD_INCLUDE_DIR
41 NAMES zstd.h
42 PATH_SUFFIXES include)
43
44 # Allow ZSTD_LIBRARY to be set manually, as the location of the zstd library
45 if(NOT ZSTD_LIBRARY)
46 find_library(ZSTD_LIBRARY_RELEASE
47 NAMES ${ZSTD_NAMES}
48 PATH_SUFFIXES lib)
49 find_library(ZSTD_LIBRARY_DEBUG
50 NAMES ${ZSTD_NAMES_DEBUG}
51 PATH_SUFFIXES lib)
52
53 include(SelectLibraryConfigurations)
54 select_library_configurations(ZSTD)
55 endif()
56
57 unset(ZSTD_NAMES)
58 unset(ZSTD_NAMES_DEBUG)
59
60 mark_as_advanced(ZSTD_INCLUDE_DIR)
61
62 if(ZSTD_INCLUDE_DIR AND EXISTS "${ZSTD_INCLUDE_DIR}/zstd.h")
63 file(STRINGS "${ZSTD_INCLUDE_DIR}/zstd.h" ZSTD_H REGEX "^#define ZSTD_VERSION_.*$")
64
65 string(REGEX REPLACE "^.*ZSTD_VERSION_MAJOR *([0-9]+).*$" "\\1" ZSTD_MAJOR_VERSION "${ZSTD_H}")
66 string(REGEX REPLACE "^.*ZSTD_VERSION_MINOR *([0-9]+).*$" "\\1" ZSTD_MINOR_VERSION "${ZSTD_H}")
67 string(REGEX REPLACE "^.*ZSTD_VERSION_RELEASE *([0-9]+).*$" "\\1" ZSTD_PATCH_VERSION "${ZSTD_H}")
68 set(ZSTD_VERSION_STRING "${ZSTD_MAJOR_VERSION}.${ZSTD_MINOR_VERSION}.${ZSTD_PATCH_VERSION}")
69 endif()
70
71 include(FindPackageHandleStandardArgs)
72 FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZSTD
73 REQUIRED_VARS ZSTD_LIBRARY ZSTD_INCLUDE_DIR
74 VERSION_VAR ZSTD_VERSION_STRING)
75
76 if(ZSTD_FOUND)
77 set(ZSTD_INCLUDE_DIRS ${ZSTD_INCLUDE_DIR})
78
79 if(NOT ZSTD_LIBRARIES)
80 set(ZSTD_LIBRARIES ${ZSTD_LIBRARY})
81 endif()
82
83 if(NOT TARGET ZSTD::ZSTD)
84 add_library(ZSTD::ZSTD UNKNOWN IMPORTED)
85 set_target_properties(ZSTD::ZSTD PROPERTIES
86 INTERFACE_INCLUDE_DIRECTORIES "${ZSTD_INCLUDE_DIRS}")
87
88 if(ZSTD_LIBRARY_RELEASE)
89 set_property(TARGET ZSTD::ZSTD APPEND PROPERTY
90 IMPORTED_CONFIGURATIONS RELEASE)
91 set_target_properties(ZSTD::ZSTD PROPERTIES
92 IMPORTED_LOCATION_RELEASE "${ZSTD_LIBRARY_RELEASE}")
93 endif()
94
95 if(ZSTD_LIBRARY_DEBUG)
96 set_property(TARGET ZSTD::ZSTD APPEND PROPERTY
97 IMPORTED_CONFIGURATIONS DEBUG)
98 set_target_properties(ZSTD::ZSTD PROPERTIES
99 IMPORTED_LOCATION_DEBUG "${ZSTD_LIBRARY_DEBUG}")
100 endif()
101
102 if(NOT ZSTD_LIBRARY_RELEASE AND NOT ZSTD_LIBRARY_DEBUG)
103 set_target_properties(ZSTD::ZSTD PROPERTIES
104 IMPORTED_LOCATION "${ZSTD_LIBRARY}")
105 endif()
106 endif()
107 endif()