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