blob: f50968f914fbbec0e3553c61d7155ccd7ddb52ab [file] [log] [blame]
# Copyright 2018 The Chromium OS 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() {
# Set this to false if you'd like to disable -Werror.
enable_werror = true
# Set this to false if you want to disable Large File Support (LFS).
enable_lfs = true
}
_cflags_no_exceptions = [
"-fno-exceptions",
"-fno-unwind-tables",
"-fno-asynchronous-unwind-tables",
]
config("no_exceptions") {
cflags_cc = _cflags_no_exceptions
cflags_c = _cflags_no_exceptions
}
# Symbol visibility is set to be internal by default. Add this to your target's
# configs to make its symbols visible.
# Setting "-fvisibility=default" directly in your target's cflags doesn't work
# because it will be overwritten by the "-fvisibility=internal" in the
# compiler_defaults' cflags.
config("visibility_default") {
cflags = [ "-fvisibility=default" ]
}
config("compiler_defaults") {
defines = []
libs = []
include_dirs = [
"${root_gen_dir}/include",
"${platform2_root}",
]
cflags = [
"-Wall",
"-Wno-psabi",
"-Wunused",
"-Wno-unused-parameter",
"-ggdb3",
"-fstack-protector-strong",
"-Wformat=2",
"-fvisibility=internal",
"-Wa,--noexecstack",
]
cflags_c = [ "-std=gnu11" ] + external_cppflags + external_cxxflags
cflags_cc = [ "-std=gnu++14" ] + external_cppflags + external_cxxflags
ldflags = external_ldflags + [
"-Wl,-z,relro",
"-Wl,-z,noexecstack",
"-Wl,-z,now",
"-Wl,--as-needed",
]
if (enable_werror) {
cflags += [ "-Werror" ]
}
if (use.cros_host) {
defines += [ "NDEBUG" ]
}
if (enable_lfs) {
defines += [
# Enable support for new LFS funcs (ftello/etc...).
"_LARGEFILE_SOURCE",
# Enable support for 64bit variants (off64_t/fseeko64/etc...).
"_LARGEFILE64_SOURCE",
# Default to 64bit variants (off_t is defined as off64_t).
"_FILE_OFFSET_BITS=64",
]
}
# Remove no_exceptions flags given as arguments making the config pluggable.
# See BUILDCONFIG.gn.
cflags_cc -= _cflags_no_exceptions
cflags_c -= _cflags_no_exceptions
if (!use.cros_host) {
include_dirs += [ "${sysroot}/usr/include" ]
cflags += [ "--sysroot=${sysroot}" ]
ldflags += [ "--sysroot=${sysroot}" ]
}
if (use.profiling) {
cflags += [
"-fprofile-instr-generate",
"-fcoverage-mapping",
]
ldflags += [
"-fprofile-instr-generate",
"-fcoverage-mapping",
]
}
if (use.tcmalloc) {
libs += [ "-ltcmalloc" ]
}
}
# Generates position independent executable.
# This is a default config for executables and static libraries.
config("pie") {
cflags = [ "-fPIE" ]
# ldflags are not pushed to dependents, so applying ldflags to source sets or
# static libraries will be a no-op. You can just remove "pie" config from an
# executable to make the executable not position independent.
ldflags = [ "-pie" ]
}
# Use thin archive. It makes sense only for static libraries.
# This is a default config for static libraries.
config("use_thin_archive") {
arflags = [ "rcsT" ]
}
# Generates position independent code.
# This is a default config for shared libraries.
config("pic") {
cflags = [ "-fPIC" ]
}
if (use.test) {
# This config should be at the top in the configs list, especially before
# the config for libchrome-${libbase-ver} to avoid weird heap-buffer-overflow
# error from happening when ASAN is enabled.
# TODO(crbug.com/887845): Remove this note after library order issue is resolved.
config("test") {
libs = []
# Don't worry about overlinking, ld.gold's --as-needed will
# deal with that.
libs += exec_script("//common-mk/args_generator_wrapper.py",
[
"gtest-config",
"--libs",
],
"list lines")
libs += exec_script("//common-mk/args_generator_wrapper.py",
[
"gmock-config",
"--libs",
],
"list lines")
}
}