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