xref: /curl/CMake/FindBrotli.cmake (revision f66af623)
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 brotli library
25#
26# Input variables:
27#
28# - `BROTLI_INCLUDE_DIR`:    The brotli include directory.
29# - `BROTLICOMMON_LIBRARY`:  Path to `brotlicommon` library.
30# - `BROTLIDEC_LIBRARY`:     Path to `brotlidec` library.
31#
32# Result variables:
33#
34# - `BROTLI_FOUND`:          System has brotli.
35# - `BROTLI_INCLUDE_DIRS`:   The brotli include directories.
36# - `BROTLI_LIBRARIES`:      The brotli library names.
37# - `BROTLI_VERSION`:        Version of brotli.
38
39if(CURL_USE_PKGCONFIG)
40  find_package(PkgConfig QUIET)
41  pkg_check_modules(PC_BROTLI "libbrotlidec")
42endif()
43
44find_path(BROTLI_INCLUDE_DIR "brotli/decode.h"
45  HINTS
46    ${PC_BROTLI_INCLUDEDIR}
47    ${PC_BROTLI_INCLUDE_DIRS}
48)
49
50find_library(BROTLICOMMON_LIBRARY NAMES "brotlicommon"
51  HINTS
52    ${PC_BROTLI_LIBDIR}
53    ${PC_BROTLI_LIBRARY_DIRS}
54)
55find_library(BROTLIDEC_LIBRARY NAMES "brotlidec"
56  HINTS
57    ${PC_BROTLI_LIBDIR}
58    ${PC_BROTLI_LIBRARY_DIRS}
59)
60
61if(PC_BROTLI_VERSION)
62  set(BROTLI_VERSION ${PC_BROTLI_VERSION})
63endif()
64
65include(FindPackageHandleStandardArgs)
66find_package_handle_standard_args(Brotli
67  REQUIRED_VARS
68    BROTLI_INCLUDE_DIR
69    BROTLIDEC_LIBRARY
70    BROTLICOMMON_LIBRARY
71  VERSION_VAR
72    BROTLI_VERSION
73)
74
75if(BROTLI_FOUND)
76  set(BROTLI_INCLUDE_DIRS ${BROTLI_INCLUDE_DIR})
77  set(BROTLI_LIBRARIES ${BROTLIDEC_LIBRARY} ${BROTLICOMMON_LIBRARY})
78endif()
79
80mark_as_advanced(BROTLI_INCLUDE_DIR BROTLIDEC_LIBRARY BROTLICOMMON_LIBRARY)
81