1 # Copyright 2016 Google Inc.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 import("gn/shared_sources.gni")
8 if (!defined(is_skia_standalone)) {
9 is_skia_standalone = false
13 skia_use_angle = false
15 skia_use_fontconfig = is_linux
16 skia_use_freetype = is_android || is_fuchsia || is_linux
17 skia_use_giflib = !is_fuchsia
18 skia_use_libjpeg_turbo = true
19 skia_use_libpng = true
20 skia_use_libwebp = !is_fuchsia
22 skia_use_sfntly = !is_fuchsia
23 skia_use_vulkan = is_android && defined(ndk_api) && ndk_api >= 24
26 skia_enable_android_framework_defines = false
27 skia_enable_gpu = true
28 skia_enable_tools = is_skia_standalone
29 skia_enable_vulkan_debug_layers = is_skia_standalone && is_debug
33 skia_use_vulkan = skia_use_vulkan || skia_vulkan_sdk != ""
35 # Our tools require static linking (they use non-exported symbols).
36 skia_enable_tools = skia_enable_tools && !is_component_build
38 fontmgr_android_enabled = skia_use_expat && skia_use_freetype
40 skia_public_includes = [
58 # Skia public API, generally provided by :skia.
59 config("skia_public") {
60 include_dirs = skia_public_includes
61 defines = [ "SKIA_DLL" ]
62 if (is_fuchsia || is_linux) {
63 defines += [ "SK_SAMPLES_FOR_X" ]
65 if (skia_enable_android_framework_defines) {
66 defines += skia_android_framework_defines
68 if (!skia_enable_gpu) {
69 defines += [ "SK_SUPPORT_GPU=0" ]
73 # Skia internal APIs, used by Skia itself and a few test tools.
74 config("skia_private") {
84 "src/effects/gradients",
102 defines = [ "SK_GAMMA_APPLY_TO_A8" ]
105 "SK_GAMMA_EXPONENT=1.4",
106 "SK_GAMMA_CONTRAST=0.0",
109 if (is_official_build || is_android) {
110 # TODO(bsalomon): it'd be nice to make Android normal.
111 defines += [ "SK_ALLOW_STATIC_GLOBAL_INITIALIZERS=0" ]
115 if (skia_use_vulkan) {
116 if (skia_vulkan_sdk != "") {
117 include_dirs += [ "$skia_vulkan_sdk/x86_64/include/" ]
118 lib_dirs += [ "$skia_vulkan_sdk/x86_64/lib/" ]
124 # Any code that's linked into Skia-the-library should use this config via += skia_library_configs.
125 config("skia_library") {
126 visibility = [ ":*" ]
127 defines = [ "SKIA_IMPLEMENTATION=1" ]
130 skia_library_configs = [
136 # Use for CPU-specific Skia code that needs particular compiler flags.
138 if (invoker.enabled) {
139 source_set(target_name) {
140 forward_variables_from(invoker, "*")
141 configs += skia_library_configs
144 # If not enabled, a phony empty target that swallows all otherwise unused variables.
145 source_set(target_name) {
146 forward_variables_from(invoker,
156 is_x86 = current_cpu == "x64" || current_cpu == "x86"
159 enabled = !is_x86 && current_cpu != "arm" && current_cpu != "arm64"
160 sources = skia_opts.none_sources
165 enabled = current_cpu == "arm"
166 sources = skia_opts.armv7_sources + skia_opts.neon_sources
171 enabled = current_cpu == "arm64"
172 sources = skia_opts.arm64_sources
177 enabled = current_cpu == "arm64"
178 sources = skia_opts.crc32_sources
179 cflags = [ "-march=armv8-a+crc" ]
184 sources = skia_opts.sse2_sources
185 cflags = [ "-msse2" ]
190 sources = skia_opts.ssse3_sources
191 cflags = [ "-mssse3" ]
196 sources = skia_opts.sse41_sources
197 cflags = [ "-msse4.1" ]
202 sources = skia_opts.sse42_sources
203 cflags = [ "-msse4.2" ]
208 sources = skia_opts.avx_sources
214 sources = skia_opts.hsw_sources
225 enabled = current_cpu == "mipsel"
226 sources = skia_opts.mips_dsp_sources
230 # Any feature of Skia that requires third-party code should be optional and use this template.
231 template("optional") {
232 if (invoker.enabled) {
233 config(target_name + "_public") {
234 if (defined(invoker.public_defines)) {
235 defines = invoker.public_defines
238 source_set(target_name) {
239 forward_variables_from(invoker,
243 "sources_when_disabled",
245 all_dependent_configs = [ ":" + target_name + "_public" ]
246 configs += skia_library_configs
249 source_set(target_name) {
250 forward_variables_from(invoker,
257 "sources_when_disabled",
259 if (defined(invoker.sources_when_disabled)) {
260 sources = invoker.sources_when_disabled
262 configs += skia_library_configs
267 optional("fontmgr_android") {
268 enabled = fontmgr_android_enabled
271 "//third_party/expat",
272 "//third_party/freetype2",
275 "src/ports/SkFontMgr_android.cpp",
276 "src/ports/SkFontMgr_android_factory.cpp",
277 "src/ports/SkFontMgr_android_parser.cpp",
281 optional("fontmgr_custom") {
282 enabled = is_linux && skia_use_freetype && !skia_use_fontconfig
285 "//third_party/freetype2",
288 "src/ports/SkFontMgr_custom.cpp",
289 "src/ports/SkFontMgr_custom_directory_factory.cpp",
293 optional("fontmgr_fontconfig") {
294 enabled = skia_use_freetype && skia_use_fontconfig
297 "//third_party:fontconfig",
298 "//third_party/freetype2",
301 "src/ports/SkFontConfigInterface.cpp",
302 "src/ports/SkFontConfigInterface_direct.cpp",
303 "src/ports/SkFontConfigInterface_direct_factory.cpp",
304 "src/ports/SkFontMgr_FontConfigInterface.cpp",
305 "src/ports/SkFontMgr_fontconfig.cpp",
306 "src/ports/SkFontMgr_fontconfig_factory.cpp",
310 optional("fontmgr_fuchsia") {
311 enabled = is_fuchsia && skia_use_freetype
314 "//third_party/freetype2",
317 "src/ports/SkFontMgr_custom.cpp",
318 "src/ports/SkFontMgr_custom_empty_factory.cpp",
323 enabled = skia_use_giflib
324 public_defines = [ "SK_HAS_GIF_LIBRARY" ]
327 "//third_party/giflib",
330 "src/codec/SkGifCodec.cpp",
335 enabled = skia_enable_gpu
338 sources = skia_gpu_sources + [ "src/gpu/gl/GrGLDefaultInterface_native.cpp" ]
340 # These paths need to be absolute to match the ones produced by shared_sources.gni.
341 sources -= get_path_info([
342 "src/gpu/gl/GrGLCreateNativeInterface_none.cpp",
343 "src/gpu/gl/GrGLDefaultInterface_none.cpp",
347 sources += [ "src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp" ]
348 } else if (is_linux) {
349 sources += [ "src/gpu/gl/glx/GrGLCreateNativeInterface_glx.cpp" ]
351 sources += [ "src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp" ]
353 sources += [ "src/gpu/gl/GrGLCreateNativeInterface_none.cpp" ]
357 if (skia_use_vulkan) {
358 public_defines += [ "SK_VULKAN" ]
359 sources += skia_vk_sources
360 if (skia_enable_vulkan_debug_layers) {
361 public_defines += [ "SK_ENABLE_VK_LAYERS" ]
367 enabled = skia_use_libjpeg_turbo
368 public_defines = [ "SK_HAS_JPEG_LIBRARY" ]
371 "//third_party/libjpeg-turbo:libjpeg",
374 "src/codec/SkJpegCodec.cpp",
375 "src/codec/SkJpegDecoderMgr.cpp",
376 "src/codec/SkJpegUtility.cpp",
377 "src/images/SkJPEGImageEncoder.cpp",
378 "src/images/SkJPEGWriteUtility.cpp",
383 enabled = skia_use_zlib
386 "//third_party/zlib",
388 sources = skia_pdf_sources
389 sources_when_disabled = [ "src/pdf/SkDocument_PDF_None.cpp" ]
391 if (skia_use_sfntly) {
392 deps += [ "//third_party/sfntly" ]
393 public_defines = [ "SK_PDF_USE_SFNTLY" ]
398 enabled = skia_use_libpng
399 public_defines = [ "SK_HAS_PNG_LIBRARY" ]
402 "//third_party/libpng",
405 "src/codec/SkIcoCodec.cpp",
406 "src/codec/SkPngCodec.cpp",
407 "src/images/SkPNGImageEncoder.cpp",
411 optional("typeface_freetype") {
412 enabled = skia_use_freetype
415 "//third_party/freetype2",
418 "src/ports/SkFontHost_FreeType.cpp",
419 "src/ports/SkFontHost_FreeType_common.cpp",
424 enabled = skia_use_libwebp
425 public_defines = [ "SK_HAS_WEBP_LIBRARY" ]
428 "//third_party/libwebp",
431 "src/codec/SkWebpAdapterCodec.cpp",
432 "src/codec/SkWebpCodec.cpp",
433 "src/images/SkWEBPImageEncoder.cpp",
438 enabled = skia_use_expat
441 "//third_party/expat",
445 "src/xml/SkXMLParser.cpp",
446 "src/xml/SkXMLWriter.cpp",
451 public_configs = [ ":skia_public" ]
452 configs += skia_library_configs
462 ":fontmgr_fontconfig",
475 ":typeface_freetype",
481 sources += skia_core_sources
482 sources += skia_effects_sources
483 sources += skia_sksl_sources
484 sources += skia_utils_sources
486 "src/android/SkBitmapRegionCodec.cpp",
487 "src/android/SkBitmapRegionDecoder.cpp",
488 "src/codec/SkAndroidCodec.cpp",
489 "src/codec/SkBmpCodec.cpp",
490 "src/codec/SkBmpMaskCodec.cpp",
491 "src/codec/SkBmpRLECodec.cpp",
492 "src/codec/SkBmpStandardCodec.cpp",
493 "src/codec/SkCodec.cpp",
494 "src/codec/SkCodecImageGenerator.cpp",
495 "src/codec/SkMaskSwizzler.cpp",
496 "src/codec/SkMasks.cpp",
497 "src/codec/SkSampledCodec.cpp",
498 "src/codec/SkSampler.cpp",
499 "src/codec/SkSwizzler.cpp",
500 "src/codec/SkWbmpCodec.cpp",
501 "src/images/SkImageEncoder.cpp",
502 "src/images/SkImageEncoder_Factory.cpp",
503 "src/images/SkKTXImageEncoder.cpp",
504 "src/ports/SkDiscardableMemory_none.cpp",
505 "src/ports/SkGlobalInitialization_default.cpp",
506 "src/ports/SkImageGenerator_skia.cpp",
507 "src/ports/SkMemory_malloc.cpp",
508 "src/ports/SkOSFile_stdio.cpp",
509 "src/sfnt/SkOTTable_name.cpp",
510 "src/sfnt/SkOTUtils.cpp",
511 "src/svg/SkSVGCanvas.cpp",
512 "src/svg/SkSVGDevice.cpp",
513 "src/utils/mac/SkStream_mac.cpp",
514 "third_party/etc1/etc1.cpp",
515 "third_party/ktx/ktx.cpp",
522 "src/ports/SkDebug_win.cpp",
523 "src/ports/SkFontHost_win.cpp",
524 "src/ports/SkFontMgr_win_dw.cpp",
525 "src/ports/SkFontMgr_win_dw_factory.cpp",
526 "src/ports/SkImageEncoder_WIC.cpp",
527 "src/ports/SkImageGeneratorWIC.cpp",
528 "src/ports/SkOSFile_win.cpp",
529 "src/ports/SkOSLibrary_win.cpp",
530 "src/ports/SkScalerContext_win_dw.cpp",
531 "src/ports/SkTLS_win.cpp",
532 "src/ports/SkTypeface_win_dw.cpp",
533 "src/xps/SkDocument_XPS.cpp",
536 [ get_path_info("src/utils/SkThreadUtils_pthread.cpp", "abspath") ]
539 "src/ports/SkOSFile_posix.cpp",
540 "src/ports/SkOSLibrary_posix.cpp",
541 "src/ports/SkTLS_pthread.cpp",
542 "src/xps/SkDocument_XPS_None.cpp",
548 "//third_party/cpu-features",
549 "//third_party/expat",
551 sources += [ "src/ports/SkDebug_android.cpp" ]
565 sources += [ "src/ports/SkDebug_stdio.cpp" ]
570 "src/ports/SkDebug_stdio.cpp",
571 "src/ports/SkFontHost_mac.cpp",
572 "src/ports/SkImageEncoder_CG.cpp",
573 "src/ports/SkImageGeneratorCG.cpp",
576 "ApplicationServices.framework",
582 sources += [ "src/ports/SkDebug_stdio.cpp" ]
586 skia_h_headers = exec_script("gyp/find.py",
587 [ "*.h" ] + rebase_path(skia_public_includes),
591 rebase_path("include/gpu/gl/GrGLConfig_chrome.h"),
592 rebase_path("include/gpu/vk/GrVkBackendContext.h"),
593 rebase_path("include/gpu/vk/GrVkDefines.h"),
594 rebase_path("include/gpu/vk/GrVkInterface.h"),
595 rebase_path("include/gpu/vk/GrVkTypes.h"),
596 rebase_path("include/ports/SkFontMgr_fontconfig.h"),
600 script = "gn/echo_headers.py"
601 args = [ rebase_path("$target_gen_dir/skia.h", root_build_dir) ] +
602 rebase_path(skia_h_headers, target_gen_dir)
603 inputs = skia_h_headers
605 "$target_gen_dir/skia.h",
609 if (skia_enable_gpu && target_cpu == "x64") {
610 # Our bots only have 64-bit libOSMesa installed.
611 # TODO: worth fixing?
612 executable("fiddle") {
613 include_dirs = [ "$target_gen_dir" ]
620 "src/images/SkForceLinking.cpp",
621 "tools/fiddle/draw.cpp",
622 "tools/fiddle/fiddle_main.cpp",
631 # Targets guarded by skia_enable_tools may use //third_party freely.
632 if (skia_enable_tools) {
633 template("test_lib") {
634 config(target_name + "_config") {
635 include_dirs = invoker.public_include_dirs
636 if (defined(invoker.public_defines)) {
637 defines = invoker.public_defines
640 source_set(target_name) {
641 forward_variables_from(invoker, "*", [ "public_include_dirs" ])
643 ":" + target_name + "_config",
647 if (!defined(deps)) {
655 test_lib("gpu_tool_utils") {
656 public_include_dirs = []
657 if (skia_enable_gpu) {
659 public_include_dirs += [ "tools/gpu" ]
663 "tools/gpu/GrContextFactory.cpp",
664 "tools/gpu/GrTest.cpp",
665 "tools/gpu/TestContext.cpp",
666 "tools/gpu/gl/GLTestContext.cpp",
667 "tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp",
668 "tools/gpu/gl/debug/DebugGLTestContext.cpp",
669 "tools/gpu/gl/debug/GrBufferObj.cpp",
670 "tools/gpu/gl/debug/GrFrameBufferObj.cpp",
671 "tools/gpu/gl/debug/GrProgramObj.cpp",
672 "tools/gpu/gl/debug/GrShaderObj.cpp",
673 "tools/gpu/gl/debug/GrTextureObj.cpp",
674 "tools/gpu/gl/debug/GrTextureUnitObj.cpp",
675 "tools/gpu/gl/null/NullGLTestContext.cpp",
680 sources += [ "tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp" ]
681 } else if (is_linux) {
682 sources += [ "tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp" ]
684 sources += [ "tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp" ]
687 if (skia_use_angle) {
688 public_defines += [ "SK_ANGLE" ]
689 deps += [ "//third_party/angle2" ]
690 sources += [ "tools/gpu/gl/angle/GLTestContext_angle.cpp" ]
693 public_defines += [ "SK_MESA" ]
694 sources += [ "tools/gpu/gl/mesa/GLTestContext_mesa.cpp" ]
697 if (skia_use_vulkan) {
698 sources += [ "tools/gpu/vk/VkTestContext.cpp" ]
704 public_include_dirs = [ "tools/flags" ]
706 "tools/flags/SkCommandLineFlags.cpp",
709 test_lib("common_flags") {
710 public_include_dirs = [ "tools/flags" ]
712 "tools/flags/SkCommonFlags.cpp",
713 "tools/flags/SkCommonFlagsConfig.cpp",
721 test_lib("tool_utils") {
722 public_include_dirs = [
728 "src/images/SkForceLinking.cpp",
729 "src/utils/SkMultiPictureDocumentReader.cpp", # TODO(halcanary): move to tools?
730 "tools/AndroidSkDebugToStdOut.cpp",
731 "tools/CrashHandler.cpp",
732 "tools/LsanSuppressions.cpp",
733 "tools/ProcStats.cpp",
734 "tools/Resources.cpp",
735 "tools/ThermalManager.cpp",
736 "tools/UrlDataManager.cpp",
737 "tools/debugger/SkDebugCanvas.cpp",
738 "tools/debugger/SkDrawCommand.cpp",
739 "tools/debugger/SkJsonWriteBuffer.cpp",
740 "tools/debugger/SkObjectParser.cpp",
741 "tools/debugger/SkOverdrawMode.cpp",
742 "tools/picture_utils.cpp",
743 "tools/random_parse_path.cpp",
744 "tools/sk_tool_utils.cpp",
745 "tools/sk_tool_utils_font.cpp",
746 "tools/timer/Timer.cpp",
751 "//third_party/libpng",
754 "//third_party/jsoncpp",
758 gm_sources = exec_script("gyp/find.py",
766 public_include_dirs = [ "gm" ]
775 tests_sources = exec_script("gyp/find.py",
778 rebase_path("tests"),
784 public_include_dirs = [ "tests" ]
785 sources = tests_sources - [
786 rebase_path("tests/PathOpsSkpClipTest.cpp"), # alternate main
787 rebase_path("tests/SkpSkGrTest.cpp"), # doesn't compile
788 rebase_path("tests/skia_test.cpp"), # alternate main
790 if (!fontmgr_android_enabled) {
791 sources -= [ rebase_path("tests/FontMgrAndroidParserTest.cpp") ]
794 ":experimental_svg_model",
799 "//third_party/libpng",
800 "//third_party/zlib",
804 bench_sources = exec_script("gyp/find.py",
807 rebase_path("bench"),
813 public_include_dirs = [ "bench" ]
814 sources = bench_sources
816 rebase_path("bench/nanobench.cpp"),
817 rebase_path("bench/nanobenchAndroid.cpp"),
828 test_lib("experimental_svg_model") {
829 public_include_dirs = [ "experimental/svg/model" ]
831 "experimental/svg/model/SkSVGAttribute.cpp",
832 "experimental/svg/model/SkSVGAttributeParser.cpp",
833 "experimental/svg/model/SkSVGCircle.cpp",
834 "experimental/svg/model/SkSVGContainer.cpp",
835 "experimental/svg/model/SkSVGDOM.cpp",
836 "experimental/svg/model/SkSVGEllipse.cpp",
837 "experimental/svg/model/SkSVGLine.cpp",
838 "experimental/svg/model/SkSVGLinearGradient.cpp",
839 "experimental/svg/model/SkSVGNode.cpp",
840 "experimental/svg/model/SkSVGPath.cpp",
841 "experimental/svg/model/SkSVGPoly.cpp",
842 "experimental/svg/model/SkSVGRect.cpp",
843 "experimental/svg/model/SkSVGRenderContext.cpp",
844 "experimental/svg/model/SkSVGSVG.cpp",
845 "experimental/svg/model/SkSVGShape.cpp",
846 "experimental/svg/model/SkSVGStop.cpp",
847 "experimental/svg/model/SkSVGTransformableNode.cpp",
848 "experimental/svg/model/SkSVGValue.cpp",
858 "dm/DMJsonWriter.cpp",
861 include_dirs = [ "tests" ]
864 ":experimental_svg_model",
871 "//third_party/jsoncpp",
872 "//third_party/libpng",
877 if (!is_debug) { # I've benchmarked debug code once too many times...
878 executable("monobench") {
880 "tools/monobench.cpp",
890 executable("nanobench") {
892 "bench/nanobench.cpp",
897 ":experimental_svg_model",
903 "//third_party/jsoncpp",
908 if (skia_enable_gpu) {
909 executable("skpbench") {
911 "tools/skpbench/skpbench.cpp",
923 if (current_cpu != "mipsel") { # Clang 3.8 crashes while compiling hb-icu.cc for mipsel.
924 executable("sktexttopdf-hb") {
926 "tools/SkShaper_harfbuzz.cpp",
927 "tools/using_skia_and_harfbuzz.cpp",
931 "//third_party/harfbuzz",
936 executable("sktexttopdf") {
938 "tools/SkShaper_primitive.cpp",
939 "tools/using_skia_and_harfbuzz.cpp",
947 executable("get_images_from_skps") {
949 "tools/get_images_from_skps.cpp",
954 "//third_party/jsoncpp",
959 executable("skiaserve") {
961 "tools/skiaserve/Request.cpp",
962 "tools/skiaserve/Response.cpp",
963 "tools/skiaserve/skiaserve.cpp",
964 "tools/skiaserve/urlhandlers/BatchBoundsHandler.cpp",
965 "tools/skiaserve/urlhandlers/BatchesHandler.cpp",
966 "tools/skiaserve/urlhandlers/BreakHandler.cpp",
967 "tools/skiaserve/urlhandlers/ClipAlphaHandler.cpp",
968 "tools/skiaserve/urlhandlers/CmdHandler.cpp",
969 "tools/skiaserve/urlhandlers/ColorModeHandler.cpp",
970 "tools/skiaserve/urlhandlers/DataHandler.cpp",
971 "tools/skiaserve/urlhandlers/DownloadHandler.cpp",
972 "tools/skiaserve/urlhandlers/EnableGPUHandler.cpp",
973 "tools/skiaserve/urlhandlers/ImgHandler.cpp",
974 "tools/skiaserve/urlhandlers/InfoHandler.cpp",
975 "tools/skiaserve/urlhandlers/PostHandler.cpp",
976 "tools/skiaserve/urlhandlers/QuitHandler.cpp",
977 "tools/skiaserve/urlhandlers/RootHandler.cpp",
984 "//third_party/jsoncpp",
985 "//third_party/libmicrohttpd",
986 "//third_party/libpng",
993 "fuzz/FilterFuzz.cpp",
994 "fuzz/FuzzGradients.cpp",
995 "fuzz/FuzzParsePath.cpp",
996 "fuzz/FuzzPathop.cpp",
997 "fuzz/FuzzScaleToSides.cpp",