Revert "Add SkTypeface::getVariationDesignPosition."
[platform/upstream/libSkiaSharp.git] / BUILD.gn
1 # Copyright 2016 Google Inc.
2 #
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import("gn/android_framework_defines.gni")
7 import("gn/shared_sources.gni")
8
9 if (!defined(is_skia_standalone)) {
10   is_skia_standalone = false
11 }
12
13 declare_args() {
14   skia_use_angle = false
15   skia_use_expat = true
16   skia_use_fontconfig = is_linux
17   skia_use_freetype = is_android || is_fuchsia || is_linux
18   skia_use_gdi = false
19   skia_use_icu = !is_fuchsia && !is_ios && !is_win  # TODO: Windows
20   skia_use_libjpeg_turbo = true
21   skia_use_libpng = true
22   skia_use_libwebp = !is_fuchsia
23   skia_use_lua = false
24   skia_use_mesa = false
25   skia_use_piex = !is_win
26   skia_use_zlib = true
27
28   skia_android_serial = ""
29   skia_enable_android_framework_defines = false
30   skia_enable_discrete_gpu = true
31   skia_enable_effects = true
32   skia_enable_jumper = is_skia_standalone
33   skia_enable_gpu = true
34   skia_enable_pdf = true
35   skia_enable_tools = is_skia_standalone
36   skia_enable_vulkan_debug_layers = is_skia_standalone && is_debug
37   skia_vulkan_sdk = getenv("VULKAN_SDK")
38 }
39 declare_args() {
40   skia_use_dng_sdk =
41       !is_fuchsia && !is_win && skia_use_libjpeg_turbo && skia_use_zlib
42   skia_use_sfntly = skia_use_icu
43
44   if (is_android) {
45     skia_use_vulkan = defined(ndk_api) && ndk_api >= 24
46   } else {
47     skia_use_vulkan = skia_vulkan_sdk != ""
48   }
49 }
50
51 # Our tools require static linking (they use non-exported symbols).
52 skia_enable_tools = skia_enable_tools && !is_component_build
53
54 fontmgr_android_enabled = skia_use_expat && skia_use_freetype
55
56 skia_public_includes = [
57   "include/android",
58   "include/c",
59   "include/codec",
60   "include/config",
61   "include/core",
62   "include/effects",
63   "include/gpu",
64   "include/gpu/gl",
65   "include/pathops",
66   "include/ports",
67   "include/svg",
68   "include/utils",
69   "include/utils/mac",
70 ]
71
72 # Skia public API, generally provided by :skia.
73 config("skia_public") {
74   include_dirs = skia_public_includes
75   defines = []
76   if (is_component_build) {
77     defines += [ "SKIA_DLL" ]
78   }
79   if (is_fuchsia || is_linux) {
80     defines += [ "SK_SAMPLES_FOR_X" ]
81   }
82   if (skia_enable_android_framework_defines) {
83     defines += android_framework_defines
84   }
85   if (!skia_enable_gpu) {
86     defines += [ "SK_SUPPORT_GPU=0" ]
87   }
88 }
89
90 # Skia internal APIs, used by Skia itself and a few test tools.
91 config("skia_private") {
92   visibility = [ ":*" ]
93
94   include_dirs = [
95     "include/private",
96     "src/c",
97     "src/codec",
98     "src/core",
99     "src/effects",
100     "src/effects/gradients",
101     "src/fonts",
102     "src/image",
103     "src/images",
104     "src/lazy",
105     "src/opts",
106     "src/pathops",
107     "src/pdf",
108     "src/ports",
109     "src/sfnt",
110     "src/sksl",
111     "src/utils",
112     "src/utils/win",
113     "src/xml",
114     "third_party/etc1",
115     "third_party/gif",
116   ]
117
118   defines = [
119     "SK_GAMMA_APPLY_TO_A8",
120     "SK_INTERNAL",
121   ]
122   if (is_android) {
123     defines += [
124       "SK_GAMMA_EXPONENT=1.4",
125       "SK_GAMMA_CONTRAST=0.0",
126     ]
127   }
128   if (is_official_build || is_android) {
129     # TODO(bsalomon): it'd be nice to make Android normal.
130     defines += [ "SK_ALLOW_STATIC_GLOBAL_INITIALIZERS=0" ]
131   }
132   libs = []
133   lib_dirs = []
134   if (skia_use_vulkan) {
135     if (skia_vulkan_sdk != "" && !is_android) {
136       if (is_win) {
137         include_dirs += [ "$skia_vulkan_sdk/Include/" ]
138         lib_dirs += [ "$skia_vulkan_sdk/Bin" ]
139       } else {
140         include_dirs += [ "$skia_vulkan_sdk/include/" ]
141         lib_dirs += [ "$skia_vulkan_sdk/lib/" ]
142       }
143     }
144     if (is_win) {
145       libs += [ "vulkan-1.lib" ]
146     } else {
147       libs += [ "vulkan" ]
148     }
149   }
150   if (skia_enable_gpu) {
151     include_dirs += [ "src/gpu" ]
152   }
153   if (skia_use_angle) {
154     defines += [ "SK_ANGLE" ]
155   }
156   if (skia_enable_discrete_gpu) {
157     defines += [ "SK_ENABLE_DISCRETE_GPU" ]
158   }
159 }
160
161 # Any code that's linked into Skia-the-library should use this config via += skia_library_configs.
162 config("skia_library") {
163   visibility = [ ":*" ]
164   defines = [ "SKIA_IMPLEMENTATION=1" ]
165 }
166
167 skia_library_configs = [
168   ":skia_public",
169   ":skia_private",
170   ":skia_library",
171 ]
172
173 # Use for CPU-specific Skia code that needs particular compiler flags.
174 template("opts") {
175   if (invoker.enabled) {
176     source_set(target_name) {
177       forward_variables_from(invoker, "*")
178       configs += skia_library_configs
179     }
180   } else {
181     # If not enabled, a phony empty target that swallows all otherwise unused variables.
182     source_set(target_name) {
183       forward_variables_from(invoker,
184                              "*",
185                              [
186                                "sources",
187                                "cflags",
188                              ])
189     }
190   }
191 }
192
193 is_x86 = current_cpu == "x64" || current_cpu == "x86"
194
195 opts("none") {
196   enabled = !is_x86 && current_cpu != "arm" && current_cpu != "arm64"
197   sources = skia_opts.none_sources
198   cflags = []
199 }
200
201 opts("armv7") {
202   enabled = current_cpu == "arm"
203   sources = skia_opts.armv7_sources + skia_opts.neon_sources
204   cflags = []
205 }
206
207 opts("arm64") {
208   enabled = current_cpu == "arm64"
209   sources = skia_opts.arm64_sources
210   cflags = []
211 }
212
213 opts("crc32") {
214   enabled = current_cpu == "arm64"
215   sources = skia_opts.crc32_sources
216   cflags = [ "-march=armv8-a+crc" ]
217 }
218
219 opts("sse2") {
220   enabled = is_x86
221   sources = skia_opts.sse2_sources
222   if (is_win) {
223     defines = [ "SK_CPU_SSE_LEVEL=SK_CPU_SSE_LEVEL_SSE2" ]
224   } else {
225     cflags = [ "-msse2" ]
226   }
227 }
228
229 opts("ssse3") {
230   enabled = is_x86
231   sources = skia_opts.ssse3_sources
232   if (is_win) {
233     defines = [ "SK_CPU_SSE_LEVEL=SK_CPU_SSE_LEVEL_SSSE3" ]
234   } else {
235     cflags = [ "-mssse3" ]
236   }
237 }
238
239 opts("sse41") {
240   enabled = is_x86
241   sources = skia_opts.sse41_sources
242   if (is_win) {
243     defines = [ "SK_CPU_SSE_LEVEL=SK_CPU_SSE_LEVEL_SSE41" ]
244   } else {
245     cflags = [ "-msse4.1" ]
246   }
247 }
248
249 opts("sse42") {
250   enabled = is_x86
251   sources = skia_opts.sse42_sources
252   if (is_win) {
253     defines = [ "SK_CPU_SSE_LEVEL=SK_CPU_SSE_LEVEL_SSE42" ]
254   } else {
255     cflags = [ "-msse4.2" ]
256   }
257 }
258
259 opts("avx") {
260   enabled = is_x86
261   sources = skia_opts.avx_sources
262   if (is_win) {
263     cflags = [ "/arch:AVX" ]
264   } else {
265     cflags = [ "-mavx" ]
266   }
267 }
268
269 opts("hsw") {
270   enabled = is_x86
271   sources = skia_opts.hsw_sources
272   if (is_win) {
273     cflags = [ "/arch:AVX2" ]
274   } else {
275     cflags = [
276       "-mavx2",
277       "-mbmi",
278       "-mbmi2",
279       "-mf16c",
280       "-mfma",
281     ]
282   }
283 }
284
285 # Any feature of Skia that requires third-party code should be optional and use this template.
286 template("optional") {
287   if (invoker.enabled) {
288     config(target_name + "_public") {
289       if (defined(invoker.public_defines)) {
290         defines = invoker.public_defines
291       }
292     }
293     source_set(target_name) {
294       forward_variables_from(invoker,
295                              "*",
296                              [
297                                "public_defines",
298                                "sources_when_disabled",
299                                "configs_to_remove",
300                              ])
301       all_dependent_configs = [ ":" + target_name + "_public" ]
302       configs += skia_library_configs
303       if (defined(invoker.configs_to_remove)) {
304         configs -= invoker.configs_to_remove
305       }
306     }
307   } else {
308     source_set(target_name) {
309       forward_variables_from(invoker,
310                              "*",
311                              [
312                                "public_defines",
313                                "deps",
314                                "libs",
315                                "sources",
316                                "sources_when_disabled",
317                                "configs_to_remove",
318                              ])
319       if (defined(invoker.sources_when_disabled)) {
320         sources = invoker.sources_when_disabled
321       }
322       configs += skia_library_configs
323     }
324   }
325 }
326
327 optional("effects") {
328   enabled = skia_enable_effects
329   sources =
330       skia_effects_sources + [ "src/ports/SkGlobalInitialization_default.cpp" ]
331   sources_when_disabled = [ "src/ports/SkGlobalInitialization_none.cpp" ]
332 }
333
334 optional("fontmgr_android") {
335   enabled = fontmgr_android_enabled
336
337   deps = [
338     "//third_party/expat",
339     "//third_party/freetype2",
340   ]
341   sources = [
342     "src/ports/SkFontMgr_android.cpp",
343     "src/ports/SkFontMgr_android_factory.cpp",
344     "src/ports/SkFontMgr_android_parser.cpp",
345   ]
346 }
347
348 optional("fontmgr_custom") {
349   enabled = is_linux && skia_use_freetype && !skia_use_fontconfig
350
351   deps = [
352     "//third_party/freetype2",
353   ]
354   sources = [
355     "src/ports/SkFontMgr_custom.cpp",
356     "src/ports/SkFontMgr_custom.h",
357     "src/ports/SkFontMgr_custom_directory.cpp",
358     "src/ports/SkFontMgr_custom_directory_factory.cpp",
359     "src/ports/SkFontMgr_custom_embedded.cpp",
360     "src/ports/SkFontMgr_custom_empty.cpp",
361   ]
362 }
363
364 optional("fontmgr_fontconfig") {
365   enabled = skia_use_freetype && skia_use_fontconfig
366
367   deps = [
368     "//third_party:fontconfig",
369     "//third_party/freetype2",
370   ]
371   sources = [
372     "src/ports/SkFontConfigInterface.cpp",
373     "src/ports/SkFontConfigInterface_direct.cpp",
374     "src/ports/SkFontConfigInterface_direct_factory.cpp",
375     "src/ports/SkFontMgr_FontConfigInterface.cpp",
376     "src/ports/SkFontMgr_fontconfig.cpp",
377     "src/ports/SkFontMgr_fontconfig_factory.cpp",
378   ]
379 }
380
381 optional("fontmgr_fuchsia") {
382   enabled = is_fuchsia && skia_use_freetype
383
384   deps = [
385     "//third_party/freetype2",
386   ]
387   sources = [
388     "src/ports/SkFontMgr_custom.cpp",
389     "src/ports/SkFontMgr_custom_empty.cpp",
390     "src/ports/SkFontMgr_custom_empty_factory.cpp",
391   ]
392 }
393
394 optional("gpu") {
395   enabled = skia_enable_gpu
396   public_defines = []
397
398   sources = skia_gpu_sources + skia_sksl_sources +
399             [ "src/gpu/gl/GrGLDefaultInterface_native.cpp" ]
400
401   # These paths need to be absolute to match the ones produced by shared_sources.gni.
402   sources -= get_path_info([
403                              "src/gpu/gl/GrGLCreateNativeInterface_none.cpp",
404                              "src/gpu/gl/GrGLDefaultInterface_none.cpp",
405                            ],
406                            "abspath")
407   libs = []
408   if (is_android) {
409     sources += [ "src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp" ]
410   } else if (is_linux) {
411     sources += [ "src/gpu/gl/glx/GrGLCreateNativeInterface_glx.cpp" ]
412     libs += [
413       "GL",
414       "GLU",
415     ]
416   } else if (is_mac) {
417     sources += [ "src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp" ]
418   } else if (is_ios) {
419     sources += [ "src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp" ]
420   } else if (is_win) {
421     sources += [ "src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp" ]
422     libs += [ "OpenGL32.lib" ]
423   } else {
424     sources += [ "src/gpu/gl/GrGLCreateNativeInterface_none.cpp" ]
425   }
426
427   if (skia_use_vulkan) {
428     public_defines += [ "SK_VULKAN" ]
429     sources += skia_vk_sources
430     if (skia_enable_vulkan_debug_layers) {
431       public_defines += [ "SK_ENABLE_VK_LAYERS" ]
432     }
433   }
434 }
435
436 optional("jpeg") {
437   enabled = skia_use_libjpeg_turbo
438   public_defines = [ "SK_HAS_JPEG_LIBRARY" ]
439
440   deps = [
441     "//third_party/libjpeg-turbo:libjpeg",
442   ]
443   sources = [
444     "src/codec/SkJpegCodec.cpp",
445     "src/codec/SkJpegDecoderMgr.cpp",
446     "src/codec/SkJpegUtility.cpp",
447     "src/images/SkJPEGImageEncoder.cpp",
448     "src/images/SkJPEGWriteUtility.cpp",
449   ]
450 }
451
452 optional("pdf") {
453   enabled = skia_use_zlib && skia_enable_pdf
454   public_defines = [ "SK_SUPPORT_PDF" ]
455
456   deps = [
457     "//third_party/zlib",
458   ]
459   sources = skia_pdf_sources
460   sources_when_disabled = [ "src/pdf/SkDocument_PDF_None.cpp" ]
461
462   if (skia_use_sfntly) {
463     deps += [ "//third_party/sfntly" ]
464     public_defines += [ "SK_PDF_USE_SFNTLY" ]
465   }
466 }
467
468 optional("png") {
469   enabled = skia_use_libpng
470   public_defines = [ "SK_HAS_PNG_LIBRARY" ]
471
472   deps = [
473     "//third_party/libpng",
474   ]
475   sources = [
476     "src/codec/SkIcoCodec.cpp",
477     "src/codec/SkPngCodec.cpp",
478     "src/images/SkPNGImageEncoder.cpp",
479   ]
480 }
481
482 optional("raw") {
483   enabled = skia_use_dng_sdk && skia_use_libjpeg_turbo && skia_use_piex
484   public_defines = [ "SK_CODEC_DECODES_RAW" ]
485
486   deps = [
487     "//third_party/dng_sdk",
488     "//third_party/libjpeg-turbo:libjpeg",
489     "//third_party/piex",
490   ]
491
492   # SkRawCodec catches any exceptions thrown by dng_sdk, insulating the rest of
493   # Skia.
494   configs_to_remove = [ "//gn:no_exceptions" ]
495
496   sources = [
497     "src/codec/SkRawAdapterCodec.cpp",
498     "src/codec/SkRawCodec.cpp",
499   ]
500 }
501
502 optional("jumper") {
503   enabled = skia_enable_jumper
504   public_defines = [ "SK_JUMPER" ]
505   sources = [
506     "src/jumper/SkJumper.cpp",
507     "src/jumper/SkJumper_stages.cpp",
508   ]
509   if (is_win && target_cpu == "x64") {
510     sources += [ "src/jumper/SkJumper_generated_win.S" ]
511   } else if (!is_win) {
512     sources += [ "src/jumper/SkJumper_generated.S" ]
513   }
514 }
515
516 optional("typeface_freetype") {
517   enabled = skia_use_freetype
518
519   deps = [
520     "//third_party/freetype2",
521   ]
522   sources = [
523     "src/ports/SkFontHost_FreeType.cpp",
524     "src/ports/SkFontHost_FreeType_common.cpp",
525   ]
526 }
527
528 optional("webp") {
529   enabled = skia_use_libwebp
530   public_defines = [ "SK_HAS_WEBP_LIBRARY" ]
531
532   deps = [
533     "//third_party/libwebp",
534   ]
535   sources = [
536     "src/codec/SkWebpAdapterCodec.cpp",
537     "src/codec/SkWebpCodec.cpp",
538     "src/images/SkWEBPImageEncoder.cpp",
539   ]
540 }
541
542 optional("xml") {
543   enabled = skia_use_expat
544   public_defines = [ "SK_XML" ]
545
546   deps = [
547     "//third_party/expat",
548   ]
549   sources = [
550     "src/svg/SkSVGCanvas.cpp",
551     "src/svg/SkSVGDevice.cpp",
552     "src/xml/SkDOM.cpp",
553     "src/xml/SkXMLParser.cpp",
554     "src/xml/SkXMLWriter.cpp",
555   ]
556 }
557
558 component("skia") {
559   public_configs = [ ":skia_public" ]
560   configs += skia_library_configs
561
562   deps = [
563     ":arm64",
564     ":armv7",
565     ":avx",
566     ":crc32",
567     ":effects",
568     ":fontmgr_android",
569     ":fontmgr_custom",
570     ":fontmgr_fontconfig",
571     ":fontmgr_fuchsia",
572     ":gpu",
573     ":hsw",
574     ":jpeg",
575     ":jumper",
576     ":none",
577     ":pdf",
578     ":png",
579     ":raw",
580     ":sse2",
581     ":sse41",
582     ":sse42",
583     ":ssse3",
584     ":typeface_freetype",
585     ":webp",
586     ":xml",
587   ]
588
589   # This file (and all GN files in Skia) are designed to work with an
590   # empty sources assignment filter; we handle all that explicitly.
591   # We clear the filter here for clients who may have set up a global filter.
592   set_sources_assignment_filter([])
593
594   sources = []
595   sources += skia_core_sources
596   sources += skia_utils_sources
597   sources += skia_xps_sources
598   sources += [
599     "src/android/SkBitmapRegionCodec.cpp",
600     "src/android/SkBitmapRegionDecoder.cpp",
601     "src/codec/SkAndroidCodec.cpp",
602     "src/codec/SkBmpCodec.cpp",
603     "src/codec/SkBmpMaskCodec.cpp",
604     "src/codec/SkBmpRLECodec.cpp",
605     "src/codec/SkBmpStandardCodec.cpp",
606     "src/codec/SkCodec.cpp",
607     "src/codec/SkCodecImageGenerator.cpp",
608     "src/codec/SkGifCodec.cpp",
609     "src/codec/SkMaskSwizzler.cpp",
610     "src/codec/SkMasks.cpp",
611     "src/codec/SkSampledCodec.cpp",
612     "src/codec/SkSampler.cpp",
613     "src/codec/SkStreamBuffer.cpp",
614     "src/codec/SkSwizzler.cpp",
615     "src/codec/SkWbmpCodec.cpp",
616     "src/images/SkImageEncoder.cpp",
617     "src/ports/SkDiscardableMemory_none.cpp",
618     "src/ports/SkImageGenerator_skia.cpp",
619     "src/ports/SkMemory_malloc.cpp",
620     "src/ports/SkOSFile_stdio.cpp",
621     "src/sfnt/SkOTTable_name.cpp",
622     "src/sfnt/SkOTUtils.cpp",
623     "src/utils/mac/SkStream_mac.cpp",
624     "third_party/etc1/etc1.cpp",
625     "third_party/gif/SkGifImageReader.cpp",
626   ]
627
628   libs = []
629
630   if (is_win) {
631     sources += [
632       "src/fonts/SkFontMgr_indirect.cpp",
633       "src/ports/SkDebug_win.cpp",
634       "src/ports/SkFontHost_win.cpp",
635       "src/ports/SkFontMgr_win_dw.cpp",
636       "src/ports/SkImageEncoder_WIC.cpp",
637       "src/ports/SkImageGeneratorWIC.cpp",
638       "src/ports/SkOSFile_win.cpp",
639       "src/ports/SkOSLibrary_win.cpp",
640       "src/ports/SkScalerContext_win_dw.cpp",
641       "src/ports/SkTLS_win.cpp",
642       "src/ports/SkTypeface_win_dw.cpp",
643     ]
644     if (skia_use_gdi) {
645       sources += [ "src/ports/SkFontMgr_win_gdi_factory.cpp" ]
646       libs += [
647         "Gdi32.lib",
648         "Usp10.lib",
649       ]
650     } else {
651       sources += [ "src/ports/SkFontMgr_win_dw_factory.cpp" ]
652     }
653     sources -=
654         [ get_path_info("src/utils/SkThreadUtils_pthread.cpp", "abspath") ]
655     libs += [
656       "FontSub.lib",
657       "Ole32.lib",
658       "OleAut32.lib",
659       "User32.lib",
660     ]
661   } else {
662     sources += [
663       "src/ports/SkOSFile_posix.cpp",
664       "src/ports/SkOSLibrary_posix.cpp",
665       "src/ports/SkTLS_pthread.cpp",
666     ]
667   }
668
669   if (is_android) {
670     deps += [ "//third_party/expat" ]
671     if (is_skia_standalone && ndk != "") {
672       deps += [ "//third_party/cpu-features" ]
673     }
674     sources += [ "src/ports/SkDebug_android.cpp" ]
675     libs += [
676       "EGL",
677       "GLESv2",
678       "log",
679     ]
680   }
681
682   if (is_linux) {
683     sources += [ "src/ports/SkDebug_stdio.cpp" ]
684   }
685
686   if (is_mac) {
687     sources += [
688       "src/ports/SkDebug_stdio.cpp",
689       "src/ports/SkFontHost_mac.cpp",
690       "src/ports/SkImageEncoder_CG.cpp",
691       "src/ports/SkImageGeneratorCG.cpp",
692     ]
693     libs += [
694       "ApplicationServices.framework",
695       "OpenGL.framework",
696     ]
697   }
698
699   if (is_ios) {
700     sources += [
701       "src/ports/SkDebug_stdio.cpp",
702       "src/ports/SkFontHost_mac.cpp",
703       "src/ports/SkImageEncoder_CG.cpp",
704       "src/ports/SkImageGeneratorCG.cpp",
705     ]
706     libs += [
707       "CoreFoundation.framework",
708       "CoreGraphics.framework",
709       "CoreText.framework",
710       "ImageIO.framework",
711       "MobileCoreServices.framework",
712     ]
713   }
714
715   if (is_fuchsia) {
716     sources += [ "src/ports/SkDebug_stdio.cpp" ]
717   }
718 }
719
720 # Targets guarded by skia_enable_tools may use //third_party freely.
721 if (skia_enable_tools) {
722   # Used by gn_to_bp.py to list our public include dirs.
723   source_set("public") {
724     configs += [ ":skia_public" ]
725   }
726
727   config("skia.h_config") {
728     include_dirs = [ "$target_gen_dir" ]
729   }
730   action("skia.h") {
731     public_configs = [ ":skia.h_config" ]
732     skia_h = "$target_gen_dir/skia.h"
733     script = "gn/find_headers.py"
734     args = [ rebase_path(skia_h, root_build_dir) ] +
735            rebase_path(skia_public_includes)
736     depfile = "$skia_h.deps"
737     outputs = [
738       skia_h,
739     ]
740   }
741
742   if (skia_enable_gpu && target_cpu == "x64") {
743     # Our bots only have 64-bit libOSMesa installed.
744     # TODO: worth fixing?
745     executable("fiddle") {
746       libs = []
747       if (is_linux) {
748         libs += [ "OSMesa" ]
749       }
750
751       sources = [
752         "tools/fiddle/draw.cpp",
753         "tools/fiddle/fiddle_main.cpp",
754       ]
755       deps = [
756         ":skia",
757         ":skia.h",
758       ]
759     }
760   }
761
762   if (skia_enable_gpu) {
763     source_set("public_headers_warnings_check") {
764       sources = [
765         "tools/public_headers_warnings_check.cpp",
766       ]
767       configs -= [ "//gn:warnings_except_public_headers" ]
768       deps = [
769         ":skia",
770         ":skia.h",
771       ]
772     }
773   }
774
775   template("test_lib") {
776     config(target_name + "_config") {
777       include_dirs = invoker.public_include_dirs
778       if (defined(invoker.public_defines)) {
779         defines = invoker.public_defines
780       }
781     }
782     source_set(target_name) {
783       forward_variables_from(invoker, "*", [ "public_include_dirs" ])
784       public_configs = [
785         ":" + target_name + "_config",
786         ":skia_private",
787       ]
788
789       if (!defined(deps)) {
790         deps = []
791       }
792       deps += [ ":skia" ]
793       testonly = true
794     }
795   }
796
797   template("test_app") {
798     if (defined(invoker.is_shared_library) && invoker.is_shared_library) {
799       shared_library("lib" + target_name) {
800         forward_variables_from(invoker, "*", [ "is_shared_library" ])
801         testonly = true
802       }
803     } else {
804       _executable = target_name
805       executable(_executable) {
806         forward_variables_from(invoker, "*", [ "is_shared_library" ])
807         testonly = true
808       }
809     }
810     if (is_android && skia_android_serial != "" && defined(_executable)) {
811       action("push_" + target_name) {
812         script = "gn/push_to_android.py"
813         deps = [
814           ":" + _executable,
815         ]
816         _stamp = "$target_gen_dir/$_executable.pushed_$skia_android_serial"
817         outputs = [
818           _stamp,
819         ]
820         args = [
821           rebase_path("$root_build_dir/$_executable"),
822           skia_android_serial,
823           rebase_path(_stamp),
824         ]
825         testonly = true
826       }
827     }
828   }
829
830   test_lib("gpu_tool_utils") {
831     public_include_dirs = []
832     if (skia_enable_gpu) {
833       public_defines = []
834       public_include_dirs += [ "tools/gpu" ]
835
836       deps = []
837       sources = [
838         "tools/gpu/GrContextFactory.cpp",
839         "tools/gpu/GrTest.cpp",
840         "tools/gpu/TestContext.cpp",
841         "tools/gpu/gl/GLTestContext.cpp",
842         "tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp",
843         "tools/gpu/gl/debug/DebugGLTestContext.cpp",
844         "tools/gpu/gl/debug/GrBufferObj.cpp",
845         "tools/gpu/gl/debug/GrFrameBufferObj.cpp",
846         "tools/gpu/gl/debug/GrProgramObj.cpp",
847         "tools/gpu/gl/debug/GrShaderObj.cpp",
848         "tools/gpu/gl/debug/GrTextureObj.cpp",
849         "tools/gpu/gl/debug/GrTextureUnitObj.cpp",
850         "tools/gpu/gl/null/NullGLTestContext.cpp",
851       ]
852       libs = []
853
854       if (is_android) {
855         sources += [ "tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp" ]
856       } else if (is_ios) {
857         sources += [ "tools/gpu/gl/iOS/CreatePlatformGLTestContext_iOS.mm" ]
858         libs += [ "OpenGLES.framework" ]
859       } else if (is_linux) {
860         sources += [ "tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp" ]
861         libs += [ "X11" ]
862       } else if (is_mac) {
863         sources += [ "tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp" ]
864       } else if (is_win) {
865         sources += [ "tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp" ]
866         libs += [
867           "Gdi32.lib",
868           "OpenGL32.lib",
869         ]
870       }
871
872       if (skia_use_angle) {
873         deps += [ "//third_party/angle2" ]
874         sources += [ "tools/gpu/gl/angle/GLTestContext_angle.cpp" ]
875       }
876       if (skia_use_mesa) {
877         public_defines += [ "SK_MESA" ]
878         sources += [ "tools/gpu/gl/mesa/GLTestContext_mesa.cpp" ]
879         libs += [ "OSMesa" ]
880       }
881       if (skia_use_vulkan) {
882         sources += [ "tools/gpu/vk/VkTestContext.cpp" ]
883       }
884     }
885   }
886
887   test_lib("flags") {
888     public_include_dirs = [ "tools/flags" ]
889     sources = [
890       "tools/flags/SkCommandLineFlags.cpp",
891     ]
892   }
893   test_lib("common_flags") {
894     public_include_dirs = [ "tools/flags" ]
895     sources = [
896       "tools/flags/SkCommonFlags.cpp",
897       "tools/flags/SkCommonFlagsConfig.cpp",
898     ]
899     deps = [
900       ":flags",
901       ":gpu_tool_utils",
902     ]
903   }
904
905   test_lib("tool_utils") {
906     public_include_dirs = [
907       "tools",
908       "tools/debugger",
909       "tools/timer",
910     ]
911     sources = [
912       "src/utils/SkMultiPictureDocumentReader.cpp",  # TODO(halcanary): move to tools?
913       "tools/AndroidSkDebugToStdOut.cpp",
914       "tools/CrashHandler.cpp",
915       "tools/LsanSuppressions.cpp",
916       "tools/ProcStats.cpp",
917       "tools/Resources.cpp",
918       "tools/ThermalManager.cpp",
919       "tools/UrlDataManager.cpp",
920       "tools/debugger/SkDebugCanvas.cpp",
921       "tools/debugger/SkDrawCommand.cpp",
922       "tools/debugger/SkJsonWriteBuffer.cpp",
923       "tools/debugger/SkObjectParser.cpp",
924       "tools/picture_utils.cpp",
925       "tools/random_parse_path.cpp",
926       "tools/sk_tool_utils.cpp",
927       "tools/sk_tool_utils_font.cpp",
928       "tools/timer/Timer.cpp",
929     ]
930     libs = []
931     if (is_ios) {
932       sources += [ "tools/ios_utils.m" ]
933       libs += [ "Foundation.framework" ]
934     }
935     deps = [
936       ":common_flags",
937       ":flags",
938       "//third_party/libpng",
939     ]
940     public_deps = [
941       "//third_party/jsoncpp",
942     ]
943   }
944
945   import("gn/gm.gni")
946   test_lib("gm") {
947     public_include_dirs = [ "gm" ]
948     sources = gm_sources
949     deps = [
950       ":flags",
951       ":gpu_tool_utils",
952       ":skia",
953       ":tool_utils",
954     ]
955   }
956
957   import("gn/tests.gni")
958   test_lib("tests") {
959     public_include_dirs = [ "tests" ]
960     sources = tests_sources + pathops_tests_sources
961     if (!fontmgr_android_enabled) {
962       sources -= [ "//tests/FontMgrAndroidParserTest.cpp" ]
963     }
964     deps = [
965       ":experimental_svg_model",
966       ":flags",
967       ":gpu_tool_utils",
968       ":skia",
969       ":tool_utils",
970       "//third_party/libpng",
971       "//third_party/zlib",
972     ]
973   }
974
975   import("gn/bench.gni")
976   test_lib("bench") {
977     public_include_dirs = [ "bench" ]
978     sources = bench_sources
979     deps = [
980       ":flags",
981       ":gm",
982       ":gpu_tool_utils",
983       ":skia",
984       ":tool_utils",
985     ]
986   }
987
988   test_lib("experimental_svg_model") {
989     public_include_dirs = [ "experimental/svg/model" ]
990     sources = [
991       "experimental/svg/model/SkSVGAttribute.cpp",
992       "experimental/svg/model/SkSVGAttributeParser.cpp",
993       "experimental/svg/model/SkSVGCircle.cpp",
994       "experimental/svg/model/SkSVGClipPath.cpp",
995       "experimental/svg/model/SkSVGContainer.cpp",
996       "experimental/svg/model/SkSVGDOM.cpp",
997       "experimental/svg/model/SkSVGEllipse.cpp",
998       "experimental/svg/model/SkSVGLine.cpp",
999       "experimental/svg/model/SkSVGLinearGradient.cpp",
1000       "experimental/svg/model/SkSVGNode.cpp",
1001       "experimental/svg/model/SkSVGPath.cpp",
1002       "experimental/svg/model/SkSVGPoly.cpp",
1003       "experimental/svg/model/SkSVGRect.cpp",
1004       "experimental/svg/model/SkSVGRenderContext.cpp",
1005       "experimental/svg/model/SkSVGSVG.cpp",
1006       "experimental/svg/model/SkSVGShape.cpp",
1007       "experimental/svg/model/SkSVGStop.cpp",
1008       "experimental/svg/model/SkSVGTransformableNode.cpp",
1009       "experimental/svg/model/SkSVGValue.cpp",
1010     ]
1011     deps = [
1012       ":skia",
1013     ]
1014   }
1015
1016   test_lib("views") {
1017     public_include_dirs = [ "include/views" ]
1018     sources = [
1019       "src/views/SkEvent.cpp",
1020       "src/views/SkEventSink.cpp",
1021       "src/views/SkOSMenu.cpp",
1022       "src/views/SkTagList.cpp",
1023       "src/views/SkTouchGesture.cpp",
1024       "src/views/SkView.cpp",
1025       "src/views/SkViewPriv.cpp",
1026     ]
1027     libs = []
1028     deps = []
1029     if (!is_android) {
1030       sources += [ "src/views/SkWindow.cpp" ]
1031     }
1032     if (is_linux) {
1033       public_include_dirs += [ "src/views/unix" ]
1034       sources += [
1035         "src/views/unix/SkOSWindow_Unix.cpp",
1036         "src/views/unix/keysym2ucs.c",
1037       ]
1038       libs += [
1039         "GL",
1040         "X11",
1041       ]
1042     } else if (is_mac) {
1043       sources += [
1044         "src/views/mac/SkEventNotifier.mm",
1045         "src/views/mac/SkNSView.mm",
1046         "src/views/mac/SkOSWindow_Mac.mm",
1047         "src/views/mac/SkTextFieldCell.m",
1048       ]
1049       libs += [
1050         "QuartzCore.framework",
1051         "Cocoa.framework",
1052         "Foundation.framework",
1053       ]
1054     } else if (is_win) {
1055       sources += [ "src/views/win/SkOSWindow_win.cpp" ]
1056     }
1057     if (skia_use_angle) {
1058       deps += [ "//third_party/angle2" ]
1059     }
1060   }
1061
1062   if (skia_use_lua) {
1063     test_lib("lua") {
1064       public_include_dirs = []
1065       sources = [
1066         "src/utils/SkLua.cpp",
1067         "src/utils/SkLuaCanvas.cpp",
1068       ]
1069       deps = [
1070         "//third_party/lua",
1071       ]
1072     }
1073
1074     test_app("lua_app") {
1075       sources = [
1076         "tools/lua/lua_app.cpp",
1077       ]
1078       deps = [
1079         ":lua",
1080         ":skia",
1081         "//third_party/lua",
1082       ]
1083     }
1084
1085     test_app("lua_pictures") {
1086       sources = [
1087         "tools/lua/lua_pictures.cpp",
1088       ]
1089       deps = [
1090         ":flags",
1091         ":lua",
1092         ":skia",
1093         ":tool_utils",
1094         "//third_party/lua",
1095       ]
1096     }
1097   }
1098
1099   import("gn/samples.gni")
1100   test_lib("samples") {
1101     public_include_dirs = [ "samplecode" ]
1102     include_dirs = [ "experimental" ]
1103     sources = samples_sources + [
1104                 "experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp",
1105                 "experimental/SkSetPoly3To3.cpp",
1106                 "experimental/SkSetPoly3To3_A.cpp",
1107                 "experimental/SkSetPoly3To3_D.cpp",
1108               ]
1109     deps = [
1110       ":experimental_svg_model",
1111       ":gm",
1112       ":tool_utils",
1113       ":views",
1114       ":xml",
1115     ]
1116
1117     if (skia_use_lua) {
1118       sources += [ "samplecode/SampleLua.cpp" ]
1119       deps += [
1120         ":lua",
1121         "//third_party/lua",
1122       ]
1123     }
1124   }
1125
1126   test_app("dm") {
1127     sources = [
1128       "dm/DM.cpp",
1129       "dm/DMJsonWriter.cpp",
1130       "dm/DMSrcSink.cpp",
1131     ]
1132     include_dirs = [ "tests" ]
1133     deps = [
1134       ":common_flags",
1135       ":experimental_svg_model",
1136       ":flags",
1137       ":gm",
1138       ":gpu_tool_utils",
1139       ":skia",
1140       ":tests",
1141       ":tool_utils",
1142       "//third_party/jsoncpp",
1143       "//third_party/libpng",
1144     ]
1145   }
1146
1147   if (!is_debug) {  # I've benchmarked debug code once too many times...
1148     test_app("monobench") {
1149       sources = [
1150         "tools/monobench.cpp",
1151       ]
1152       deps = [
1153         ":bench",
1154         ":skia",
1155       ]
1156     }
1157   }
1158
1159   test_app("nanobench") {
1160     sources = [
1161       "bench/nanobench.cpp",
1162     ]
1163     deps = [
1164       ":bench",
1165       ":common_flags",
1166       ":experimental_svg_model",
1167       ":flags",
1168       ":gm",
1169       ":gpu_tool_utils",
1170       ":skia",
1171       ":tool_utils",
1172       "//third_party/jsoncpp",
1173     ]
1174   }
1175
1176   test_app("skpinfo") {
1177     sources = [
1178       "tools/skpinfo.cpp",
1179     ]
1180     deps = [
1181       ":flags",
1182       ":skia",
1183     ]
1184   }
1185
1186   if (is_linux || is_win || is_mac) {
1187     test_app("SampleApp") {
1188       sources = [
1189         "samplecode/SampleApp.cpp",
1190         "samplecode/SamplePictFile.cpp",
1191       ]
1192       if (is_mac) {
1193         sources += [ "src/views/mac/skia_mac.mm" ]
1194       } else if (is_win) {
1195         sources += [ "src/views/win/skia_win.cpp" ]
1196       } else if (is_linux) {
1197         sources += [ "src/views/unix/skia_unix.cpp" ]
1198       }
1199       deps = [
1200         ":flags",
1201         ":gm",
1202         ":gpu_tool_utils",
1203         ":samples",
1204         ":skia",
1205         ":tool_utils",
1206         ":views",
1207       ]
1208       if (skia_use_angle) {
1209         deps += [ "//third_party/angle2" ]
1210       }
1211     }
1212   }
1213
1214   if (skia_enable_gpu) {
1215     test_app("skpbench") {
1216       sources = [
1217         "tools/skpbench/skpbench.cpp",
1218       ]
1219       deps = [
1220         ":flags",
1221         ":gpu_tool_utils",
1222         ":skia",
1223         ":tool_utils",
1224       ]
1225     }
1226   }
1227
1228   # We can't yet build ICU on iOS or Windows.
1229   if (!is_ios && !is_win) {
1230     test_app("sktexttopdf-hb") {
1231       sources = [
1232         "tools/SkShaper_harfbuzz.cpp",
1233         "tools/using_skia_and_harfbuzz.cpp",
1234       ]
1235       deps = [
1236         ":skia",
1237         "//third_party/harfbuzz",
1238       ]
1239     }
1240   }
1241   test_app("sktexttopdf") {
1242     sources = [
1243       "tools/SkShaper_primitive.cpp",
1244       "tools/using_skia_and_harfbuzz.cpp",
1245     ]
1246     deps = [
1247       ":skia",
1248     ]
1249   }
1250
1251   test_app("get_images_from_skps") {
1252     sources = [
1253       "tools/get_images_from_skps.cpp",
1254     ]
1255     deps = [
1256       ":flags",
1257       ":skia",
1258       "//third_party/jsoncpp",
1259     ]
1260   }
1261
1262   test_app("colorspaceinfo") {
1263     sources = [
1264       "tools/colorspaceinfo.cpp",
1265     ]
1266     deps = [
1267       ":flags",
1268       ":skia",
1269       ":tool_utils",
1270     ]
1271   }
1272
1273   if (!is_ios) {
1274     test_app("skiaserve") {
1275       sources = [
1276         "tools/skiaserve/Request.cpp",
1277         "tools/skiaserve/Response.cpp",
1278         "tools/skiaserve/skiaserve.cpp",
1279         "tools/skiaserve/urlhandlers/BreakHandler.cpp",
1280         "tools/skiaserve/urlhandlers/ClipAlphaHandler.cpp",
1281         "tools/skiaserve/urlhandlers/CmdHandler.cpp",
1282         "tools/skiaserve/urlhandlers/ColorModeHandler.cpp",
1283         "tools/skiaserve/urlhandlers/DataHandler.cpp",
1284         "tools/skiaserve/urlhandlers/DownloadHandler.cpp",
1285         "tools/skiaserve/urlhandlers/EnableGPUHandler.cpp",
1286         "tools/skiaserve/urlhandlers/ImgHandler.cpp",
1287         "tools/skiaserve/urlhandlers/InfoHandler.cpp",
1288         "tools/skiaserve/urlhandlers/OpBoundsHandler.cpp",
1289         "tools/skiaserve/urlhandlers/OpsHandler.cpp",
1290         "tools/skiaserve/urlhandlers/OverdrawHandler.cpp",
1291         "tools/skiaserve/urlhandlers/PostHandler.cpp",
1292         "tools/skiaserve/urlhandlers/QuitHandler.cpp",
1293         "tools/skiaserve/urlhandlers/RootHandler.cpp",
1294       ]
1295       deps = [
1296         ":flags",
1297         ":gpu_tool_utils",
1298         ":skia",
1299         ":tool_utils",
1300         "//third_party/jsoncpp",
1301         "//third_party/libmicrohttpd",
1302         "//third_party/libpng",
1303       ]
1304     }
1305   }
1306
1307   test_app("fuzz") {
1308     sources = [
1309       "fuzz/FilterFuzz.cpp",
1310       "fuzz/FuzzDrawFunctions.cpp",
1311       "fuzz/FuzzGradients.cpp",
1312       "fuzz/FuzzParsePath.cpp",
1313       "fuzz/FuzzPathop.cpp",
1314       "fuzz/FuzzScaleToSides.cpp",
1315       "fuzz/fuzz.cpp",
1316     ]
1317     deps = [
1318       ":flags",
1319       ":skia",
1320       ":tool_utils",
1321     ]
1322   }
1323
1324   test_app("pathops_unittest") {
1325     sources = pathops_tests_sources + [
1326                 rebase_path("tests/skia_test.cpp"),
1327                 rebase_path("tests/Test.cpp"),
1328               ]
1329     deps = [
1330       ":flags",
1331       ":gpu_tool_utils",
1332       ":skia",
1333       ":tool_utils",
1334     ]
1335   }
1336
1337   test_app("dump_record") {
1338     sources = [
1339       "tools/DumpRecord.cpp",
1340       "tools/dump_record.cpp",
1341     ]
1342     deps = [
1343       ":flags",
1344       ":skia",
1345     ]
1346   }
1347
1348   test_app("skdiff") {
1349     sources = [
1350       "tools/skdiff/skdiff.cpp",
1351       "tools/skdiff/skdiff_html.cpp",
1352       "tools/skdiff/skdiff_main.cpp",
1353       "tools/skdiff/skdiff_utils.cpp",
1354     ]
1355     deps = [
1356       ":skia",
1357       ":tool_utils",
1358     ]
1359   }
1360
1361   test_app("skp_parser") {
1362     sources = [
1363       "tools/skp_parser.cpp",
1364     ]
1365     deps = [
1366       ":skia",
1367       ":tool_utils",
1368       "//third_party/jsoncpp",
1369     ]
1370   }
1371
1372   if (skia_enable_gpu && (is_android || is_linux || is_win || is_mac)) {
1373     test_app("viewer") {
1374       is_shared_library = is_android
1375       sources = [
1376         "tools/viewer/GMSlide.cpp",
1377         "tools/viewer/ImageSlide.cpp",
1378         "tools/viewer/SKPSlide.cpp",
1379         "tools/viewer/SampleSlide.cpp",
1380         "tools/viewer/Viewer.cpp",
1381         "tools/viewer/sk_app/CommandSet.cpp",
1382         "tools/viewer/sk_app/GLWindowContext.cpp",
1383         "tools/viewer/sk_app/Window.cpp",
1384       ]
1385       libs = []
1386
1387       if (is_android) {
1388         sources += [
1389           "tools/viewer/sk_app/android/GLWindowContext_android.cpp",
1390           "tools/viewer/sk_app/android/RasterWindowContext_android.cpp",
1391           "tools/viewer/sk_app/android/Window_android.cpp",
1392           "tools/viewer/sk_app/android/main_android.cpp",
1393           "tools/viewer/sk_app/android/surface_glue_android.cpp",
1394         ]
1395         libs += [ "android" ]
1396       } else if (is_linux) {
1397         sources += [
1398           "tools/viewer/sk_app/unix/GLWindowContext_unix.cpp",
1399           "tools/viewer/sk_app/unix/RasterWindowContext_unix.cpp",
1400           "tools/viewer/sk_app/unix/Window_unix.cpp",
1401           "tools/viewer/sk_app/unix/main_unix.cpp",
1402         ]
1403       } else if (is_win) {
1404         sources += [
1405           "tools/viewer/sk_app/win/GLWindowContext_win.cpp",
1406           "tools/viewer/sk_app/win/RasterWindowContext_win.cpp",
1407           "tools/viewer/sk_app/win/Window_win.cpp",
1408           "tools/viewer/sk_app/win/main_win.cpp",
1409         ]
1410       } else if (is_mac) {
1411         sources += [
1412           "tools/viewer/sk_app/mac/GLWindowContext_mac.cpp",
1413           "tools/viewer/sk_app/mac/RasterWindowContext_mac.cpp",
1414           "tools/viewer/sk_app/mac/Window_mac.cpp",
1415           "tools/viewer/sk_app/mac/main_mac.cpp",
1416         ]
1417       }
1418
1419       if (skia_use_vulkan) {
1420         sources += [ "tools/viewer/sk_app/VulkanWindowContext.cpp" ]
1421         if (is_android) {
1422           sources +=
1423               [ "tools/viewer/sk_app/android/VulkanWindowContext_android.cpp" ]
1424         } else if (is_linux) {
1425           sources += [ "tools/viewer/sk_app/unix/VulkanWindowContext_unix.cpp" ]
1426           libs += [ "X11-xcb" ]
1427         } else if (is_win) {
1428           sources += [ "tools/viewer/sk_app/win/VulkanWindowContext_win.cpp" ]
1429         }
1430       }
1431
1432       include_dirs = []
1433       deps = [
1434         ":flags",
1435         ":gm",
1436         ":gpu_tool_utils",
1437         ":samples",
1438         ":skia",
1439         ":tool_utils",
1440         ":views",
1441         "//third_party/imgui",
1442         "//third_party/jsoncpp",
1443       ]
1444       if (is_android) {
1445         deps += [ "//third_party/native_app_glue" ]
1446       } else if (is_mac) {
1447         deps += [ "//third_party/libsdl" ]
1448       }
1449     }
1450   }
1451
1452   if (is_android && is_skia_standalone && ndk != "") {
1453     copy("gdbserver") {
1454       sources = [
1455         "$ndk/$ndk_gdbserver",
1456       ]
1457       outputs = [
1458         "$root_out_dir/gdbserver",
1459       ]
1460     }
1461     if (ndk_simpleperf != "") {
1462       copy("simpleperf") {
1463         sources = [
1464           "$ndk/$ndk_simpleperf",
1465           "$ndk/simpleperf/simpleperf_report.py",
1466         ]
1467         outputs = [
1468           "$root_out_dir/{{source_file_part}}",
1469         ]
1470       }
1471     }
1472   }
1473
1474   if (skia_enable_gpu) {
1475     test_app("skslc") {
1476       sources = [
1477         "src/sksl/SkSLMain.cpp",
1478       ]
1479       deps = [
1480         ":flags",
1481         ":skia",
1482       ]
1483     }
1484   }
1485 }