skia2/gn/BUILD.gn

452 lines
12 KiB
Plaintext
Raw Normal View History

# Copyright 2016 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
declare_args() {
ar = "ar"
cc = "cc"
cxx = "c++"
if (is_android) {
ar = "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin/ar"
cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang"
cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++"
}
windk = "C:/Program Files (x86)/Microsoft Visual Studio 14.0"
extra_cflags = []
extra_cflags_c = []
extra_cflags_cc = []
extra_ldflags = []
cc_wrapper = ""
}
if (!is_win) {
is_clang = exec_script("is_clang.py",
[
cc,
cxx,
],
"value")
}
config("default") {
asmflags = []
cflags = []
cflags_c = []
cflags_cc = []
defines = []
ldflags = []
if (is_win) {
cflags += [
"/FS", # Preserve previous PDB behavior.
"/bigobj", # Some of our files are bigger than the regular limits.
]
cflags_c += [ "/TC" ]
cflags_cc += [ "/TP" ]
defines += [
"_HAS_EXCEPTIONS=0",
"WIN32_LEAN_AND_MEAN",
"NOMINMAX",
]
include_dirs = [
"$windk/../Windows Kits/10/Include/10.0.10150.0/ucrt",
"$windk/../Windows Kits/8.1/Include/shared",
"$windk/../Windows Kits/8.1/Include/um",
"$windk/VC/include",
]
lib_dirs = [
"$windk/../Windows Kits/10/Lib/10.0.10150.0/ucrt/x64",
"$windk/../Windows Kits/8.1/Lib/winv6.3/um/x64",
"$windk/VC/lib/amd64",
]
} else {
cflags += [
"-O1",
"-fstrict-aliasing",
"-fPIC",
"-fvisibility=hidden",
"-Werror",
"-Wall",
"-Wextra",
"-Winit-self",
"-Wpointer-arith",
"-Wsign-compare",
"-Wvla",
"-Wno-deprecated-declarations",
"-Wno-unused-parameter",
]
cflags_cc += [
"-std=c++11",
"-fno-exceptions",
"-fno-threadsafe-statics",
"-fvisibility-inlines-hidden",
"-Wnon-virtual-dtor",
]
if (is_clang) {
cflags += [
"-Weverything",
"-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings.
]
if (is_android && target_cpu == "x86") {
# Clang seems to think new/malloc will only be 4-byte aligned on x86 Android.
# We're pretty sure it's actually 8-byte alignment.
cflags += [ "-Wno-over-aligned" ]
}
cflags += [
"-Wno-cast-align",
"-Wno-conditional-uninitialized",
"-Wno-conversion",
"-Wno-disabled-macro-expansion",
"-Wno-documentation",
"-Wno-documentation-unknown-command",
"-Wno-double-promotion",
"-Wno-exit-time-destructors", # TODO: OK outside libskia
"-Wno-float-conversion",
"-Wno-float-equal",
"-Wno-format-nonliteral",
"-Wno-global-constructors", # TODO: OK outside libskia
"-Wno-gnu-zero-variadic-macro-arguments",
"-Wno-missing-prototypes",
"-Wno-missing-variable-declarations",
"-Wno-pedantic",
"-Wno-reserved-id-macro",
"-Wno-shadow",
"-Wno-shift-sign-overflow",
"-Wno-sign-conversion",
"-Wno-switch-enum",
"-Wno-undef",
"-Wno-unreachable-code",
"-Wno-unreachable-code-break",
"-Wno-unreachable-code-return",
"-Wno-unused-macros",
"-Wno-unused-member-function",
]
cflags_cc += [
"-Wno-abstract-vbase-init",
"-Wno-range-loop-analysis",
"-Wno-weak-vtables",
]
# We are unlikely to want to fix these.
cflags += [
"-Wno-covered-switch-default",
"-Wno-deprecated",
"-Wno-implicit-fallthrough",
"-Wno-missing-noreturn",
"-Wno-old-style-cast",
"-Wno-padded",
]
cflags_cc += [
"-Wno-c++98-compat",
"-Wno-c++98-compat-pedantic",
"-Wno-undefined-func-template",
]
}
}
if (current_cpu == "arm") {
cflags += [
"-march=armv7-a",
"-mfpu=neon",
"-mthumb",
]
} else if (current_cpu == "mipsel") {
cflags += [
"-march=mips32r2",
"-mdspr2",
]
} else if (current_cpu == "x86") {
asmflags += [ "-m32" ]
cflags += [
"-m32",
"-msse2",
"-mfpmath=sse",
]
ldflags += [ "-m32" ]
}
if (is_android) {
asmflags += [
"--target=$ndk_target",
"-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
]
cflags += [
"--sysroot=$ndk/platforms/$ndk_platform",
"--target=$ndk_target",
"-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
]
cflags_cc += [
"-isystem$ndk/sources/android/support/include",
Update to Android NDK r13. The libc++ include paths have changed very slightly. I've left GN compatible with both older r12 NDKs and the new r13 to smooth the transition. The libc++ in r13 depends on long-double math.h functions (cosl, atanl, etc.) only available in Android API v21 (Lollipop) and up. That's what the 64-bit bots were already on, so we just pull the 32-bit bots up to the same target. Conveniently, the oldest bots we have (N7 and N10) are on Lollipop. The r13 MIPS64 sysroots are a little weird... /usr/include and /usr/lib64 but no /usr/lib. That'd be fine---we only want 64-bit builds---but Clang searches for /usr/lib64 via its path to /usr/lib, and without at least an empty /usr/lib, it can't find /usr/lib64. So you'll see a special mips64el section in the GN config where we do this all manually (other platforms pick this all up correctly from --sysroot). I've chosen to do this rather than fix it up in the asset create.py scripts so that we stay compatible with vanilla NDKs, which is convenient for developers. CQ_INCLUDE_TRYBOTS=master.client.skia.compile:Build-Mac-Clang-arm64-Debug-GN_Android-Trybot,Build-Ubuntu-Clang-arm-Debug-GN_Android-Trybot,Build-Ubuntu-Clang-arm-Release-GN_Android-Trybot,Build-Ubuntu-Clang-arm64-Debug-GN_Android-Trybot,Build-Ubuntu-Clang-arm64-Debug-GN_Android_FrameworkDefs-Trybot,Build-Ubuntu-Clang-arm64-Debug-GN_Android_Vulkan-Trybot,Build-Ubuntu-Clang-arm64-Release-GN_Android-Trybot,Build-Ubuntu-Clang-mips64el-Debug-GN_Android-Trybot,Build-Ubuntu-Clang-mips64el-Release-GN_Android-Trybot,Build-Ubuntu-Clang-mips64el-Release-GN_Android-Trybot,Build-Ubuntu-Clang-mipsel-Debug-GN_Android-Trybot,Build-Ubuntu-Clang-mipsel-Release-GN_Android-Trybot,Build-Ubuntu-Clang-x64-Debug-GN_Android-Trybot,Build-Ubuntu-Clang-x64-Release-GN_Android-Trybot,Build-Ubuntu-Clang-x86-Debug-GN_Android-Trybot,Build-Ubuntu-Clang-x86-Release-GN_Android-Trybot BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3180 Change-Id: I6f3b5d9411ded0ee49c1099490f41fa86a8736f8 Reviewed-on: https://skia-review.googlesource.com/3180 Reviewed-by: Eric Boren <borenet@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org>
2016-10-11 15:21:36 +00:00
"-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include", # Through r12b.
"-isystem$ndk/sources/cxx-stl/llvm-libc++/include", # Since r13.
]
ldflags += [
"--sysroot=$ndk/platforms/$ndk_platform",
"--target=$ndk_target",
"-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin",
"-pie",
]
lib_dirs = [
"$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib",
"$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x",
]
Update to Android NDK r13. The libc++ include paths have changed very slightly. I've left GN compatible with both older r12 NDKs and the new r13 to smooth the transition. The libc++ in r13 depends on long-double math.h functions (cosl, atanl, etc.) only available in Android API v21 (Lollipop) and up. That's what the 64-bit bots were already on, so we just pull the 32-bit bots up to the same target. Conveniently, the oldest bots we have (N7 and N10) are on Lollipop. The r13 MIPS64 sysroots are a little weird... /usr/include and /usr/lib64 but no /usr/lib. That'd be fine---we only want 64-bit builds---but Clang searches for /usr/lib64 via its path to /usr/lib, and without at least an empty /usr/lib, it can't find /usr/lib64. So you'll see a special mips64el section in the GN config where we do this all manually (other platforms pick this all up correctly from --sysroot). I've chosen to do this rather than fix it up in the asset create.py scripts so that we stay compatible with vanilla NDKs, which is convenient for developers. CQ_INCLUDE_TRYBOTS=master.client.skia.compile:Build-Mac-Clang-arm64-Debug-GN_Android-Trybot,Build-Ubuntu-Clang-arm-Debug-GN_Android-Trybot,Build-Ubuntu-Clang-arm-Release-GN_Android-Trybot,Build-Ubuntu-Clang-arm64-Debug-GN_Android-Trybot,Build-Ubuntu-Clang-arm64-Debug-GN_Android_FrameworkDefs-Trybot,Build-Ubuntu-Clang-arm64-Debug-GN_Android_Vulkan-Trybot,Build-Ubuntu-Clang-arm64-Release-GN_Android-Trybot,Build-Ubuntu-Clang-mips64el-Debug-GN_Android-Trybot,Build-Ubuntu-Clang-mips64el-Release-GN_Android-Trybot,Build-Ubuntu-Clang-mips64el-Release-GN_Android-Trybot,Build-Ubuntu-Clang-mipsel-Debug-GN_Android-Trybot,Build-Ubuntu-Clang-mipsel-Release-GN_Android-Trybot,Build-Ubuntu-Clang-x64-Debug-GN_Android-Trybot,Build-Ubuntu-Clang-x64-Release-GN_Android-Trybot,Build-Ubuntu-Clang-x86-Debug-GN_Android-Trybot,Build-Ubuntu-Clang-x86-Release-GN_Android-Trybot BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3180 Change-Id: I6f3b5d9411ded0ee49c1099490f41fa86a8736f8 Reviewed-on: https://skia-review.googlesource.com/3180 Reviewed-by: Eric Boren <borenet@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org>
2016-10-11 15:21:36 +00:00
if (current_cpu == "mips64el") {
# The r13 NDK omits /usr/lib from the MIPS64 sysroots, but Clang searches
# for /usr/lib64 as $PATH_TO_USR_LIB/../lib64. If there's no /usr/lib,
# it can't find /usr/lib64. We must point Clang at /usr/lib64 manually.
lib_dirs += [ "$ndk/platforms/$ndk_platform/usr/lib64" ]
ldflags += [
# Clang will try to link these two files, but not find them. Again, do it manually.
"-nostartfiles",
"$ndk/platforms/$ndk_platform/usr/lib64/crtbegin_dynamic.o",
"$ndk/platforms/$ndk_platform/usr/lib64/crtend_android.o",
]
}
libs = [
# Order matters here! Keep these three in exactly this order.
"c++_static",
"c++abi",
"android_support",
]
if (target_cpu == "arm") {
libs += [ "unwind" ]
}
}
if (is_linux) {
libs = [ "pthread" ]
}
if (sanitize != "") {
# You can either pass the sanitizers directly, e.g. "address,undefined",
# or pass one of the couple common aliases used by the bots.
sanitizers = sanitize
if (sanitize == "ASAN") {
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"
} else if (sanitize == "TSAN") {
sanitizers = "thread"
} else if (sanitize == "MSAN") {
sanitizers = "memory"
}
cflags += [
"-fsanitize=$sanitizers",
"-fno-sanitize-recover=$sanitizers",
"-fsanitize-blacklist=" + rebase_path("../tools/xsan.blacklist"),
]
ldflags += [ "-fsanitize=$sanitizers" ]
if (sanitizers == "memory") {
cflags += [ "-fsanitize-memory-track-origins" ]
cflags_cc += [ "-stdlib=libc++" ]
ldflags += [ "-stdlib=libc++" ]
}
}
}
config("extra_flags") {
cflags = extra_cflags
cflags_c = extra_cflags_c
cflags_cc = extra_cflags_cc
ldflags = extra_ldflags
}
config("debug_symbols") {
# It's annoying to wait for full debug symbols to push over
# to Android devices. -gline-tables-only is a lot slimmer.
if (is_android) {
cflags = [ "-gline-tables-only" ]
} else if (!is_win) {
cflags = [ "-g" ]
}
}
config("no_rtti") {
if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI
if (!is_win) {
cflags_cc = [ "-fno-rtti" ]
}
}
}
config("release") {
if (!is_win) {
cflags = [ "-O3" ]
}
defines = [ "NDEBUG" ]
}
config("executable") {
if (is_mac) {
ldflags = [ "-Wl,-rpath,@loader_path/." ]
} else if (is_linux) {
ldflags = [
"-rdynamic",
"-Wl,-rpath,\$ORIGIN",
]
}
}
toolchain("msvc") {
lib_dir_switch = "/LIBPATH:"
cl_exe = "$windk/VC/bin/amd64/cl.exe"
link_exe = "$windk/VC/bin/amd64/link.exe"
lib_exe = "$windk/VC/bin/amd64/lib.exe"
tool("cc") {
rspfile = "{{output}}.rsp"
precompiled_header_type = "msvc"
pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
# Label names may have spaces so pdbname must be quoted.
command = "$cl_exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
depsformat = "msvc"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
]
rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
}
tool("cxx") {
rspfile = "{{output}}.rsp"
precompiled_header_type = "msvc"
pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
# Label names may have spaces so pdbname must be quoted.
command = "$cl_exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
depsformat = "msvc"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
]
rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
}
tool("alink") {
rspfile = "{{output}}.rsp"
command = "$lib_exe /nologo {{arflags}} /OUT:{{output}} @$rspfile"
outputs = [
# Ignore {{output_extension}} and always use .lib, there's no reason to
# allow targets to override this extension on Windows.
"{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
]
default_output_extension = ".lib"
default_output_dir = "{{target_out_dir}}"
# inputs_newline works around a fixed per-line buffer size in the linker.
rspfile_content = "{{inputs_newline}}"
}
tool("link") {
exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
pdbname = "$exename.pdb"
rspfile = "$exename.rsp"
command = "$link_exe /nologo /OUT:$exename /PDB:$pdbname @$rspfile"
default_output_extension = ".exe"
default_output_dir = "{{root_out_dir}}"
outputs = [
exename,
]
# inputs_newline works around a fixed per-line buffer size in the linker.
rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
}
tool("stamp") {
win_stamp_path = rebase_path("win_stamp.py")
command = "python $win_stamp_path {{output}}"
}
}
toolchain("gcc_like") {
lib_switch = "-l"
lib_dir_switch = "-L"
tool("cc") {
depfile = "{{output}}.d"
command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
depsformat = "gcc"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
]
description = "$cc_wrapper $cc ... -o {{output}}"
}
tool("cxx") {
depfile = "{{output}}.d"
command = "$cc_wrapper $cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
depsformat = "gcc"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
]
description = "$cc_wrapper $cxx ... -o {{output}}"
}
tool("asm") {
depfile = "{{output}}.d"
command = "$cc_wrapper $cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
depsformat = "gcc"
outputs = [
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
]
description = "$cc_wrapper $cc ... -o {{output}}"
}
tool("alink") {
command = "rm -f {{output}} && $ar rcs {{output}} {{inputs}}"
outputs = [
"{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
]
default_output_extension = ".a"
output_prefix = "lib"
description = "$ar {{output}} ..."
}
tool("solink") {
soname = "{{target_output_name}}{{output_extension}}"
rpath = "-Wl,-soname,$soname"
if (is_mac) {
rpath = "-Wl,-install_name,@rpath/$soname"
}
command = "$cc_wrapper $cxx -shared {{ldflags}} {{inputs}} {{solibs}} {{libs}} $rpath -o {{output}}"
outputs = [
"{{root_out_dir}}/$soname",
]
output_prefix = "lib"
default_output_extension = ".so"
description = "$cc_wrapper $cxx -shared ... -o {{output}}"
}
tool("link") {
command = "$cc_wrapper $cxx {{ldflags}} {{inputs}} {{solibs}} {{libs}} -o {{output}}"
outputs = [
"{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
]
description = "$cc_wrapper $cxx ... -o {{output}}"
}
tool("stamp") {
command = "touch {{output}}"
}
tool("copy") {
command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
}
}