GN: add sources_when_disabled to optional

Also make sources_when_disabled and public_defines optional arguments.
These are the two mechanisms code uses to turn itself off...
probably at most one is ever used per optional.

Update fiddle to not crash when there's no PDF backend.

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

Review-Url: https://codereview.chromium.org/2292343003
diff --git a/BUILD.gn b/BUILD.gn
index 446345b..c86315d 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -239,15 +239,21 @@
 template("optional") {
   if (invoker.enabled) {
     config(target_name + "_public") {
-      defines = invoker.public_defines
+      if (defined(invoker.public_defines)) {
+        defines = invoker.public_defines
+      }
     }
     source_set(target_name) {
-      forward_variables_from(invoker, "*", [ "public_defines" ])
+      forward_variables_from(invoker,
+                             "*",
+                             [
+                               "public_defines",
+                               "sources_when_disabled",
+                             ])
       all_dependent_configs = [ ":" + target_name + "_public" ]
       configs += skia_library_configs
     }
   } else {
-    # If not enabled, a phony empty target that swallows all otherwise unused variables.
     source_set(target_name) {
       forward_variables_from(invoker,
                              "*",
@@ -255,14 +261,18 @@
                                "public_defines",
                                "deps",
                                "sources",
+                               "sources_when_disabled",
                              ])
+      if (defined(invoker.sources_when_disabled)) {
+        sources = invoker.sources_when_disabled
+      }
+      configs += skia_library_configs
     }
   }
 }
 
 optional("fontmgr_android") {
   enabled = fontmgr_android_enabled
-  public_defines = []
 
   deps = [
     "//third_party/expat",
@@ -277,7 +287,6 @@
 
 optional("fontmgr_fontconfig") {
   enabled = skia_use_freetype && skia_use_fontconfig
-  public_defines = []
 
   deps = [
     "//third_party:fontconfig",
@@ -322,16 +331,16 @@
 
 optional("pdf") {
   enabled = skia_use_zlib
-  public_defines = []
 
   deps = [
     "//third_party/zlib",
   ]
   sources = pdf_gypi.sources
+  sources_when_disabled = [ "src/pdf/SkDocument_PDF_None.cpp" ]
 
   if (skia_use_sfntly) {
     deps += [ "//third_party/sfntly" ]
-    public_defines += [ "SK_PDF_USE_SFNTLY" ]
+    public_defines = [ "SK_PDF_USE_SFNTLY" ]
   }
 }
 
@@ -351,7 +360,6 @@
 
 optional("typeface_freetype") {
   enabled = skia_use_freetype
-  public_defines = []
 
   deps = [
     "//third_party/freetype2",
@@ -378,7 +386,6 @@
 
 optional("xml") {
   enabled = skia_use_expat
-  public_defines = []
 
   deps = [
     "//third_party/expat",