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.
12 if (host_os == "win") {
13 ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar.exe"
14 cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang.exe"
15 cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++.exe"
17 ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar"
18 cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang"
19 cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++"
34 enable_bitcode = false
41 windk = "C:/Program Files (x86)/Microsoft Visual Studio 14.0"
43 windk = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional"
47 if (host_os == "win") {
49 stamp = "cmd.exe /c echo >"
55 is_clang = is_android || is_ios || is_mac || (cc == "clang" && cxx == "clang++")
56 if (!is_clang && !is_win) {
57 is_clang = exec_script("is_clang.py",
68 if (target_cpu == "x86" || target_cpu == "x64") {
69 sdk = "appletvsimulator"
73 if (target_cpu == "x86" || target_cpu == "x64") {
74 sdk = "iphonesimulator"
77 ios_sysroot = exec_script("find_ios_sysroot.py", [ sdk ], "trim string")
91 "/FS", # Preserve previous PDB behavior.
92 "/bigobj", # Some of our files are bigger than the regular limits.
93 "/WX", # Treat warnings as errors.
94 "/utf-8", # Set Source and Executable character sets to UTF-8.
97 "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf().
98 "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL.
99 "WIN32_LEAN_AND_MEAN",
106 "$windk/../Windows Kits/10/Include/10.0.10240.0/ucrt",
107 "$windk/../Windows Kits/10/Include/10.0.10240.0/um",
108 "$windk/../Windows Kits/10/Include/10.0.10240.0/shared",
109 "$windk/../Windows Kits/10/Include/10.0.10240.0/winrt",
112 "$windk/../Windows Kits\10\lib\10.0.10240.0\ucrt\$target_cpu",
113 "$windk/../Windows Kits\10\lib\10.0.10240.0\um\$target_cpu",
120 "$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt",
121 "$windk/../Windows Kits/8.1/Include/shared",
122 "$windk/../Windows Kits/8.1/Include/um",
123 "$windk/../Windows Kits/8.1/Include/winrt",
125 # For builds using win_toolchain asset.
126 "$windk/win_sdk/Include/10.0.14393.0/shared",
127 "$windk/win_sdk/Include/10.0.14393.0/ucrt",
128 "$windk/win_sdk/Include/10.0.14393.0/um",
129 "$windk/win_sdk/Include/10.0.14393.0/winrt",
133 "$windk/../Windows Kits/10/Lib/10.0.10150.0/ucrt/$target_cpu",
134 "$windk/../Windows Kits/8.1/Lib/winv6.3/um/$target_cpu",
136 # For builds using win_toolchain asset.
137 "$windk/win_sdk/Lib/10.0.14393.0/ucrt/$target_cpu",
138 "$windk/win_sdk/Lib/10.0.14393.0/um/$target_cpu",
141 if (target_cpu == "x86") {
142 lib_dirs += [ "$windk/VC/lib" ]
143 } else if (target_cpu == "arm") {
144 lib_dirs += [ "$windk/VC/lib/arm" ]
146 lib_dirs += [ "$windk/VC/lib/amd64" ]
152 "-fvisibility=hidden",
157 "-fno-threadsafe-statics",
158 "-fvisibility-inlines-hidden",
162 if (current_cpu == "arm" && !is_win) {
168 } else if (current_cpu == "mipsel" && !is_win) {
170 "-no-integrated-as", # Clang <4.0 doesn't understand 'usw' mnemonic.
173 } else if (current_cpu == "x86" && !is_win) {
174 asmflags += [ "-m32" ]
180 ldflags += [ "-m32" ]
183 if (malloc != "" && !is_win) {
185 "-fno-builtin-malloc",
186 "-fno-builtin-calloc",
187 "-fno-builtin-realloc",
195 "--target=$ndk_target",
196 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
199 "--sysroot=$ndk/platforms/$ndk_platform",
200 "--target=$ndk_target",
201 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
204 "-isystem$ndk/sources/android/support/include",
205 "-isystem$ndk/sources/cxx-stl/gnu-libstdc++/4.9/include",
206 "-isystem$ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ndk_stdlib/include",
209 "--sysroot=$ndk/platforms/$ndk_platform",
210 "--target=$ndk_target",
211 "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
214 "$ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/$ndk_stdlib",
215 "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
218 if (current_cpu == "mips64el") {
219 # The r13 NDK omits /usr/lib from the MIPS64 sysroots, but Clang searches
220 # for /usr/lib64 as $PATH_TO_USR_LIB/../lib64. If there's no /usr/lib,
221 # it can't find /usr/lib64. We must point Clang at /usr/lib64 manually.
222 lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ]
223 ldflags += [ "-B$ndk/platforms/$ndk_platform/usr/lib64" ]
226 libs += [ "gnustl_static" ]
231 if (target_cpu == "arm") {
233 } else if (target_cpu == "x86") {
235 } else if (target_cpu == "x64") {
250 cflags_cc += [ "-stdlib=libc++" ]
261 if (enable_bitcode) {
268 libs += [ "pthread" ]
271 if (sanitize != "") {
272 # You can either pass the sanitizers directly, e.g. "address,undefined",
273 # or pass one of the couple common aliases used by the bots.
274 sanitizers = sanitize
275 if (sanitize == "ASAN") {
276 sanitizers = "address,bool,function,integer-divide-by-zero,nonnull-attribute,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr"
277 } else if (sanitize == "TSAN") {
278 sanitizers = "thread"
279 } else if (sanitize == "MSAN") {
280 sanitizers = "memory"
284 "-fsanitize=$sanitizers",
285 "-fno-sanitize-recover=$sanitizers",
286 "-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"),
288 ldflags += [ "-fsanitize=$sanitizers" ]
289 if (sanitizers == "memory") {
290 cflags += [ "-fsanitize-memory-track-origins" ]
291 cflags_cc += [ "-stdlib=libc++" ]
292 ldflags += [ "-stdlib=libc++" ]
297 config("no_exceptions") {
298 # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.)
300 cflags_cc = [ "-fno-exceptions" ]
310 "/W3", # Turn on lots of warnings.
312 # Disable a bunch of warnings:
313 "/wd4244", # conversion from 'float' to 'int', possible loss of data
314 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
315 "/wd4800", # forcing value to bool 'true' or 'false' (performance warning)
317 # Probably only triggers when /EHsc is enabled.
318 "/wd4291", # no matching operator delete found;
319 # memory will not be freed if initialization throws an exception
330 "-Wno-deprecated-declarations",
331 "-Wno-maybe-uninitialized",
333 cflags_cc += [ "-Wnon-virtual-dtor" ]
338 "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
341 if ((target_cpu == "x86" && is_android) ||
342 (target_cpu == "arm" && is_ios)) {
343 # Clang seems to think new/malloc will only be 4-byte aligned on x86 Android and 32-bit iOS.
344 # We're pretty sure it's actually 8-byte alignment.
345 cflags += [ "-Wno-over-aligned" ]
350 "-Wno-conditional-uninitialized",
352 "-Wno-disabled-macro-expansion",
353 "-Wno-documentation",
354 "-Wno-documentation-unknown-command",
355 "-Wno-double-promotion",
356 "-Wno-exit-time-destructors", # TODO: OK outside libskia
357 "-Wno-float-conversion",
359 "-Wno-format-nonliteral",
360 "-Wno-global-constructors", # TODO: OK outside libskia
361 "-Wno-gnu-zero-variadic-macro-arguments",
362 "-Wno-missing-prototypes",
363 "-Wno-missing-variable-declarations",
365 "-Wno-reserved-id-macro",
367 "-Wno-shift-sign-overflow",
368 "-Wno-sign-conversion",
369 "-Wno-signed-enum-bitfield",
372 "-Wno-unreachable-code",
373 "-Wno-unreachable-code-break",
374 "-Wno-unreachable-code-return",
375 "-Wno-unused-macros",
376 "-Wno-unused-member-function",
379 "-Wno-abstract-vbase-init",
383 # We are unlikely to want to fix these.
385 "-Wno-covered-switch-default",
387 "-Wno-implicit-fallthrough",
388 "-Wno-missing-noreturn",
389 "-Wno-old-style-cast",
394 "-Wno-c++98-compat-pedantic",
395 "-Wno-undefined-func-template",
398 "-Wno-direct-ivar-access",
399 "-Wno-objc-interface-ivars",
404 config("warnings_except_public_headers") {
406 cflags = [ "-Wno-unused-parameter" ]
410 config("extra_flags") {
411 asmflags = extra_asmflags
412 cflags = extra_cflags
413 cflags_c = extra_cflags_c
414 cflags_cc = extra_cflags_cc
415 ldflags = extra_ldflags
418 config("debug_symbols") {
419 # It's annoying to wait for full debug symbols to push over
420 # to Android devices. -gline-tables-only is a lot slimmer.
422 cflags = [ "-gline-tables-only" ]
425 ldflags = [ "/DEBUG" ]
432 if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
434 cflags_cc = [ "/GR-" ]
436 cflags_cc = [ "-fno-rtti" ]
456 if (!enable_bitcode) {
459 "-ffunction-sections",
462 if (is_mac || is_ios) {
463 ldflags = [ "-dead_strip" ]
465 ldflags = [ "-Wl,--gc-sections" ]
468 defines = [ "NDEBUG" ]
471 config("executable") {
475 ldflags = [ "-Wl,-rpath,@loader_path/." ]
476 } else if (is_linux) {
479 "-Wl,-rpath,\$ORIGIN",
483 "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed".
484 "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to.
490 lib_dir_switch = "/LIBPATH:"
495 if (target_cpu != "x64") {
496 if (target_cpu == "x86") {
498 } else if (target_cpu == "arm") {
501 env_setup = "cmd /c \"\"$windk/VC/vcvarsall.bat\" $_target && "
504 bin = "$windk/VC/bin/$_target"
508 if (target_cpu == "x64") {
511 command = "$env_setup\"$bin/$_ml.exe\" /nologo /c /Fo {{output}} {{source}}$env_setup_end"
513 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
515 description = "assemble {{source}}"
519 rspfile = "{{output}}.rsp"
520 precompiled_header_type = "msvc"
521 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
523 # Label names may have spaces so pdbname must be quoted.
524 command = "$env_setup\"$bin/cl.exe\" /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\"$env_setup_end"
527 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
529 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
530 description = "compile {{source}}"
534 rspfile = "{{output}}.rsp"
535 precompiled_header_type = "msvc"
536 pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
538 # Label names may have spaces so pdbname must be quoted.
539 command = "$env_setup\"$bin/cl.exe\" /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\"$env_setup_end"
542 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
544 rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
545 description = "compile {{source}}"
549 rspfile = "{{output}}.rsp"
551 command = "$env_setup\"$bin/lib.exe\" /nologo /ignore:4221 {{arflags}} /OUT:{{output}} @$rspfile$env_setup_end"
553 # Ignore {{output_extension}} and always use .lib, there's no reason to
554 # allow targets to override this extension on Windows.
555 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
557 default_output_extension = ".lib"
558 default_output_dir = "{{target_out_dir}}"
560 # inputs_newline works around a fixed per-line buffer size in the linker.
561 rspfile_content = "{{inputs_newline}}"
562 description = "link {{output}}"
566 dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
567 libname = "${dllname}.lib"
568 pdbname = "${dllname}.pdb"
569 rspfile = "${dllname}.rsp"
571 command = "$env_setup\"$bin/link.exe\" /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile$env_setup_end"
577 default_output_extension = ".dll"
578 default_output_dir = "{{root_out_dir}}"
580 link_output = libname
581 depend_output = libname
587 # I don't quite understand this. Aping Chrome's toolchain/win/BUILD.gn.
590 # inputs_newline works around a fixed per-line buffer size in the linker.
591 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
592 description = "link {{output}}"
596 exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
597 pdbname = "$exename.pdb"
598 rspfile = "$exename.rsp"
601 "$env_setup\"$bin/link.exe\" /nologo /OUT:$exename /PDB:$pdbname @$rspfile$env_setup_end"
603 default_output_extension = ".exe"
604 default_output_dir = "{{root_out_dir}}"
609 # inputs_newline works around a fixed per-line buffer size in the linker.
610 rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
611 description = "link {{output}}"
615 command = "$stamp {{output}}"
616 description = "stamp {{output}}"
620 cp_py = rebase_path("cp.py")
621 command = "$python $cp_py {{source}} {{output}}"
622 description = "copy {{source}} {{output}}"
626 toolchain("gcc_like") {
628 lib_dir_switch = "-L"
631 depfile = "{{output}}.d"
632 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
635 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
637 description = "compile {{source}}"
641 depfile = "{{output}}.d"
642 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
645 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
647 description = "compile {{source}}"
651 depfile = "{{output}}.d"
652 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
655 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
657 description = "compile {{source}}"
661 depfile = "{{output}}.d"
662 command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objc}} -c {{source}} -o {{output}}"
665 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
667 description = "compile {{source}}"
671 depfile = "{{output}}.d"
672 command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
675 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
677 description = "compile {{source}}"
681 rspfile = "{{output}}.rsp"
682 rspfile_content = "{{inputs}}"
683 ar_py = rebase_path("ar.py")
684 command = "$python $ar_py $ar {{output}} $rspfile"
686 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
688 default_output_extension = ".a"
689 output_prefix = "lib"
690 description = "link {{output}}"
694 soname = "{{target_output_name}}{{output_extension}}"
696 rpath = "-Wl,-soname,$soname"
698 rpath = "-Wl,-install_name,@rpath/$soname"
701 command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
703 "{{root_out_dir}}/$soname",
705 output_prefix = "lib"
706 default_output_extension = ".so"
707 description = "link {{output}}"
711 command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
713 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
715 description = "link {{output}}"
719 command = "$stamp {{output}}"
720 description = "stamp {{output}}"
724 cp_py = rebase_path("cp.py")
725 command = "$python $cp_py {{source}} {{output}}"
726 description = "copy {{source}} {{output}}"