GN: make libwebp an optional dependency
This will be handy for folks who don't have libwebp, like Fuchsia.
I convinced myself that this is done right by:
- building in all three modes (default and explicitly set both ways);
- looking at verbose Ninja logs to see the presence/lack of SK_HAS_WEBP_LIBRARY;
- running dm -m Codec, which passes with libwebp and segfault without it.
If this is viable, I intend to make all third-party dependencies optional
and follow this pattern. :skia should link and degrade gracefully without
any of //third_party. It's okay for tools to have hard third-party
dependencies; we just need them to get past the `gn gen` stage without them.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2270693004
Review-Url: https://codereview.chromium.org/2270693004
diff --git a/BUILD.gn b/BUILD.gn
index 6b00f45..ccf2e6b 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -4,6 +4,7 @@
# found in the LICENSE file.
declare_args() {
+ skia_use_libwebp = !is_fuchsia
}
skia_public_includes = [
@@ -64,7 +65,6 @@
"SK_HAS_GIF_LIBRARY",
"SK_HAS_JPEG_LIBRARY",
"SK_HAS_PNG_LIBRARY",
- "SK_HAS_WEBP_LIBRARY",
# TODO(halcanary): make this the default; this is the value Android uses.
"SK_SFNTLY_SUBSETTER=\"sample/chromium/font_subsetter.h\"",
@@ -183,16 +183,37 @@
}
}
+if (skia_use_libwebp) {
+ config("webp_config") {
+ defines = [ "SK_HAS_WEBP_LIBRARY" ]
+ }
+ source_set("webp") {
+ configs += skia_library_configs
+ all_dependent_configs = [ ":webp_config" ]
+ deps = [
+ "//third_party/libwebp",
+ ]
+ sources = [
+ "src/codec/SkWebpAdapterCodec.cpp",
+ "src/codec/SkWebpCodec.cpp",
+ "src/images/SkWEBPImageEncoder.cpp",
+ ]
+ }
+} else {
+ source_set("webp") {
+ }
+}
+
component("skia") {
public_configs = [ ":skia_public" ]
configs += skia_library_configs
deps = [
+ ":webp",
"//third_party/expat",
"//third_party/giflib",
"//third_party/libjpeg-turbo:libjpeg",
"//third_party/libpng",
- "//third_party/libwebp",
"//third_party/sfntly",
"//third_party/zlib",
]
@@ -240,15 +261,12 @@
"src/codec/SkSampler.cpp",
"src/codec/SkSwizzler.cpp",
"src/codec/SkWbmpCodec.cpp",
- "src/codec/SkWebpAdapterCodec.cpp",
- "src/codec/SkWebpCodec.cpp",
"src/images/SkImageEncoder.cpp",
"src/images/SkImageEncoder_Factory.cpp",
"src/images/SkJPEGImageEncoder.cpp",
"src/images/SkJPEGWriteUtility.cpp",
"src/images/SkKTXImageEncoder.cpp",
"src/images/SkPNGImageEncoder.cpp",
- "src/images/SkWEBPImageEncoder.cpp",
"src/ports/SkDiscardableMemory_none.cpp",
"src/ports/SkGlobalInitialization_default.cpp",
"src/ports/SkImageGenerator_skia.cpp",