Debian Codegraph @

cmake/modules/FindWebP.cmake

raw
1 # Copyright (C) 2020 Sony Interactive Entertainment Inc.
2 # Copyright (C) 2012 Raphael Kubo da Costa <[email protected]>
3 # Copyright (C) 2013 Igalia S.L.
4 # Copyright (C) 2021 L. E. Segovia <[email protected]>
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS
16 # IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS
19 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 #[=======================================================================[.rst:
28 FindWebP
29 --------------
30
31 Find WebP headers and libraries.
32
33 Imported Targets
34 ^^^^^^^^^^^^^^^^
35
36 ``WebP::webp``
37 The WebP library, if found.
38
39 ``WebP::webpdemux``
40 The WebP demux library, if found.
41
42 ``WebP::libwebpmux``
43 The WebP mux library, if found.
44
45 ``WebP::decoder``
46 The WebP decoder library, if found.
47
48 ``WebP::sharpyuv``
49 The WebP Sharp RGB to YUV420 conversion library, if found.
50
51 Result Variables
52 ^^^^^^^^^^^^^^^^
53
54 This will define the following variables in your project:
55
56 ``WebP_FOUND``
57 true if (the requested version of) WebP is available.
58 ``WebP_VERSION``
59 the version of WebP.
60 ``WebP_LIBRARIES``
61 the libraries to link against to use WebP.
62 ``WebP_INCLUDE_DIRS``
63 where to find the WebP headers.
64 ``WebP_COMPILE_OPTIONS``
65 this should be passed to target_compile_options(), if the
66 target is not used for linking
67
68 #]=======================================================================]
69
70 include(FindPackageHandleStandardArgs)
71
72 set(PC_WEBP_CONFIG_DIR CACHE STRING "PkgConfig path for locating the package modules")
73 foreach(_dir ${CMAKE_PREFIX_PATH})
74 list(APPEND PC_WEBP_CONFIG_DIR ${_dir}/share/WebP/cmake)
75 endforeach()
76 mark_as_advanced(PC_WEBP_CONFIG_DIR)
77
78 find_package(WebP QUIET NO_MODULE
79 HINTS ${PC_WEBP_CONFIG_DIR} /usr/share/WebP/cmake /usr/local/share/WebP/cmake
80 )
81 mark_as_advanced(WebP_DIR)
82
83 # if we found the WebP CMake package then we are done, and
84 # can print what we found and return.
85 if(WebP_FOUND)
86 if (TARGET WebP::webp)
87 set(WebP_webp_FOUND ON)
88 else ()
89 set(WebP_webp_FOUND OFF)
90 endif ()
91
92 if (TARGET WebP::webpdemux)
93 set(WebP_demux_FOUND ON)
94 else ()
95 set(WebP_demux_FOUND OFF)
96 endif ()
97
98 if (TARGET WebP::libwebpmux)
99 set(WebP_mux_FOUND ON)
100 else ()
101 set(WebP_mux_FOUND OFF)
102 endif ()
103
104 if (TARGET WebP::decoder)
105 set(WebP_decoder_FOUND ON)
106 else ()
107 set(WebP_decoder_FOUND OFF)
108 endif ()
109
110 if (TARGET WebP::sharpyuv)
111 set(WebP_sharpyuv_FOUND ON)
112 else ()
113 set(WebP_sharpyuv_FOUND OFF)
114 endif ()
115
116 find_package_handle_standard_args(WebP
117 FOUND_VAR WebP_FOUND
118 HANDLE_COMPONENTS
119 CONFIG_MODE
120 )
121 return()
122 endif()
123
124 find_package(PkgConfig QUIET)
125
126 if (PkgConfig_FOUND)
127 pkg_check_modules(PC_WEBP QUIET libwebp)
128 set(WebP_VERSION ${PC_WEBP_VERSION})
129 set(WebP_COMPILE_OPTIONS "${PC_WEBP_CFLAGS};${PC_WEBP_CFLAGS_OTHER}")
130
131 pkg_check_modules(PC_WEBP_DECODER QUIET libwebpdecoder)
132
133 pkg_check_modules(PC_WEBP_DEMUX QUIET libwebpdemux)
134
135 pkg_check_modules(PC_WEBP_DECODER QUIET libwebpmux)
136
137 pkg_check_modules(PC_WEBP_SHARPYUV QUIET libsharpyuv)
138 endif ()
139
140 find_path(WebP_INCLUDE_DIR
141 NAMES webp/decode.h
142 HINTS ${PC_WEBP_INCLUDEDIR} ${PC_WEBP_INCLUDE_DIRS}
143 )
144
145 find_library(WebP_LIBRARY
146 NAMES ${WebP_NAMES} webp libwebp
147 HINTS ${PC_WEBP_LIBDIR} ${PC_WEBP_LIBRARY_DIRS}
148 )
149
150 # There's nothing in the WebP headers that could be used to detect the exact
151 # WebP version being used so don't attempt to do so. A version can only be found
152 # through pkg-config
153 if (NOT WebP_VERSION)
154 message(WARNING "Cannot determine WebP version without pkg-config")
155 endif ()
156
157 if (WebP_INCLUDE_DIR AND WebP_LIBRARY)
158 set(WebP_webp_FOUND ON)
159 else()
160 set(WebP_webp_FOUND OFF)
161 endif()
162
163 # Find components
164 if ("demux" IN_LIST WebP_FIND_COMPONENTS)
165 find_library(WebP_DEMUX_LIBRARY
166 NAMES ${WebP_DEMUX_NAMES} webpdemux libwebpdemux
167 HINTS ${PC_WEBP_LIBDIR} ${PC_WEBP_LIBRARY_DIRS}
168 )
169
170 if (WebP_DEMUX_LIBRARY)
171 set(WebP_demux_FOUND ON)
172 else ()
173 set(WebP_demux_FOUND OFF)
174 endif ()
175 endif ()
176
177 if ("mux" IN_LIST WebP_FIND_COMPONENTS)
178 find_library(WebP_MUX_LIBRARY
179 NAMES ${WebP_MUX_NAMES} webpmux libwebpmux
180 HINTS ${PC_WEBP_LIBDIR} ${PC_WEBP_LIBRARY_DIRS}
181 )
182
183 if (WebP_MUX_LIBRARY)
184 set(WebP_mux_FOUND ON)
185 else ()
186 set(WebP_mux_FOUND OFF)
187 endif ()
188 endif ()
189
190 if ("decoder" IN_LIST WebP_FIND_COMPONENTS)
191 find_library(WebP_DECODER_LIBRARY
192 NAMES ${WebP_DECODER_NAMES} webpdecoder libwebpdecoder
193 HINTS ${PC_WEBP_LIBDIR} ${PC_WEBP_LIBRARY_DIRS}
194 )
195
196 if (WebP_DECODER_LIBRARY)
197 set(WebP_decoder_FOUND ON)
198 else ()
199 set(WebP_decoder_FOUND OFF)
200 endif ()
201 endif ()
202
203 # SharpYUV is a dependency of WebP, should be looked up
204 # if neither the CMake module nor pkgconf are available
205 # (this could only happen, in theory, in Windows MSVC)
206 if ("sharpyuv" IN_LIST WebP_FIND_COMPONENTS OR WebP_webp_FOUND)
207 find_library(WebP_SHARPYUV_LIBRARY
208 NAMES ${WebP_DECODER_NAMES} sharpyuv libsharpyuv
209 HINTS ${PC_WEBP_LIBDIR} ${PC_WEBP_LIBRARY_DIRS}
210 )
211
212 if (WebP_SHARPYUV_LIBRARY)
213 set(WebP_sharpyuv_FOUND ON)
214 else ()
215 set(WebP_sharpyuv_FOUND OFF)
216 endif ()
217 endif ()
218
219 find_package_handle_standard_args(WebP
220 FOUND_VAR WebP_FOUND
221 REQUIRED_VARS WebP_INCLUDE_DIR WebP_LIBRARY
222 HANDLE_COMPONENTS
223 VERSION_VAR WebP_VERSION
224 )
225
226 if (WebP_FOUND)
227 if (WebP_LIBRARY AND NOT TARGET WebP::webp)
228 add_library(WebP::webp UNKNOWN IMPORTED GLOBAL)
229 set_target_properties(WebP::webp PROPERTIES
230 IMPORTED_LOCATION "${WebP_LIBRARY}"
231 INTERFACE_COMPILE_OPTIONS "${PC_WEBP_CFLAGS};${PC_WEBP_CFLAGS_OTHER}"
232 INTERFACE_INCLUDE_DIRECTORIES "${WebP_INCLUDE_DIR};${PC_WEBP_INCLUDE_DIRS}"
233 INTERFACE_LINK_LIBRARIES "${PC_WEBP_LINK_LIBRARIES}"
234 )
235 endif ()
236
237 if (WebP_DEMUX_LIBRARY AND NOT TARGET WebP::webpdemux)
238 add_library(WebP::webpdemux UNKNOWN IMPORTED GLOBAL)
239 set_target_properties(WebP::webpdemux PROPERTIES
240 IMPORTED_LOCATION "${WebP_DEMUX_LIBRARY}"
241 INTERFACE_COMPILE_OPTIONS "${PC_WEBP_DEMUX_CFLAGS};${PC_WEBP_DEMUX_CFLAGS_OTHER}"
242 INTERFACE_INCLUDE_DIRECTORIES "${WebP_INCLUDE_DIR};${PC_WEBP_DEMUX_INCLUDE_DIRS}"
243 INTERFACE_LINK_LIBRARIES "${PC_WEBP_DEMUX_LINK_LIBRARIES}"
244 )
245 endif ()
246
247 if (WebP_MUX_LIBRARY AND NOT TARGET WebP::libwebpmux)
248 add_library(WebP::libwebpmux UNKNOWN IMPORTED GLOBAL)
249 set_target_properties(WebP::libwebpmux PROPERTIES
250 IMPORTED_LOCATION "${WebP_MUX_LIBRARY}"
251 INTERFACE_COMPILE_OPTIONS "${PC_WEBP_MUX_CFLAGS};${PC_WEBP_MUX_CFLAGS_OTHER}"
252 INTERFACE_INCLUDE_DIRECTORIES "${WebP_INCLUDE_DIR};${PC_WEBP_MUX_INCLUDE_DIRS}"
253 INTERFACE_LINK_LIBRARIES "${PC_WEBP_MUX_LINK_LIBRARIES}"
254 )
255 endif ()
256
257 if (WebP_DECODER_LIBRARY AND NOT TARGET WebP::webpdecoder)
258 add_library(WebP::webpdecoder UNKNOWN IMPORTED GLOBAL)
259 set_target_properties(WebP::webpdecoder PROPERTIES
260 IMPORTED_LOCATION "${WebP_DECODER_LIBRARY}"
261 INTERFACE_COMPILE_OPTIONS "${PC_WEBP_DECODER_CFLAGS};${PC_WEBP_DECODER_CFLAGS_OTHER}"
262 INTERFACE_INCLUDE_DIRECTORIES "${WebP_INCLUDE_DIR};${PC_WEBP_DECODER_INCLUDE_DIRS}"
263 INTERFACE_LINK_LIBRARIES "${PC_WEBP_DECODER_LINK_LIBRARIES}"
264 )
265 endif ()
266
267 if (WebP_SHARPYUV_LIBRARY AND NOT TARGET WebP::sharpyuv)
268 add_library(WebP::sharpyuv UNKNOWN IMPORTED GLOBAL)
269 set_target_properties(WebP::sharpyuv PROPERTIES
270 IMPORTED_LOCATION "${WebP_SHARPYUV_LIBRARY}"
271 INTERFACE_COMPILE_OPTIONS "${PC_WEBP_SHARPYUV_CFLAGS};${PC_WEBP_SHARPYUV_CFLAGS_OTHER}"
272 INTERFACE_INCLUDE_DIRECTORIES "${WebP_INCLUDE_DIR};${PC_WEBP_SHARPYUV_INCLUDE_DIRS}"
273 INTERFACE_LINK_LIBRARIES "${PC_WEBP_SHARPYUV_LINK_LIBRARIES}"
274 )
275 endif ()
276
277 mark_as_advanced(
278 WebP_INCLUDE_DIR
279 WebP_LIBRARY
280 WebP_DEMUX_LIBRARY
281 WebP_MUX_LIBRARY
282 WebP_DECODER_LIBRARY
283 WebP_SHARPYUV_LIBRARY
284 )
285
286 set(WebP_LIBRARIES ${WebP_LIBRARY} ${WebP_DEMUX_LIBRARY} ${WebP_MUX_LIBRARY} ${WebP_DECODER_LIBRARY} ${WebP_SHARPYUV_LIBRARY})
287 set(WebP_INCLUDE_DIRS ${WebP_INCLUDE_DIR})
288
289 endif()