forked from OSchip/llvm-project
301 lines
7.6 KiB
Plaintext
301 lines
7.6 KiB
Plaintext
import("//llvm/utils/gn/build/buildflags.gni")
|
|
import("//llvm/utils/gn/build/mac_sdk.gni")
|
|
import("//llvm/utils/gn/build/toolchain/compiler.gni")
|
|
import("//llvm/utils/gn/build/toolchain/target_flags.gni")
|
|
|
|
declare_args() {
|
|
# Whether to build everything with coverage information.
|
|
# After building with this, run tests and then run
|
|
# llvm/utils/prepare-code-coverage-artifact.py \
|
|
# .../llvm-profdata .../llvm-cov out/gn/profiles/ report/ \
|
|
# out/gn/bin/llvm-undname ...`
|
|
# to generate a HTML report for the binaries passed in the last line.
|
|
llvm_build_instrumented_coverage = false
|
|
|
|
# If set, puts relative paths in debug info.
|
|
# Makes the build output independent of the build directory, but makes
|
|
# most debuggers harder to use. See "Getting to local determinism" and
|
|
# "Getting debuggers to work well with locally deterministic builds" in
|
|
# http://blog.llvm.org/2019/11/deterministic-builds-with-clang-and-lld.html
|
|
# for more information.
|
|
use_relative_paths_in_debug_info = false
|
|
|
|
# The version of host gcc. Ignored if is_clang is true.
|
|
gcc_version = 9
|
|
}
|
|
|
|
assert(!llvm_build_instrumented_coverage || is_clang,
|
|
"llvm_build_instrumented_coverage requires clang as host compiler")
|
|
|
|
config("compiler_defaults") {
|
|
defines = []
|
|
|
|
if (!llvm_enable_assertions) {
|
|
defines += [ "NDEBUG" ]
|
|
}
|
|
|
|
if (llvm_enable_expensive_checks) {
|
|
defines += [ "EXPENSIVE_CHECKS" ]
|
|
}
|
|
|
|
asmflags = target_flags
|
|
cflags = target_flags
|
|
ldflags = target_flags + target_ldflags
|
|
|
|
if (host_os == "mac" && clang_base_path != "") {
|
|
cflags += [
|
|
"-isysroot",
|
|
mac_sdk_path,
|
|
]
|
|
ldflags += [
|
|
"-isysroot",
|
|
mac_sdk_path,
|
|
]
|
|
}
|
|
|
|
if (host_os != "win") {
|
|
if (is_debug) {
|
|
cflags += [ "-g" ]
|
|
}
|
|
if (is_optimized) {
|
|
cflags += [ "-O3" ]
|
|
}
|
|
cflags += [ "-fdiagnostics-color" ]
|
|
if (use_lld) {
|
|
ldflags += [ "-Wl,--color-diagnostics" ]
|
|
}
|
|
cflags_cc = [
|
|
"-std=c++14",
|
|
"-fvisibility-inlines-hidden",
|
|
]
|
|
} else {
|
|
if (is_debug) {
|
|
cflags += [
|
|
"/Zi",
|
|
"/FS",
|
|
]
|
|
ldflags += [ "/DEBUG" ]
|
|
|
|
# Speed up links with ghash on windows.
|
|
if (use_lld && is_clang) {
|
|
cflags += [ "-gcodeview-ghash" ]
|
|
ldflags += [ "/DEBUG:GHASH" ]
|
|
}
|
|
}
|
|
if (is_optimized) {
|
|
cflags += [
|
|
"/O2",
|
|
"/Gw",
|
|
"/Zc:inline",
|
|
]
|
|
ldflags += [
|
|
"/OPT:REF",
|
|
"/OPT:ICF",
|
|
]
|
|
}
|
|
defines += [
|
|
"_CRT_SECURE_NO_DEPRECATE",
|
|
"_CRT_SECURE_NO_WARNINGS",
|
|
"_CRT_NONSTDC_NO_DEPRECATE",
|
|
"_CRT_NONSTDC_NO_WARNINGS",
|
|
"_SCL_SECURE_NO_DEPRECATE",
|
|
"_SCL_SECURE_NO_WARNINGS",
|
|
|
|
"_HAS_EXCEPTIONS=0",
|
|
"_UNICODE",
|
|
"UNICODE",
|
|
]
|
|
cflags += [ "/EHs-c-" ]
|
|
|
|
# The MSVC default value (1 MB) is not enough for parsing recursive C++
|
|
# templates in Clang.
|
|
ldflags += [ "/STACK:10000000" ]
|
|
}
|
|
|
|
# Warning setup.
|
|
if (host_os == "win" && !is_clang) {
|
|
cflags += [
|
|
# Suppress ''modifier' : used more than once' (__forceinline and inline).
|
|
"-wd4141",
|
|
|
|
# Suppress 'conversion from 'type1' to 'type2', possible loss of data'.
|
|
"-wd4244",
|
|
|
|
# Suppress 'conversion from 'size_t' to 'type', possible loss of data'.
|
|
"-wd4267",
|
|
|
|
# Suppress 'no matching operator delete found'.
|
|
"-wd4291",
|
|
|
|
# Suppress 'noexcept used with no exception handling mode specified'.
|
|
"-wd4577",
|
|
|
|
# Suppress 'destructor was implicitly defined as deleted'.
|
|
"-wd4624",
|
|
|
|
# Suppress 'unsafe mix of type <type> and type <type> in operation'.
|
|
"-wd4805",
|
|
]
|
|
} else {
|
|
if (host_os == "win") {
|
|
cflags += [ "/W4" ]
|
|
} else {
|
|
cflags += [
|
|
"-Wall",
|
|
"-Wextra",
|
|
]
|
|
}
|
|
cflags += [ "-Wno-unused-parameter" ]
|
|
if (is_clang) {
|
|
cflags += [
|
|
"-Wdelete-non-virtual-dtor",
|
|
"-Wstring-conversion",
|
|
]
|
|
} else {
|
|
cflags += [
|
|
# GCC's -Wcomment complains about // comments ending with '\' if the
|
|
# next line is also a // comment.
|
|
"-Wno-comment",
|
|
|
|
# Disable gcc's potentially uninitialized use analysis as it presents
|
|
# lots of false positives.
|
|
"-Wno-maybe-uninitialized",
|
|
]
|
|
cflags_cc += [
|
|
# The LLVM libraries have no stable C++ API, so -Wnoexcept-type is not
|
|
# useful.
|
|
"-Wno-noexcept-type",
|
|
]
|
|
if (gcc_version >= 8) {
|
|
cflags_cc += [
|
|
# Disable -Wclass-memaccess, a C++-only warning from GCC 8 that fires
|
|
# on LLVM's ADT classes.
|
|
"-Wno-class-memaccess",
|
|
]
|
|
}
|
|
if (gcc_version >= 9) {
|
|
cflags_cc += [
|
|
# Disable -Wredundant-move on GCC>=9. GCC wants to remove std::move
|
|
# in code like "A foo(ConvertibleToA a) { return std::move(a); }",
|
|
# but this code does not compile (or uses the copy constructor
|
|
# instead) on clang<=3.8. Clang also has a -Wredundant-move, but it
|
|
# only fires when the types match exactly, so we can keep it here.
|
|
"-Wno-redundant-move",
|
|
]
|
|
}
|
|
}
|
|
if (is_clang && use_goma) {
|
|
# goma converts all paths to lowercase on the server, breaking this
|
|
# warning.
|
|
cflags += [ "-Wno-nonportable-include-path" ]
|
|
}
|
|
}
|
|
|
|
# On Windows, the linker is not invoked through the compiler driver.
|
|
if (use_lld && host_os != "win") {
|
|
ldflags += [ "-fuse-ld=lld" ]
|
|
}
|
|
|
|
if (llvm_build_instrumented_coverage) {
|
|
cflags += [
|
|
"-fcoverage-mapping",
|
|
|
|
# Using an absolute path here is lame, but it's used at test execution
|
|
# time to generate the profiles, and lit doesn't specify a fixed folder
|
|
# for test execution -- so this is the only way to get all profiles into
|
|
# a single folder like llvm/utils/prepare-code-coverage-artifact.py
|
|
# expects.
|
|
"-fprofile-instr-generate=" +
|
|
rebase_path("$root_build_dir/profiles/%4m.profraw"),
|
|
]
|
|
ldflags += [ "-fprofile-instr-generate" ]
|
|
}
|
|
|
|
# Deterministic build setup, see
|
|
# http://blog.llvm.org/2019/11/deterministic-builds-with-clang-and-lld.html
|
|
if (current_os == "win") {
|
|
ldflags += [ "/pdbaltpath:%_PDB%" ]
|
|
}
|
|
if (is_clang) {
|
|
cflags += [
|
|
"-no-canonical-prefixes",
|
|
"-Werror=date-time",
|
|
]
|
|
if (current_os == "win") {
|
|
cflags += [ "-fmsc-version=1916" ]
|
|
if (use_lld) {
|
|
cflags += [ "/Brepro" ]
|
|
ldflags += [ "/Brepro" ]
|
|
}
|
|
}
|
|
if (use_relative_paths_in_debug_info) {
|
|
cflags += [
|
|
"-fdebug-compilation-dir",
|
|
".",
|
|
]
|
|
}
|
|
}
|
|
}
|
|
|
|
config("no_exceptions") {
|
|
if (host_os != "win") {
|
|
cflags_cc = [ "-fno-exceptions" ]
|
|
}
|
|
}
|
|
|
|
config("no_rtti") {
|
|
if (current_os == "win") {
|
|
cflags_cc = [ "/GR-" ]
|
|
} else {
|
|
cflags_cc = [ "-fno-rtti" ]
|
|
}
|
|
}
|
|
|
|
# To make an archive that can be distributed, you need to remove this config and
|
|
# set complete_static_lib.
|
|
config("thin_archive") {
|
|
if (current_os != "win" && current_os != "mac") {
|
|
arflags = [ "-T" ]
|
|
}
|
|
}
|
|
|
|
config("llvm_code") {
|
|
include_dirs = [
|
|
"//llvm/include",
|
|
"$root_gen_dir/llvm/include",
|
|
]
|
|
}
|
|
|
|
config("lld_code") {
|
|
include_dirs = [
|
|
"//lld/include",
|
|
"$root_gen_dir/lld/include",
|
|
]
|
|
}
|
|
|
|
config("clang_code") {
|
|
if (host_os != "win") {
|
|
cflags = [ "-fno-strict-aliasing" ]
|
|
}
|
|
include_dirs = [
|
|
"//clang/include",
|
|
"$root_gen_dir/clang/include",
|
|
]
|
|
}
|
|
|
|
config("crt_code") {
|
|
include_dirs = [ "//compiler-rt/lib" ]
|
|
cflags = [
|
|
"-fPIC",
|
|
"-funwind-tables",
|
|
"-gline-tables-only",
|
|
"-fvisibility=hidden",
|
|
]
|
|
}
|
|
|
|
config("warn_covered_switch_default") {
|
|
if (is_clang) {
|
|
cflags = [ "-Wcovered-switch-default" ]
|
|
}
|
|
}
|