FindBrotli.cmake 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_LIBRARY_DIRS`: The brotli library directories.
  38. # - `BROTLI_CFLAGS`: Required compiler flags.
  39. # - `BROTLI_VERSION`: Version of brotli.
  40. if(CURL_USE_PKGCONFIG AND
  41. NOT DEFINED BROTLI_INCLUDE_DIR AND
  42. NOT DEFINED BROTLICOMMON_LIBRARY AND
  43. NOT DEFINED BROTLIDEC_LIBRARY)
  44. find_package(PkgConfig QUIET)
  45. pkg_check_modules(BROTLI "libbrotlicommon")
  46. pkg_check_modules(BROTLIDEC "libbrotlidec")
  47. endif()
  48. if(BROTLI_FOUND AND BROTLIDEC_FOUND)
  49. list(APPEND BROTLIDEC_LIBRARIES ${BROTLI_LIBRARIES}) # order is significant: brotlidec then brotlicommon
  50. list(REVERSE BROTLIDEC_LIBRARIES)
  51. list(REMOVE_DUPLICATES BROTLIDEC_LIBRARIES)
  52. list(REVERSE BROTLIDEC_LIBRARIES)
  53. set(BROTLI_LIBRARIES ${BROTLIDEC_LIBRARIES})
  54. string(REPLACE ";" " " BROTLI_CFLAGS "${BROTLI_CFLAGS}")
  55. message(STATUS "Found Brotli (via pkg-config): ${BROTLI_INCLUDE_DIRS} (found version \"${BROTLI_VERSION}\")")
  56. else()
  57. find_path(BROTLI_INCLUDE_DIR "brotli/decode.h")
  58. find_library(BROTLICOMMON_LIBRARY NAMES "brotlicommon")
  59. find_library(BROTLIDEC_LIBRARY NAMES "brotlidec")
  60. include(FindPackageHandleStandardArgs)
  61. find_package_handle_standard_args(Brotli
  62. REQUIRED_VARS
  63. BROTLI_INCLUDE_DIR
  64. BROTLIDEC_LIBRARY
  65. BROTLICOMMON_LIBRARY
  66. )
  67. if(BROTLI_FOUND)
  68. set(BROTLI_INCLUDE_DIRS ${BROTLI_INCLUDE_DIR})
  69. set(BROTLI_LIBRARIES ${BROTLIDEC_LIBRARY} ${BROTLICOMMON_LIBRARY})
  70. endif()
  71. mark_as_advanced(BROTLI_INCLUDE_DIR BROTLIDEC_LIBRARY BROTLICOMMON_LIBRARY)
  72. endif()