blob: 7e09ba04f900d8db8bb23efcd47638eba9ace105 [file] [log] [blame]
# Copyright 2019 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.
import("//build/toolchain/ccache.gni")
config("cobalt_standalone") {
defines = [ "HAVE_GLOG" ]
}
config("no_rtti") {
cflags_cc = [ "-fno-rtti" ]
cflags_objcc = cflags_cc
}
config("no_exceptions") {
cflags_cc = [ "-fno-exceptions" ]
cflags_objcc = cflags_cc
}
config("warn_implicit_fallthrough") {
cflags = [ "-Wimplicit-fallthrough" ]
}
config("symbol_visibility_hidden") {
# Disable libc++ visibility annotations to make sure that the compiler option
# has effect on symbols defined in libc++ headers. Note that we don't want to
# disable these annotations altogether to ensure that our toolchain is usable
# outside of our build since not every user uses hidden visibility by default.
defines = [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ]
cflags = [ "-fvisibility=hidden" ]
}
config("shared_library_config") {
cflags = []
if (current_os == "linux") {
cflags += [ "-fPIC" ]
}
}
config("compiler") {
asmflags = []
cflags = [ "-fcolor-diagnostics" ]
cflags_c = []
cflags_cc = [ "-fvisibility-inlines-hidden" ]
cflags_objc = []
cflags_objcc = [ "-fvisibility-inlines-hidden" ]
ldflags = []
defines = []
configs = []
if (current_os == "fuchsia") {
configs += [ "//build/config/fuchsia:compiler" ]
} else {
cflags_c += [ "-std=c11" ]
cflags_cc += [
"-std=c++17",
"-stdlib=libc++",
]
if (current_os == "linux") {
configs += [ "//build/config/linux:compiler" ]
} else if (current_os == "mac") {
configs += [ "//build/config/mac:compiler" ]
}
}
# Linker on macOS does not support `color-diagnostics`
if (current_os != "mac") {
ldflags += [ "-Wl,--color-diagnostics" ]
}
asmflags += cflags
asmflags += cflags_c
}
config("debug") {
cflags = [ "-O0" ]
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("default_include_dirs") {
include_dirs = [
"//",
"//sysroot/include",
root_gen_dir,
]
}
config("executable_ldconfig") {
ldflags = [
"-Wl,-rpath=\$ORIGIN/",
"-Wl,-rpath-link=",
]
}
config("default_warnings") {
cflags = [
"-Wall",
"-Wextra",
"-Wnewline-eof",
"-Wno-unused-parameter",
]
}
# TODO(fxb/58162): delete once nothing is referencing this.
config("Wno-conversion") {
cflags = [ "-Wno-conversion" ]
}
config("werror") {
# ccache, at least in some configurations, caches preprocessed content. This
# means that by the time the compiler sees it, macros are unrolled. A number
# of gcc and clang diagnostics are conditioned on whether the source is part
# of a macro or not. This is because a "reasonable" looking macro invocation
# may end up doing something silly internally. This can mean self assignment
# and tautological comparisons, since macros are not typed. Macros also tend
# to over-parenthesize, and so on. This particular list of options was found
# via trial and error, and might be the best way of keeping the build quiet.
if (!use_ccache) {
cflags = [
"-Werror",
# Declarations marked as deprecated should not cause build failures,
# rather they should emit warnings to notify developers about the use of
# deprecated interfaces.
"-Wno-error=deprecated-declarations",
# Do not add additional -Wno-error to this config.
]
}
}