Allow configuration of external embedder FreeType

Add a public config to fxfreetype to make includes visible and provide a
freetype_common group as a public dependency on fxcrt. freetype_common
switches between fxfreetype and //build/config/freetype, which gives
embedders the flexibility to configure the source of FreeType.

BUG=chromium:700926

Change-Id: I73ae26979dcf69a419485def23c7a13dffa2a15d
Reviewed-on: https://pdfium-review.googlesource.com/2971
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index 530c760..45253c5 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -5,14 +5,19 @@
 import("//testing/test.gni")
 import("pdfium.gni")
 
+group("freetype_common") {
+  public_deps = []
+  if (pdf_bundle_freetype) {
+    public_deps += [ "third_party:fx_freetype" ]
+  } else {
+    public_deps += [ "//build/config/freetype" ]
+  }
+}
+
 config("pdfium_common_config") {
   cflags = []
   ldflags = []
-  include_dirs = [
-    ".",
-    "third_party/freetype/include",
-    "third_party/freetype/include/freetype",
-  ]
+  include_dirs = [ "." ]
   defines = [
     "OPJ_STATIC",
     "PNG_PREFIX",
@@ -212,12 +217,6 @@
     ]
   }
 
-  if (pdf_bundle_freetype) {
-    deps += [ "third_party:fx_freetype" ]
-  } else {
-    libs += [ "freetype" ]
-  }
-
   if (pdf_is_complete_lib) {
     complete_static_lib = true
   }
@@ -798,6 +797,7 @@
     "third_party:pdfium_base",
   ]
   public_deps = [
+    ":freetype_common",
     "third_party:pdfium_base",
   ]
 
diff --git a/build_overrides/pdfium.gni b/build_overrides/pdfium.gni
index d6bcc85..a8ce2cf 100644
--- a/build_overrides/pdfium.gni
+++ b/build_overrides/pdfium.gni
@@ -12,8 +12,8 @@
 # Default: Without XFA support.
 pdf_enable_xfa_override = false
 
-# Build PDFium either using the bundled FreeType, or using the system FreeType.
-# System FreeType only exists on Linux.
+# Build PDFium either using the bundled FreeType, or using a third-party
+# FreeType, configured by the embedder in //build/config/freetype.
 # Default: Use the bundled FreeType.
 pdf_bundle_freetype_override = true
 
diff --git a/pdfium.gni b/pdfium.gni
index 3626824..1829831 100644
--- a/pdfium.gni
+++ b/pdfium.gni
@@ -7,8 +7,8 @@
 # This file contains PDFium-related build flags.
 
 declare_args() {
-  # Build PDFium either using the bundled FreeType, or using the system
-  # FreeType.
+  # Build PDFium either using the bundled FreeType, or using a third-party
+  # FreeType, configured by the embedder in //build/config/freetype.
   pdf_bundle_freetype = pdf_bundle_freetype_override
 
   # Build PDFium either with or without v8 support.
diff --git a/third_party/BUILD.gn b/third_party/BUILD.gn
index 2055821..a24e99e 100644
--- a/third_party/BUILD.gn
+++ b/third_party/BUILD.gn
@@ -46,12 +46,19 @@
     #
     # ttgload.c casts from unsigned int to unsigned long to void*.
     cflags = [
-        "-Wno-unused-function",
-        "-Wno-int-to-void-pointer-cast",
+      "-Wno-unused-function",
+      "-Wno-int-to-void-pointer-cast",
     ]
   }
 }
 
+config("freetype_public_includes_config") {
+  include_dirs = [
+    "freetype/include",
+    "freetype/src/include",
+  ]
+}
+
 # Tests may link against this even if the production library doesn't,
 # so it needs to be separate from it.
 static_library("fx_freetype") {
@@ -63,6 +70,9 @@
     # Must be after no_chromium_code for warning flags to be ordered correctly.
     ":fx_freetype_warnings",
   ]
+
+  public_configs = [ ":freetype_public_includes_config" ]
+
   defines = [ "FT2_BUILD_LIBRARY" ]
   sources = [
     "freetype/include/freetype/config/ftconfig.h",