DW last resort font default name not necessary.
[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 is_skia_dev_build = is_skia_standalone && !is_official_build
13
14 declare_args() {
15   skia_use_angle = false
16   skia_use_expat = true
17   skia_use_fontconfig = is_linux
18   skia_use_freetype = is_android || is_fuchsia || is_linux
19   skia_use_gdi = false
20   skia_use_icu = !is_fuchsia && !is_ios && !is_win  # TODO: Windows
21   skia_use_libjpeg_turbo = true
22   skia_use_libpng = true
23   skia_use_libwebp = !is_fuchsia
24   skia_use_lua = false
25   skia_use_mesa = false
26   skia_use_piex = !is_win
27   skia_use_zlib = true
28
29   skia_android_serial = ""
30   skia_enable_android_framework_defines = false
31   skia_enable_discrete_gpu = true
32   skia_enable_effects = true
33   skia_enable_gpu = true
34   skia_enable_pdf = true
35   skia_enable_tools = is_skia_dev_build
36   skia_enable_vulkan_debug_layers = is_skia_dev_build && 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     ":typeface_freetype",
339     "//third_party/expat",
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     ":typeface_freetype",
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     ":typeface_freetype",
369     "//third_party:fontconfig",
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     ":typeface_freetype",
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("typeface_freetype") {
503   enabled = skia_use_freetype
504
505   deps = [
506     "//third_party/freetype2",
507   ]
508   sources = [
509     "src/ports/SkFontHost_FreeType.cpp",
510     "src/ports/SkFontHost_FreeType_common.cpp",
511   ]
512 }
513
514 optional("webp") {
515   enabled = skia_use_libwebp
516   public_defines = [ "SK_HAS_WEBP_LIBRARY" ]
517
518   deps = [
519     "//third_party/libwebp",
520   ]
521   sources = [
522     "src/codec/SkWebpAdapterCodec.cpp",
523     "src/codec/SkWebpCodec.cpp",
524     "src/images/SkWEBPImageEncoder.cpp",
525   ]
526 }
527
528 optional("xml") {
529   enabled = skia_use_expat
530   public_defines = [ "SK_XML" ]
531
532   deps = [
533     "//third_party/expat",
534   ]
535   sources = [
536     "src/svg/SkSVGCanvas.cpp",
537     "src/svg/SkSVGDevice.cpp",
538     "src/xml/SkDOM.cpp",
539     "src/xml/SkXMLParser.cpp",
540     "src/xml/SkXMLWriter.cpp",
541   ]
542 }
543
544 component("skia") {
545   public_configs = [ ":skia_public" ]
546   configs += skia_library_configs
547
548   deps = [
549     ":arm64",
550     ":armv7",
551     ":avx",
552     ":crc32",
553     ":effects",
554     ":fontmgr_android",
555     ":fontmgr_custom",
556     ":fontmgr_fontconfig",
557     ":fontmgr_fuchsia",
558     ":gpu",
559     ":hsw",
560     ":jpeg",
561     ":none",
562     ":pdf",
563     ":png",
564     ":raw",
565     ":sse2",
566     ":sse41",
567     ":sse42",
568     ":ssse3",
569     ":webp",
570     ":xml",
571   ]
572
573   # This file (and all GN files in Skia) are designed to work with an
574   # empty sources assignment filter; we handle all that explicitly.
575   # We clear the filter here for clients who may have set up a global filter.
576   set_sources_assignment_filter([])
577
578   sources = []
579   sources += skia_core_sources
580   sources += skia_utils_sources
581   sources += skia_xps_sources
582   sources += [
583     "src/android/SkBitmapRegionCodec.cpp",
584     "src/android/SkBitmapRegionDecoder.cpp",
585     "src/codec/SkAndroidCodec.cpp",
586     "src/codec/SkBmpCodec.cpp",
587     "src/codec/SkBmpMaskCodec.cpp",
588     "src/codec/SkBmpRLECodec.cpp",
589     "src/codec/SkBmpStandardCodec.cpp",
590     "src/codec/SkCodec.cpp",
591     "src/codec/SkCodecImageGenerator.cpp",
592     "src/codec/SkGifCodec.cpp",
593     "src/codec/SkMaskSwizzler.cpp",
594     "src/codec/SkMasks.cpp",
595     "src/codec/SkSampledCodec.cpp",
596     "src/codec/SkSampler.cpp",
597     "src/codec/SkStreamBuffer.cpp",
598     "src/codec/SkSwizzler.cpp",
599     "src/codec/SkWbmpCodec.cpp",
600     "src/images/SkImageEncoder.cpp",
601     "src/ports/SkDiscardableMemory_none.cpp",
602     "src/ports/SkImageGenerator_skia.cpp",
603     "src/ports/SkMemory_malloc.cpp",
604     "src/ports/SkOSFile_stdio.cpp",
605     "src/sfnt/SkOTTable_name.cpp",
606     "src/sfnt/SkOTUtils.cpp",
607     "src/utils/mac/SkStream_mac.cpp",
608     "third_party/etc1/etc1.cpp",
609     "third_party/gif/SkGifImageReader.cpp",
610   ]
611
612   libs = []
613
614   if (is_win) {
615     sources += [
616       "src/fonts/SkFontMgr_indirect.cpp",
617       "src/ports/SkDebug_win.cpp",
618       "src/ports/SkFontHost_win.cpp",
619       "src/ports/SkFontMgr_win_dw.cpp",
620       "src/ports/SkImageEncoder_WIC.cpp",
621       "src/ports/SkImageGeneratorWIC.cpp",
622       "src/ports/SkOSFile_win.cpp",
623       "src/ports/SkOSLibrary_win.cpp",
624       "src/ports/SkScalerContext_win_dw.cpp",
625       "src/ports/SkTLS_win.cpp",
626       "src/ports/SkTypeface_win_dw.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_android) {
654     deps += [ "//third_party/expat" ]
655     if (defined(ndk) && ndk != "") {
656       deps += [ "//third_party/cpu-features" ]
657     }
658     sources += [ "src/ports/SkDebug_android.cpp" ]
659     libs += [
660       "EGL",
661       "GLESv2",
662       "log",
663     ]
664   }
665
666   if (is_linux) {
667     sources += [ "src/ports/SkDebug_stdio.cpp" ]
668   }
669
670   if (is_mac) {
671     sources += [
672       "src/ports/SkDebug_stdio.cpp",
673       "src/ports/SkFontHost_mac.cpp",
674       "src/ports/SkImageEncoder_CG.cpp",
675       "src/ports/SkImageGeneratorCG.cpp",
676     ]
677     libs += [
678       "ApplicationServices.framework",
679       "OpenGL.framework",
680     ]
681   }
682
683   if (is_ios) {
684     sources += [
685       "src/ports/SkDebug_stdio.cpp",
686       "src/ports/SkFontHost_mac.cpp",
687       "src/ports/SkImageEncoder_CG.cpp",
688       "src/ports/SkImageGeneratorCG.cpp",
689     ]
690     libs += [
691       "CoreFoundation.framework",
692       "CoreGraphics.framework",
693       "CoreText.framework",
694       "ImageIO.framework",
695       "MobileCoreServices.framework",
696     ]
697   }
698
699   if (is_fuchsia) {
700     sources += [ "src/ports/SkDebug_stdio.cpp" ]
701   }
702 }
703
704 # Targets guarded by skia_enable_tools may use //third_party freely.
705 if (skia_enable_tools) {
706   # Used by gn_to_bp.py to list our public include dirs.
707   source_set("public") {
708     configs += [ ":skia_public" ]
709   }
710
711   config("skia.h_config") {
712     include_dirs = [ "$target_gen_dir" ]
713   }
714   action("skia.h") {
715     public_configs = [ ":skia.h_config" ]
716     skia_h = "$target_gen_dir/skia.h"
717     script = "gn/find_headers.py"
718     args = [ rebase_path(skia_h, root_build_dir) ] +
719            rebase_path(skia_public_includes)
720     depfile = "$skia_h.deps"
721     outputs = [
722       skia_h,
723     ]
724   }
725
726   if (skia_enable_gpu && target_cpu == "x64") {
727     # Our bots only have 64-bit libOSMesa installed.
728     # TODO: worth fixing?
729     executable("fiddle") {
730       libs = []
731       if (is_linux) {
732         libs += [ "OSMesa" ]
733       }
734
735       sources = [
736         "tools/fiddle/draw.cpp",
737         "tools/fiddle/fiddle_main.cpp",
738       ]
739       deps = [
740         ":skia",
741         ":skia.h",
742       ]
743     }
744   }
745
746   if (skia_enable_gpu) {
747     source_set("public_headers_warnings_check") {
748       sources = [
749         "tools/public_headers_warnings_check.cpp",
750       ]
751       configs -= [ "//gn:warnings_except_public_headers" ]
752       deps = [
753         ":skia",
754         ":skia.h",
755       ]
756     }
757   }
758
759   template("test_lib") {
760     config(target_name + "_config") {
761       include_dirs = invoker.public_include_dirs
762       if (defined(invoker.public_defines)) {
763         defines = invoker.public_defines
764       }
765     }
766     source_set(target_name) {
767       forward_variables_from(invoker, "*", [ "public_include_dirs" ])
768       public_configs = [
769         ":" + target_name + "_config",
770         ":skia_private",
771       ]
772
773       if (!defined(deps)) {
774         deps = []
775       }
776       deps += [ ":skia" ]
777       testonly = true
778     }
779   }
780
781   template("test_app") {
782     if (defined(invoker.is_shared_library) && invoker.is_shared_library) {
783       shared_library("lib" + target_name) {
784         forward_variables_from(invoker, "*", [ "is_shared_library" ])
785         testonly = true
786       }
787     } else {
788       _executable = target_name
789       executable(_executable) {
790         forward_variables_from(invoker, "*", [ "is_shared_library" ])
791         testonly = true
792       }
793     }
794     if (is_android && skia_android_serial != "" && defined(_executable)) {
795       action("push_" + target_name) {
796         script = "gn/push_to_android.py"
797         deps = [
798           ":" + _executable,
799         ]
800         _stamp = "$target_gen_dir/$_executable.pushed_$skia_android_serial"
801         outputs = [
802           _stamp,
803         ]
804         args = [
805           rebase_path("$root_build_dir/$_executable"),
806           skia_android_serial,
807           rebase_path(_stamp),
808         ]
809         testonly = true
810       }
811     }
812   }
813
814   test_lib("gpu_tool_utils") {
815     public_include_dirs = []
816     if (skia_enable_gpu) {
817       public_defines = []
818       public_include_dirs += [ "tools/gpu" ]
819
820       deps = []
821       sources = [
822         "tools/gpu/GrContextFactory.cpp",
823         "tools/gpu/GrTest.cpp",
824         "tools/gpu/TestContext.cpp",
825         "tools/gpu/gl/GLTestContext.cpp",
826         "tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp",
827         "tools/gpu/gl/debug/DebugGLTestContext.cpp",
828         "tools/gpu/gl/debug/GrBufferObj.cpp",
829         "tools/gpu/gl/debug/GrFrameBufferObj.cpp",
830         "tools/gpu/gl/debug/GrProgramObj.cpp",
831         "tools/gpu/gl/debug/GrShaderObj.cpp",
832         "tools/gpu/gl/debug/GrTextureObj.cpp",
833         "tools/gpu/gl/debug/GrTextureUnitObj.cpp",
834         "tools/gpu/gl/null/NullGLTestContext.cpp",
835       ]
836       libs = []
837
838       if (is_android) {
839         sources += [ "tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp" ]
840       } else if (is_ios) {
841         sources += [ "tools/gpu/gl/iOS/CreatePlatformGLTestContext_iOS.mm" ]
842         libs += [ "OpenGLES.framework" ]
843       } else if (is_linux) {
844         sources += [ "tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp" ]
845         libs += [ "X11" ]
846       } else if (is_mac) {
847         sources += [ "tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp" ]
848       } else if (is_win) {
849         sources += [ "tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp" ]
850         libs += [
851           "Gdi32.lib",
852           "OpenGL32.lib",
853         ]
854       }
855
856       if (skia_use_angle) {
857         deps += [ "//third_party/angle2" ]
858         sources += [ "tools/gpu/gl/angle/GLTestContext_angle.cpp" ]
859       }
860       if (skia_use_mesa) {
861         public_defines += [ "SK_MESA" ]
862         sources += [ "tools/gpu/gl/mesa/GLTestContext_mesa.cpp" ]
863         libs += [ "OSMesa" ]
864       }
865       if (skia_use_vulkan) {
866         sources += [ "tools/gpu/vk/VkTestContext.cpp" ]
867       }
868     }
869   }
870
871   test_lib("flags") {
872     public_include_dirs = [ "tools/flags" ]
873     sources = [
874       "tools/flags/SkCommandLineFlags.cpp",
875     ]
876   }
877   test_lib("common_flags") {
878     public_include_dirs = [ "tools/flags" ]
879     sources = [
880       "tools/flags/SkCommonFlags.cpp",
881       "tools/flags/SkCommonFlagsConfig.cpp",
882     ]
883     deps = [
884       ":flags",
885       ":gpu_tool_utils",
886     ]
887   }
888
889   test_lib("tool_utils") {
890     public_include_dirs = [
891       "tools",
892       "tools/debugger",
893       "tools/timer",
894     ]
895     sources = [
896       "src/utils/SkMultiPictureDocumentReader.cpp",  # TODO(halcanary): move to tools?
897       "tools/AndroidSkDebugToStdOut.cpp",
898       "tools/CrashHandler.cpp",
899       "tools/LsanSuppressions.cpp",
900       "tools/ProcStats.cpp",
901       "tools/Resources.cpp",
902       "tools/ThermalManager.cpp",
903       "tools/UrlDataManager.cpp",
904       "tools/debugger/SkDebugCanvas.cpp",
905       "tools/debugger/SkDrawCommand.cpp",
906       "tools/debugger/SkJsonWriteBuffer.cpp",
907       "tools/debugger/SkObjectParser.cpp",
908       "tools/picture_utils.cpp",
909       "tools/random_parse_path.cpp",
910       "tools/sk_tool_utils.cpp",
911       "tools/sk_tool_utils_font.cpp",
912       "tools/timer/Timer.cpp",
913     ]
914     libs = []
915     if (is_ios) {
916       sources += [ "tools/ios_utils.m" ]
917       libs += [ "Foundation.framework" ]
918     }
919     deps = [
920       ":common_flags",
921       ":flags",
922       "//third_party/libpng",
923     ]
924     public_deps = [
925       "//third_party/jsoncpp",
926     ]
927   }
928
929   import("gn/gm.gni")
930   test_lib("gm") {
931     public_include_dirs = [ "gm" ]
932     sources = gm_sources
933     deps = [
934       ":flags",
935       ":gpu_tool_utils",
936       ":skia",
937       ":tool_utils",
938     ]
939   }
940
941   import("gn/tests.gni")
942   test_lib("tests") {
943     public_include_dirs = [ "tests" ]
944     sources = tests_sources + pathops_tests_sources
945     if (!fontmgr_android_enabled) {
946       sources -= [ "//tests/FontMgrAndroidParserTest.cpp" ]
947     }
948     deps = [
949       ":experimental_svg_model",
950       ":flags",
951       ":gpu_tool_utils",
952       ":skia",
953       ":tool_utils",
954       "//third_party/libpng",
955       "//third_party/zlib",
956     ]
957   }
958
959   import("gn/bench.gni")
960   test_lib("bench") {
961     public_include_dirs = [ "bench" ]
962     sources = bench_sources
963     deps = [
964       ":flags",
965       ":gm",
966       ":gpu_tool_utils",
967       ":skia",
968       ":tool_utils",
969     ]
970   }
971
972   test_lib("experimental_svg_model") {
973     public_include_dirs = [ "experimental/svg/model" ]
974     sources = [
975       "experimental/svg/model/SkSVGAttribute.cpp",
976       "experimental/svg/model/SkSVGAttributeParser.cpp",
977       "experimental/svg/model/SkSVGCircle.cpp",
978       "experimental/svg/model/SkSVGClipPath.cpp",
979       "experimental/svg/model/SkSVGContainer.cpp",
980       "experimental/svg/model/SkSVGDOM.cpp",
981       "experimental/svg/model/SkSVGEllipse.cpp",
982       "experimental/svg/model/SkSVGLine.cpp",
983       "experimental/svg/model/SkSVGLinearGradient.cpp",
984       "experimental/svg/model/SkSVGNode.cpp",
985       "experimental/svg/model/SkSVGPath.cpp",
986       "experimental/svg/model/SkSVGPoly.cpp",
987       "experimental/svg/model/SkSVGRect.cpp",
988       "experimental/svg/model/SkSVGRenderContext.cpp",
989       "experimental/svg/model/SkSVGSVG.cpp",
990       "experimental/svg/model/SkSVGShape.cpp",
991       "experimental/svg/model/SkSVGStop.cpp",
992       "experimental/svg/model/SkSVGTransformableNode.cpp",
993       "experimental/svg/model/SkSVGValue.cpp",
994     ]
995     deps = [
996       ":skia",
997     ]
998   }
999
1000   test_lib("views") {
1001     public_include_dirs = [ "include/views" ]
1002     sources = [
1003       "src/views/SkEvent.cpp",
1004       "src/views/SkEventSink.cpp",
1005       "src/views/SkOSMenu.cpp",
1006       "src/views/SkTagList.cpp",
1007       "src/views/SkTouchGesture.cpp",
1008       "src/views/SkView.cpp",
1009       "src/views/SkViewPriv.cpp",
1010     ]
1011     libs = []
1012     deps = []
1013     if (!is_android) {
1014       sources += [ "src/views/SkWindow.cpp" ]
1015     }
1016     if (is_linux) {
1017       public_include_dirs += [ "src/views/unix" ]
1018       sources += [
1019         "src/views/unix/SkOSWindow_Unix.cpp",
1020         "src/views/unix/keysym2ucs.c",
1021       ]
1022       libs += [
1023         "GL",
1024         "X11",
1025       ]
1026     } else if (is_mac) {
1027       sources += [
1028         "src/views/mac/SkEventNotifier.mm",
1029         "src/views/mac/SkNSView.mm",
1030         "src/views/mac/SkOSWindow_Mac.mm",
1031         "src/views/mac/SkTextFieldCell.m",
1032       ]
1033       libs += [
1034         "QuartzCore.framework",
1035         "Cocoa.framework",
1036         "Foundation.framework",
1037       ]
1038     } else if (is_win) {
1039       sources += [ "src/views/win/SkOSWindow_win.cpp" ]
1040     }
1041     if (skia_use_angle) {
1042       deps += [ "//third_party/angle2" ]
1043     }
1044   }
1045
1046   if (skia_use_lua) {
1047     test_lib("lua") {
1048       public_include_dirs = []
1049       sources = [
1050         "src/utils/SkLua.cpp",
1051         "src/utils/SkLuaCanvas.cpp",
1052       ]
1053       deps = [
1054         "//third_party/lua",
1055       ]
1056     }
1057
1058     test_app("lua_app") {
1059       sources = [
1060         "tools/lua/lua_app.cpp",
1061       ]
1062       deps = [
1063         ":lua",
1064         ":skia",
1065         "//third_party/lua",
1066       ]
1067     }
1068
1069     test_app("lua_pictures") {
1070       sources = [
1071         "tools/lua/lua_pictures.cpp",
1072       ]
1073       deps = [
1074         ":flags",
1075         ":lua",
1076         ":skia",
1077         ":tool_utils",
1078         "//third_party/lua",
1079       ]
1080     }
1081   }
1082
1083   import("gn/samples.gni")
1084   test_lib("samples") {
1085     public_include_dirs = [ "samplecode" ]
1086     include_dirs = [ "experimental" ]
1087     sources = samples_sources + [
1088                 "experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp",
1089                 "experimental/SkSetPoly3To3.cpp",
1090                 "experimental/SkSetPoly3To3_A.cpp",
1091                 "experimental/SkSetPoly3To3_D.cpp",
1092               ]
1093     deps = [
1094       ":experimental_svg_model",
1095       ":gm",
1096       ":tool_utils",
1097       ":views",
1098       ":xml",
1099     ]
1100
1101     if (skia_use_lua) {
1102       sources += [ "samplecode/SampleLua.cpp" ]
1103       deps += [
1104         ":lua",
1105         "//third_party/lua",
1106       ]
1107     }
1108   }
1109
1110   test_app("dm") {
1111     sources = [
1112       "dm/DM.cpp",
1113       "dm/DMJsonWriter.cpp",
1114       "dm/DMSrcSink.cpp",
1115     ]
1116     include_dirs = [ "tests" ]
1117     deps = [
1118       ":common_flags",
1119       ":experimental_svg_model",
1120       ":flags",
1121       ":gm",
1122       ":gpu_tool_utils",
1123       ":skia",
1124       ":tests",
1125       ":tool_utils",
1126       "//third_party/jsoncpp",
1127       "//third_party/libpng",
1128     ]
1129   }
1130
1131   if (!is_debug) {  # I've benchmarked debug code once too many times...
1132     test_app("monobench") {
1133       sources = [
1134         "tools/monobench.cpp",
1135       ]
1136       deps = [
1137         ":bench",
1138         ":skia",
1139       ]
1140     }
1141   }
1142
1143   test_app("nanobench") {
1144     sources = [
1145       "bench/nanobench.cpp",
1146     ]
1147     deps = [
1148       ":bench",
1149       ":common_flags",
1150       ":experimental_svg_model",
1151       ":flags",
1152       ":gm",
1153       ":gpu_tool_utils",
1154       ":skia",
1155       ":tool_utils",
1156       "//third_party/jsoncpp",
1157     ]
1158   }
1159
1160   test_app("skpinfo") {
1161     sources = [
1162       "tools/skpinfo.cpp",
1163     ]
1164     deps = [
1165       ":flags",
1166       ":skia",
1167     ]
1168   }
1169
1170   if (is_linux || is_win || is_mac) {
1171     test_app("SampleApp") {
1172       sources = [
1173         "samplecode/SampleApp.cpp",
1174         "samplecode/SamplePictFile.cpp",
1175       ]
1176       if (is_mac) {
1177         sources += [ "src/views/mac/skia_mac.mm" ]
1178       } else if (is_win) {
1179         sources += [ "src/views/win/skia_win.cpp" ]
1180       } else if (is_linux) {
1181         sources += [ "src/views/unix/skia_unix.cpp" ]
1182       }
1183       deps = [
1184         ":flags",
1185         ":gm",
1186         ":gpu_tool_utils",
1187         ":samples",
1188         ":skia",
1189         ":tool_utils",
1190         ":views",
1191       ]
1192       if (skia_use_angle) {
1193         deps += [ "//third_party/angle2" ]
1194       }
1195     }
1196   }
1197
1198   if (skia_enable_gpu) {
1199     test_app("skpbench") {
1200       sources = [
1201         "tools/skpbench/skpbench.cpp",
1202       ]
1203       deps = [
1204         ":flags",
1205         ":gpu_tool_utils",
1206         ":skia",
1207         ":tool_utils",
1208       ]
1209     }
1210   }
1211
1212   # We can't yet build ICU on iOS or Windows.
1213   if (!is_ios && !is_win) {
1214     test_app("sktexttopdf-hb") {
1215       sources = [
1216         "tools/SkShaper_harfbuzz.cpp",
1217         "tools/using_skia_and_harfbuzz.cpp",
1218       ]
1219       deps = [
1220         ":skia",
1221         "//third_party/harfbuzz",
1222       ]
1223     }
1224   }
1225   test_app("sktexttopdf") {
1226     sources = [
1227       "tools/SkShaper_primitive.cpp",
1228       "tools/using_skia_and_harfbuzz.cpp",
1229     ]
1230     deps = [
1231       ":skia",
1232     ]
1233   }
1234
1235   test_app("get_images_from_skps") {
1236     sources = [
1237       "tools/get_images_from_skps.cpp",
1238     ]
1239     deps = [
1240       ":flags",
1241       ":skia",
1242       "//third_party/jsoncpp",
1243     ]
1244   }
1245
1246   test_app("colorspaceinfo") {
1247     sources = [
1248       "tools/colorspaceinfo.cpp",
1249     ]
1250     deps = [
1251       ":flags",
1252       ":skia",
1253       ":tool_utils",
1254     ]
1255   }
1256
1257   if (!is_ios) {
1258     test_app("skiaserve") {
1259       sources = [
1260         "tools/skiaserve/Request.cpp",
1261         "tools/skiaserve/Response.cpp",
1262         "tools/skiaserve/skiaserve.cpp",
1263         "tools/skiaserve/urlhandlers/BreakHandler.cpp",
1264         "tools/skiaserve/urlhandlers/ClipAlphaHandler.cpp",
1265         "tools/skiaserve/urlhandlers/CmdHandler.cpp",
1266         "tools/skiaserve/urlhandlers/ColorModeHandler.cpp",
1267         "tools/skiaserve/urlhandlers/DataHandler.cpp",
1268         "tools/skiaserve/urlhandlers/DownloadHandler.cpp",
1269         "tools/skiaserve/urlhandlers/EnableGPUHandler.cpp",
1270         "tools/skiaserve/urlhandlers/ImgHandler.cpp",
1271         "tools/skiaserve/urlhandlers/InfoHandler.cpp",
1272         "tools/skiaserve/urlhandlers/OpBoundsHandler.cpp",
1273         "tools/skiaserve/urlhandlers/OpsHandler.cpp",
1274         "tools/skiaserve/urlhandlers/OverdrawHandler.cpp",
1275         "tools/skiaserve/urlhandlers/PostHandler.cpp",
1276         "tools/skiaserve/urlhandlers/QuitHandler.cpp",
1277         "tools/skiaserve/urlhandlers/RootHandler.cpp",
1278       ]
1279       deps = [
1280         ":flags",
1281         ":gpu_tool_utils",
1282         ":skia",
1283         ":tool_utils",
1284         "//third_party/jsoncpp",
1285         "//third_party/libmicrohttpd",
1286         "//third_party/libpng",
1287       ]
1288     }
1289   }
1290
1291   test_app("fuzz") {
1292     sources = [
1293       "fuzz/FilterFuzz.cpp",
1294       "fuzz/FuzzCanvas.cpp",
1295       "fuzz/FuzzDrawFunctions.cpp",
1296       "fuzz/FuzzGradients.cpp",
1297       "fuzz/FuzzParsePath.cpp",
1298       "fuzz/FuzzPathop.cpp",
1299       "fuzz/FuzzScaleToSides.cpp",
1300       "fuzz/fuzz.cpp",
1301     ]
1302     deps = [
1303       ":flags",
1304       ":skia",
1305       ":tool_utils",
1306     ]
1307   }
1308
1309   test_app("pathops_unittest") {
1310     sources = pathops_tests_sources + [
1311                 rebase_path("tests/skia_test.cpp"),
1312                 rebase_path("tests/Test.cpp"),
1313               ]
1314     deps = [
1315       ":flags",
1316       ":gpu_tool_utils",
1317       ":skia",
1318       ":tool_utils",
1319     ]
1320   }
1321
1322   test_app("dump_record") {
1323     sources = [
1324       "tools/DumpRecord.cpp",
1325       "tools/dump_record.cpp",
1326     ]
1327     deps = [
1328       ":flags",
1329       ":skia",
1330     ]
1331   }
1332
1333   test_app("skdiff") {
1334     sources = [
1335       "tools/skdiff/skdiff.cpp",
1336       "tools/skdiff/skdiff_html.cpp",
1337       "tools/skdiff/skdiff_main.cpp",
1338       "tools/skdiff/skdiff_utils.cpp",
1339     ]
1340     deps = [
1341       ":skia",
1342       ":tool_utils",
1343     ]
1344   }
1345
1346   test_app("skp_parser") {
1347     sources = [
1348       "tools/skp_parser.cpp",
1349     ]
1350     deps = [
1351       ":skia",
1352       ":tool_utils",
1353       "//third_party/jsoncpp",
1354     ]
1355   }
1356
1357   if (skia_enable_gpu && (is_android || is_linux || is_win || is_mac)) {
1358     test_app("viewer") {
1359       is_shared_library = is_android
1360       sources = [
1361         "tools/viewer/GMSlide.cpp",
1362         "tools/viewer/ImageSlide.cpp",
1363         "tools/viewer/SKPSlide.cpp",
1364         "tools/viewer/SampleSlide.cpp",
1365         "tools/viewer/Viewer.cpp",
1366         "tools/viewer/sk_app/CommandSet.cpp",
1367         "tools/viewer/sk_app/GLWindowContext.cpp",
1368         "tools/viewer/sk_app/Window.cpp",
1369       ]
1370       libs = []
1371
1372       if (is_android) {
1373         sources += [
1374           "tools/viewer/sk_app/android/GLWindowContext_android.cpp",
1375           "tools/viewer/sk_app/android/RasterWindowContext_android.cpp",
1376           "tools/viewer/sk_app/android/Window_android.cpp",
1377           "tools/viewer/sk_app/android/main_android.cpp",
1378           "tools/viewer/sk_app/android/surface_glue_android.cpp",
1379         ]
1380         libs += [ "android" ]
1381       } else if (is_linux) {
1382         sources += [
1383           "tools/viewer/sk_app/unix/GLWindowContext_unix.cpp",
1384           "tools/viewer/sk_app/unix/RasterWindowContext_unix.cpp",
1385           "tools/viewer/sk_app/unix/Window_unix.cpp",
1386           "tools/viewer/sk_app/unix/main_unix.cpp",
1387         ]
1388       } else if (is_win) {
1389         sources += [
1390           "tools/viewer/sk_app/win/GLWindowContext_win.cpp",
1391           "tools/viewer/sk_app/win/RasterWindowContext_win.cpp",
1392           "tools/viewer/sk_app/win/Window_win.cpp",
1393           "tools/viewer/sk_app/win/main_win.cpp",
1394         ]
1395       } else if (is_mac) {
1396         sources += [
1397           "tools/viewer/sk_app/mac/GLWindowContext_mac.cpp",
1398           "tools/viewer/sk_app/mac/RasterWindowContext_mac.cpp",
1399           "tools/viewer/sk_app/mac/Window_mac.cpp",
1400           "tools/viewer/sk_app/mac/main_mac.cpp",
1401         ]
1402       }
1403
1404       if (skia_use_vulkan) {
1405         sources += [ "tools/viewer/sk_app/VulkanWindowContext.cpp" ]
1406         if (is_android) {
1407           sources +=
1408               [ "tools/viewer/sk_app/android/VulkanWindowContext_android.cpp" ]
1409         } else if (is_linux) {
1410           sources += [ "tools/viewer/sk_app/unix/VulkanWindowContext_unix.cpp" ]
1411           libs += [ "X11-xcb" ]
1412         } else if (is_win) {
1413           sources += [ "tools/viewer/sk_app/win/VulkanWindowContext_win.cpp" ]
1414         }
1415       }
1416
1417       include_dirs = []
1418       deps = [
1419         ":flags",
1420         ":gm",
1421         ":gpu_tool_utils",
1422         ":samples",
1423         ":skia",
1424         ":tool_utils",
1425         ":views",
1426         "//third_party/imgui",
1427         "//third_party/jsoncpp",
1428       ]
1429       if (is_android) {
1430         deps += [ "//third_party/native_app_glue" ]
1431       } else if (is_mac) {
1432         deps += [ "//third_party/libsdl" ]
1433       }
1434     }
1435   }
1436
1437   if (is_android && defined(ndk) && ndk != "") {
1438     copy("gdbserver") {
1439       sources = [
1440         "$ndk/$ndk_gdbserver",
1441       ]
1442       outputs = [
1443         "$root_out_dir/gdbserver",
1444       ]
1445     }
1446   }
1447
1448   if (skia_enable_gpu) {
1449     test_app("skslc") {
1450       sources = [
1451         "src/sksl/SkSLMain.cpp",
1452       ]
1453       deps = [
1454         ":flags",
1455         ":skia",
1456       ]
1457     }
1458   }
1459 }