blob: da13d120df6193e268db9c6fde208eb73c7394c8 [file] [log] [blame] [edit]
# 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
}
_gcc_cflags = [ "-Wno-psabi" ]
config("gcc_cflags_c") {
cflags_c = _gcc_cflags
}
config("gcc_cflags_cc") {
cflags_cc = _gcc_cflags
}
# Note: DO NOT USE THIS. Use brillo/brillo_export.h instead to export symbols.
#
# 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") {
# gnlint: disable=GnLintVisibilityFlags
cflags = [ "-fvisibility=default" ]
}
config("compiler_defaults") {
defines = []
libs = []
include_dirs = [
"${root_gen_dir}/include",
"${platform2_root}",
]
cflags = [
"-Wall",
"-Wunused",
"-Wbool-operation",
"-Wfree-nonheap-object",
"-Wint-in-bool-context",
"-Wstring-compare",
"-Wstring-plus-int",
"-Wxor-used-as-pow",
# We use C99 array designators in C++ code. Our compilers support this
# extension since C++ has no equivalent yet (as of C++20).
"-Wno-c99-designator",
"-Wno-unused-parameter",
"-Wunreachable-code",
"-Wunreachable-code-return",
"-ggdb3",
"-fstack-protector-strong",
"-Wformat=2",
"-fvisibility=internal",
"-Wa,--noexecstack",
"-Wimplicit-fallthrough",
]
cflags_c = [ "-std=gnu11" ] + external_cppflags + external_cxxflags
cflags_cc = [ "-std=gnu++17" ] + 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",
]
}
# We only rely on `enable_exceptions` arg to control no_exceptions flags
# (see BUILDCONFIG.gn) and ignore if the given external flags contain these
# flags. As removing non-existing flags causes error on GN, we add them before
# its removal to unconditionally remove them.
cflags_cc += _cflags_no_exceptions
cflags_c += _cflags_no_exceptions
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 += [ "tcmalloc" ]
}
}
# 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.
# Remove this and add ":nouse_thin_archive" to unuse thin archive.
config("use_thin_archive") {
arflags = [ "rcsT" ]
}
# Don't use thin archive. It makes sense only for static libraries.
config("nouse_thin_archive") {
arflags = [ "rcs" ]
}
# Generates position independent code.
# This is a default config for shared libraries.
config("pic") {
cflags = [ "-fPIC" ]
}
# 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") {
# Don't worry about overlinking, ld.gold's --as-needed will
# deal with that.
# TODO(crbug.com/912432): Consider use {gtest,gmock}-config --ldflags.
# '--ldflags' is not used here. It adds, e.g., -L/usr/lib64,
# so the test executable will be linked against host libraries if exists.
# Specifically, libchrome for host is linked. For host, it is built with
# -DNDEBUG, but the target built without, which causes a link error.
# cf) BaseInitLoggingImpl definition in
# aosp/external/libchrome/base/logging.h
# gtest-config and gmock-config are not installed by gtest-1.8.1.
ldflags = [
"-pthread",
# Allow unit tests of a shared library to link against the depended .so
# under the output directory, instead of the ones installed in the system
# dir. -rpath and -rpath-link has higher priority than the system library
# directory.
"-Wl,-rpath=\$ORIGIN/lib/",
"-Wl,-rpath-link=lib/",
]
# gnlint: disable=GnLintCommonTesting
libs = [
"gmock",
"gtest",
"pthread",
]
}