[cosmetic] separate c-lang format commit
[xbmc.git] / cmake / modules / FindBrotli.cmake
blob3b8a0befc6c7e43ae8b1413fc56093d29e125841
1 #.rst:
2 # FindBrotli
3 # ----------
4 # Finds the Brotli library
6 # This will define the following target ALIAS:
8 #   Brotli::Brotli   - The Brotli library
10 # The following IMPORTED targets are made
12 #   Brotli::BrotliCommon - The brotlicommon library
13 #   Brotli::BrotliDec - The brotlidec library
16 if(NOT TARGET Brotli::Brotli)
17   find_package(PkgConfig)
18   if(PKG_CONFIG_FOUND AND NOT (WIN32 OR WINDOWSSTORE))
19     pkg_check_modules(BROTLICOMMON libbrotlicommon QUIET)
20     # First item is the full path of the library file found
21     # pkg_check_modules does not populate a variable of the found library explicitly
22     list(GET BROTLICOMMON_LINK_LIBRARIES 0 BROTLICOMMON_LIBRARY)
24     pkg_check_modules(BROTLIDEC libbrotlidec QUIET)
25     # First item is the full path of the library file found
26     # pkg_check_modules does not populate a variable of the found library explicitly
27     list(GET BROTLIDEC_LINK_LIBRARIES 0 BROTLIDEC_LIBRARY)
29     set(BROTLI_INCLUDE_DIR ${BROTLICOMMON_INCLUDEDIR})
30     set(BROTLI_VERSION ${BROTLICOMMON_VERSION})
31   else()
32     find_path(BROTLI_INCLUDE_DIR NAMES brotli/decode.h
33                                  HINTS ${DEPENDS_PATH}/include ${BROTLICOMMON_INCLUDEDIR}
34                                  ${${CORE_PLATFORM_LC}_SEARCH_CONFIG})
35     find_library(BROTLICOMMON_LIBRARY NAMES brotlicommon
36                                       HINTS ${DEPENDS_PATH}/lib ${BROTLICOMON_LIBDIR}
37                                       ${${CORE_PLATFORM_LC}_SEARCH_CONFIG})
39     find_library(BROTLIDEC_LIBRARY NAMES brotlidec
40                                    HINTS ${DEPENDS_PATH}/lib ${BROTLIDEC_LIBDIR}
41                                    ${${CORE_PLATFORM_LC}_SEARCH_CONFIG})
42   endif()
44   include(FindPackageHandleStandardArgs)
45   find_package_handle_standard_args(Brotli
46                                     REQUIRED_VARS BROTLICOMMON_LIBRARY BROTLIDEC_LIBRARY BROTLI_INCLUDE_DIR
47                                     VERSION_VAR BROTLI_VERSION)
49   if(BROTLI_FOUND)
50     add_library(Brotli::BrotliCommon UNKNOWN IMPORTED)
51     set_target_properties(Brotli::BrotliCommon PROPERTIES
52                                                IMPORTED_LOCATION "${BROTLICOMMON_LIBRARY}"
53                                                INTERFACE_INCLUDE_DIRECTORIES "${BROTLI_INCLUDE_DIR}")
55     add_library(Brotli::BrotliDec UNKNOWN IMPORTED)
56     set_target_properties(Brotli::BrotliDec PROPERTIES
57                                             IMPORTED_LOCATION "${BROTLIDEC_LIBRARY}"
58                                             INTERFACE_LINK_LIBRARIES Brotli::BrotliCommon
59                                             INTERFACE_INCLUDE_DIRECTORIES "${BROTLI_INCLUDE_DIR}")
61     add_library(Brotli::Brotli ALIAS Brotli::BrotliDec)
63   else()
64     if(Brotli_FIND_REQUIRED)
65       message(FATAL_ERROR "Brotli libraries were not found.")
66     endif()
67   endif()
68 endif()