Commit 3de1b8d0b0983cf49a187a4227e7950395a3b08f

Werner Lemberg 2019-09-05T14:10:01

[cmake] Add brotli support. * CMakeLists.txt (FT_WITH_BROTLI): New option. * builds/cmake/FindBrotliDec.cmake: New file.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 70b88c1..da07ca3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -68,12 +68,14 @@
 # . `CMakeLists.txt' is provided as-is since it is normally not used by the
 #   developer team.
 #
-# . Set the `FT_WITH_ZLIB', `FT_WITH_BZIP2', `FT_WITH_PNG', and
-#   `FT_WITH_HARFBUZZ' CMake variables to `ON' to force using a dependency.
-#   Leave a variable undefined (which is the default) to use the dependency
-#   only if it is available.  Set `CMAKE_DISABLE_FIND_PACKAGE_HarfBuzz=TRUE' to
-#   disable a dependency completely (CMake package name, so `BZip2' instead of
-#   `BZIP2'). Example:
+# . Set the `FT_WITH_ZLIB', `FT_WITH_BZIP2', `FT_WITH_PNG',
+#   `FT_WITH_HARFBUZZ', and `FT_WITH_BROTLI' CMake variables to `ON' to
+#   force using a dependency.  Leave a variable undefined (which is the
+#   default) to use the dependency only if it is available.  Set
+#   `CMAKE_DISABLE_FIND_PACKAGE_XXX=TRUE' to disable a dependency completely
+#   (where `XXX' is a CMake package name like `BZip2').
+#
+#   Example:
 #
 #     cmake -DFT_WITH_ZLIB=ON -DCMAKE_DISABLE_FIND_PACKAGE_HarfBuzz=TRUE [...]
 #
@@ -156,14 +158,15 @@ string(REGEX REPLACE
 math(EXPR LIBRARY_SOVERSION "${LIBTOOL_CURRENT} - ${LIBTOOL_AGE}")
 set(LIBRARY_VERSION "${LIBRARY_SOVERSION}.${LIBTOOL_AGE}.${LIBTOOL_REVISION}")
 
-# These options mean "require x and complain if not found". They'll get
-# optionally found anyway. Use `-DCMAKE_DISABLE_FIND_PACKAGE_x=TRUE` to disable
-# searching for a packge entirely (x is the CMake package name, so "BZip2"
-# instead of "BZIP2").
+# These options mean `require x and complain if not found'.  They'll get
+# optionally found anyway.  Use `-DCMAKE_DISABLE_FIND_PACKAGE_x=TRUE` to
+# disable searching for a package entirely (`x' is the CMake package name,
+# so `BZip2' instead of `BZIP2').
 option(FT_WITH_ZLIB "Use system zlib instead of internal library." OFF)
 option(FT_WITH_BZIP2 "Support bzip2 compressed fonts." OFF)
 option(FT_WITH_PNG "Support PNG compressed OpenType embedded bitmaps." OFF)
 option(FT_WITH_HARFBUZZ "Improve auto-hinting of OpenType fonts." OFF)
+option(FT_WITH_BROTLI "Support compressed WOFF2 fonts." OFF)
 
 
 # Disallow in-source builds
@@ -219,6 +222,12 @@ else ()
   find_package(BZip2)
 endif ()
 
+if (FT_WITH_BROTLI)
+  find_package(BrotliDec REQUIRED)
+else ()
+  find_package(BrotliDec)
+endif ()
+
 # Create the configuration file
 if (UNIX)
   check_include_file("unistd.h" HAVE_UNISTD_H)
@@ -283,6 +292,11 @@ if (HARFBUZZ_FOUND)
     "/\\* +(#define +FT_CONFIG_OPTION_USE_HARFBUZZ) +\\*/" "\\1"
     FTOPTION_H "${FTOPTION_H}")
 endif ()
+if (BROTLIDEC_FOUND)
+  string(REGEX REPLACE
+    "/\\* +(#define +FT_CONFIG_OPTION_USE_BROTLI) +\\*/" "\\1"
+    FTOPTION_H "${FTOPTION_H}")
+endif ()
 
 set(FTOPTION_H_NAME "${PROJECT_BINARY_DIR}/include/freetype/config/ftoption.h")
 if (EXISTS "${FTOPTION_H_NAME}")
@@ -439,6 +453,12 @@ if (HARFBUZZ_FOUND)
   target_include_directories(freetype PRIVATE ${HARFBUZZ_INCLUDE_DIRS})
   list(APPEND PKG_CONFIG_REQUIRED_PRIVATE "harfbuzz >= ${HARFBUZZ_MIN_VERSION}")
 endif ()
+if (BROTLIDEC_FOUND)
+  target_link_libraries(freetype PRIVATE ${BROTLIDEC_LIBRARIES})
+  target_compile_definitions(freetype PRIVATE ${BROTLIDEC_DEFINITIONS})
+  target_include_directories(freetype PRIVATE ${BROTLIDEC_INCLUDE_DIRS})
+  list(APPEND PKG_CONFIG_REQUIRED_PRIVATE "libbrotlidec")
+endif ()
 
 
 # Installation
diff --git a/ChangeLog b/ChangeLog
index 5298252..cb0335a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2019-09-05  Werner Lemberg  <wl@gnu.org>
 
+	[cmake] Add brotli support.
+
+	* CMakeLists.txt (FT_WITH_BROTLI): New option.
+
+	* builds/cmake/FindBrotliDec.cmake: New file.
+
+2019-09-05  Werner Lemberg  <wl@gnu.org>
+
 	Fix handling of `AF_CONFIG_OPTION_INDIC'.
 
 	* devel/ftoption.h, include/freetype/config/ftoption.h:
diff --git a/builds/cmake/FindBrotliDec.cmake b/builds/cmake/FindBrotliDec.cmake
new file mode 100644
index 0000000..b3df17a
--- /dev/null
+++ b/builds/cmake/FindBrotliDec.cmake
@@ -0,0 +1,51 @@
+# FindBrotliDec.cmake
+#
+# Copyright (C) 2019 by
+# David Turner, Robert Wilhelm, and Werner Lemberg.
+#
+# Written by Werner Lemberg <wl@gnu.org>
+#
+# This file is part of the FreeType project, and may only be used, modified,
+# and distributed under the terms of the FreeType project license,
+# LICENSE.TXT.  By continuing to use, modify, or distribute this file you
+# indicate that you have read the license and understand and accept it
+# fully.
+#
+#
+# Try to find libbrotlidec include and library directories.
+#
+# If found, the following variables are set.
+#
+#   BROTLIDEC_INCLUDE_DIRS
+#   BROTLIDEC_LIBRARIES
+
+include(FindPkgConfig)
+pkg_check_modules(PC_BROTLIDEC QUIET libbrotlidec)
+
+if (PC_BROTLIDEC_VERSION)
+  set(BROTLIDEC_VERSION "${PC_BROTLIDEC_VERSION}")
+endif ()
+
+
+find_path(BROTLIDEC_INCLUDE_DIRS
+  NAMES brotli/decode.h
+  HINTS ${PC_BROTLIDEC_INCLUDEDIR}
+        ${PC_BROTLIDEC_INCLUDE_DIRS}
+  PATH_SUFFIXES brotli)
+
+find_library(BROTLIDEC_LIBRARIES
+  NAMES brotlidec
+  HINTS ${PC_BROTLIDEC_LIBDIR}
+        ${PC_BROTLIDEC_LIBRARY_DIRS})
+
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(
+  brotlidec
+  REQUIRED_VARS BROTLIDEC_INCLUDE_DIRS BROTLIDEC_LIBRARIES
+  FOUND_VAR BROTLIDEC_FOUND
+  VERSION_VAR BROTLIDEC_VERSION)
+
+mark_as_advanced(
+  BROTLIDEC_INCLUDE_DIRS
+  BROTLIDEC_LIBRARIES)