-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBUILD.gn
193 lines (171 loc) · 5.63 KB
/
BUILD.gn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# 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",
]
}