blob: ef7f9a1b53908b5bd807332b51b31a9804d83e6a [file] [log] [blame]
# Copyright 2016 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
declare_args() {
# Use ThinLTO variant of LTO if use_lto = true.
use_thinlto = true
# Number of parallel ThinLTO jobs.
thinlto_jobs = 8
}
config("compiler") {
asmflags = []
cflags = []
cflags_c = []
cflags_cc = [ "-fvisibility-inlines-hidden" ]
cflags_objc = []
cflags_objcc = [ "-fvisibility-inlines-hidden" ]
ldflags = []
defines = []
configs = []
if (is_debug) {
cflags += [ "-g" ]
}
if (current_os == "fuchsia") {
configs += [ "//build/config/fuchsia:compiler" ]
} else {
cflags_c += [ "-std=c11" ]
cflags_cc += [
"-std=c++14",
"-stdlib=libc++",
]
if (current_os == "linux") {
configs += [ "//build/config/linux:compiler" ]
} else if (current_os == "mac") {
configs += [ "//build/config/mac:compiler" ]
}
}
asmflags += cflags
asmflags += cflags_c
}
config("lto") {
if (use_thinlto) {
cflags = [ "-flto=thin" ]
ldflags = cflags + [
# ThinLTO driver launches number of threads in parallel whose
# number is by default equivalent to the number of cores. We
# need to limit the parallelism to avoid aggressive competition
# between different linker jobs.
"-Wl,--thinlto-jobs=$thinlto_jobs",
# Set ThinLTO cache directory which is used to cache native
# object files for ThinLTO incremental builds. This directory
# is not managed by Ninja and has to be cleaned manually.
"-Wl,--thinlto-cache-dir=" +
rebase_path("$root_out_dir/thinlto-cache", root_build_dir),
]
} else {
cflags = [
"-flto",
# Enable whole-program devirtualization and virtual constant propagation.
"-fwhole-program-vtables",
]
ldflags = cflags
}
}
config("relative_paths") {
# Make builds independent of absolute file path.
absolute_path = rebase_path("//.")
cflags = [
"-no-canonical-prefixes",
"-fdebug-prefix-map=$absolute_path=.",
]
}
config("debug") {
cflags = [
"-g",
"-Og",
]
ldflags = cflags
}
config("release") {
defines = [ "NDEBUG=1" ]
cflags = [
"-O3",
"-fdata-sections",
"-ffunction-sections",
]
ldflags = cflags
if (current_os == "mac") {
ldflags += [ "-Wl,-dead_strip" ]
} else {
ldflags += [ "-Wl,--gc-sections" ]
}
}
config("no_exceptions") {
cflags_cc = [ "-fno-exceptions" ]
cflags_objcc = cflags_cc
}
config("no_rtti") {
cflags_cc = [ "-fno-rtti" ]
cflags_objcc = cflags_cc
}
config("default_include_dirs") {
include_dirs = [
"//",
root_gen_dir,
]
}
config("default_warnings") {
cflags = [
"-Wall",
"-Wextra",
"-Wno-unused-parameter",
]
if (current_os == "fuchsia") {
cflags += [
# TODO(TO-99): Remove once all the cases of unused 'this' lamda capture
# have been removed from our codebase.
"-Wno-unused-lambda-capture",
# TODO(TO-100): Remove once comparator types provide const call operator.
"-Wno-user-defined-warnings",
]
}
}
config("symbol_visibility_hidden") {
cflags = [ "-fvisibility=hidden" ]
}
config("symbol_no_undefined") {
if (current_os == "mac") {
ldflags = [ "-Wl,-undefined,error" ]
} else {
ldflags = [ "-Wl,--no-undefined" ]
}
}
config("shared_library_config") {
configs = []
cflags = []
if (current_os == "fuchsia") {
configs += [ "//build/config/fuchsia:shared_library_config" ]
} else if (current_os == "linux") {
cflags += [ "-fPIC" ]
} else if (current_os == "mac") {
configs += [ "//build/config/mac:mac_dynamic_flags" ]
}
}
config("executable_config") {
configs = []
if (current_os == "fuchsia") {
configs += [
"//build/config/fuchsia:executable_config",
"//build/config/fuchsia:mxio_config",
]
} else if (current_os == "mac") {
configs += [
"//build/config/mac:mac_dynamic_flags",
"//build/config/mac:mac_executable_flags",
]
}
}
config("default_libs") {
configs = []
if (current_os == "mac") {
configs += [ "//build/config/mac:default_libs" ]
}
}