Make Skottie's GN setup more DLL friendly

Skottie doesn't currently build with is_component_build=true. Trying to
build a DLL with skia_enable_skottie=false failed, because we ended up
with a component("skottie") that had no sources. That led to fallback
linker behavior, but no DllMain.

To solve this, and simplify things, move the skia_enable_skottie checks
to the outer scope, and simply replace all the referenced components
with empty groups when it's not enabled. Also fix some fm code that was
assuming it was always enabled.

Change-Id: I4a47d80d882e6c557ee14b34255e22e09292cc8c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/207302
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/modules/skottie/BUILD.gn b/modules/skottie/BUILD.gn
index 996b8ef..5ab762b 100644
--- a/modules/skottie/BUILD.gn
+++ b/modules/skottie/BUILD.gn
@@ -9,15 +9,13 @@
   skia_enable_skottie = true
 }
 
-config("public_config") {
-  if (skia_enable_skottie) {
+if (skia_enable_skottie) {
+  config("public_config") {
     defines = [ "SK_ENABLE_SKOTTIE" ]
     include_dirs = [ "include" ]
   }
-}
 
-component("skottie") {
-  if (skia_enable_skottie) {
+  component("skottie") {
     check_includes = false
     import("skottie.gni")
     public_configs = [ ":public_config" ]
@@ -30,15 +28,13 @@
       "../skshaper",
     ]
   }
-}
 
-if (defined(is_skia_standalone)) {
-  config("utils_config") {
-    include_dirs = [ "utils" ]
-  }
-  source_set("utils") {
-    check_includes = false
-    if (skia_enable_skottie) {
+  if (defined(is_skia_standalone)) {
+    config("utils_config") {
+      include_dirs = [ "utils" ]
+    }
+    source_set("utils") {
+      check_includes = false
       testonly = true
 
       public_configs = [ ":utils_config" ]
@@ -51,11 +47,9 @@
         "../..:skia",
       ]
     }
-  }
 
-  if (skia_enable_tools) {
-    source_set("tests") {
-      if (skia_enable_skottie) {
+    if (skia_enable_tools) {
+      source_set("tests") {
         testonly = true
 
         configs += [
@@ -72,10 +66,8 @@
           "../..:skia",
         ]
       }
-    }
 
-    source_set("fuzz") {
-      if (skia_enable_skottie) {
+      source_set("fuzz") {
         check_includes = false
         testonly = true
 
@@ -102,30 +94,28 @@
           ":skottie",
         ]
       }
-    }
 
-    source_set("tool") {
-      check_includes = false
-      testonly = true
+      source_set("tool") {
+        check_includes = false
+        testonly = true
 
-      configs += [ "../..:skia_private" ]
-      sources = [
-        "src/SkottieTool.cpp",
-      ]
+        configs += [ "../..:skia_private" ]
+        sources = [
+          "src/SkottieTool.cpp",
+        ]
 
-      deps = [
-        "../..:flags",
-        "../..:skia",
-      ]
+        deps = [
+          "../..:flags",
+          "../..:skia",
+        ]
 
-      public_deps = [
-        ":skottie",
-        ":utils",
-      ]
-    }
+        public_deps = [
+          ":skottie",
+          ":utils",
+        ]
+      }
 
-    source_set("gm") {
-      if (skia_enable_skottie) {
+      source_set("gm") {
         check_includes = false
         testonly = true
 
@@ -147,4 +137,15 @@
       }
     }
   }
+} else {
+  group("skottie") {
+  }
+  group("fuzz") {
+  }
+  group("gm") {
+  }
+  group("tests") {
+  }
+  group("utils") {
+  }
 }
diff --git a/tools/fm/fm.cpp b/tools/fm/fm.cpp
index 6e385d4..2a918ab 100644
--- a/tools/fm/fm.cpp
+++ b/tools/fm/fm.cpp
@@ -23,8 +23,6 @@
 #include "SkPictureRecorder.h"
 #include "SkSVGDOM.h"
 #include "SkTHash.h"
-#include "Skottie.h"
-#include "SkottieUtils.h"
 #include "ToolUtils.h"
 #include "gm.h"
 #include <chrono>
@@ -32,6 +30,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#if defined(SK_ENABLE_SKOTTIE)
+    #include "Skottie.h"
+    #include "SkottieUtils.h"
+#endif
+
 using sk_gpu_test::GrContextFactory;
 
 static DEFINE_string2(sources, s, "", "Which GMs, .skps, or images to draw.");
@@ -171,6 +174,7 @@
     };
 }
 
+#if defined(SK_ENABLE_SKOTTIE)
 static void init(Source* source, sk_sp<skottie::Animation> animation) {
     source->size = {1000,1000};
     source->draw = [animation](SkCanvas* canvas) {
@@ -200,7 +204,7 @@
         return ok;
     };
 }
-
+#endif
 
 static sk_sp<SkImage> draw_with_cpu(std::function<bool(SkCanvas*)> draw,
                                     SkImageInfo info) {
@@ -401,7 +405,9 @@
                     init(source, svg);
                     continue;
                 }
-            } else if (name.endsWith(".json")) {
+            }
+#if defined(SK_ENABLE_SKOTTIE)
+            else if (name.endsWith(".json")) {
                 const SkString dir  = SkOSPath::Dirname(name.c_str());
                 if (sk_sp<skottie::Animation> animation = skottie::Animation::Builder()
                         .setResourceProvider(skottie_utils::FileResourceProvider::Make(dir))
@@ -409,7 +415,9 @@
                     init(source, animation);
                     continue;
                 }
-            } else if (std::shared_ptr<SkCodec> codec = SkCodec::MakeFromData(blob)) {
+            }
+#endif
+            else if (std::shared_ptr<SkCodec> codec = SkCodec::MakeFromData(blob)) {
                 init(source, codec);
                 continue;
             }