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