GN: ft and fc as optionals

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2292613002

Review-Url: https://codereview.chromium.org/2292613002
diff --git a/BUILD.gn b/BUILD.gn
index 02cb350..6b761f0 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -7,6 +7,8 @@
   skia_enable_tools = !is_fuchsia && !is_component_build
 
   skia_use_expat = true
+  skia_use_fontconfig = is_linux
+  skia_use_freetype = is_android || is_linux
   skia_use_giflib = !is_fuchsia
   skia_use_libjpeg_turbo = true
   skia_use_libpng = true
@@ -246,6 +248,23 @@
   }
 }
 
+optional("fontmgr_fontconfig") {
+  enabled = skia_use_freetype && skia_use_fontconfig
+  public_defines = []
+
+  deps = [
+    "//third_party:fontconfig",
+    "//third_party/freetype2",
+  ]
+  sources = [
+    "src/ports/SkFontConfigInterface_direct.cpp",
+    "src/ports/SkFontConfigInterface_direct_factory.cpp",
+    "src/ports/SkFontMgr_FontConfigInterface.cpp",
+    "src/ports/SkFontMgr_fontconfig.cpp",
+    "src/ports/SkFontMgr_fontconfig_factory.cpp",
+  ]
+}
+
 optional("gif") {
   enabled = skia_use_giflib
   public_defines = [ "SK_HAS_GIF_LIBRARY" ]
@@ -303,6 +322,19 @@
   ]
 }
 
+optional("typeface_freetype") {
+  enabled = skia_use_freetype
+  public_defines = []
+
+  deps = [
+    "//third_party/freetype2",
+  ]
+  sources = [
+    "src/ports/SkFontHost_FreeType.cpp",
+    "src/ports/SkFontHost_FreeType_common.cpp",
+  ]
+}
+
 optional("webp") {
   enabled = skia_use_libwebp
   public_defines = [ "SK_HAS_WEBP_LIBRARY" ]
@@ -341,6 +373,7 @@
     ":avx",
     ":crc32",
     ":dsp",
+    ":fontmgr_fontconfig",
     ":gif",
     ":jpeg",
     ":none",
@@ -350,6 +383,7 @@
     ":sse41",
     ":sse42",
     ":ssse3",
+    ":typeface_freetype",
     ":webp",
     ":xml",
   ]
@@ -426,13 +460,10 @@
     deps += [
       "//third_party/cpu-features",
       "//third_party/expat",
-      "//third_party/freetype2",
     ]
     sources += [
       "src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp",
       "src/ports/SkDebug_android.cpp",
-      "src/ports/SkFontHost_FreeType.cpp",
-      "src/ports/SkFontHost_FreeType_common.cpp",
       "src/ports/SkFontMgr_android.cpp",
       "src/ports/SkFontMgr_android_factory.cpp",
       "src/ports/SkFontMgr_android_parser.cpp",
@@ -445,10 +476,6 @@
   }
 
   if (is_linux) {
-    deps += [
-      "third_party:fontconfig",
-      "//third_party/freetype2",
-    ]
     libs += [
       "GL",
       "GLU",
@@ -457,13 +484,6 @@
     sources += [
       "src/gpu/gl/glx/GrGLCreateNativeInterface_glx.cpp",
       "src/ports/SkDebug_stdio.cpp",
-      "src/ports/SkFontConfigInterface_direct.cpp",
-      "src/ports/SkFontConfigInterface_direct_factory.cpp",
-      "src/ports/SkFontHost_FreeType.cpp",
-      "src/ports/SkFontHost_FreeType_common.cpp",
-      "src/ports/SkFontMgr_FontConfigInterface.cpp",
-      "src/ports/SkFontMgr_fontconfig.cpp",
-      "src/ports/SkFontMgr_fontconfig_factory.cpp",
     ]
   }