-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBUILDCONFIG.gn
268 lines (233 loc) · 7.87 KB
/
BUILDCONFIG.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# 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() {
# The OS build is running on.
OS = ""
# Specifies pkg-config program to retrieve information about packages.
pkg_config = ""
# The logical root directory for headers and libraries.
# Trailing slash should not be added (except root path).
sysroot = ""
# The libdir of the target board. e.g. /usr/lib64
libdir = ""
# The path to the directory where build artifacts are located.
build_root = ""
# The path to src/platform2.
platform2_root = ""
# Libbase revision number read from BASE_VER variable or file.
libbase_ver = ""
# Set true to allow C++ code to use exceptions.
enable_exceptions = false
# Set true if clang is used for C compiler.
clang_cc = false
# Set true if clang is used for C++ compiler.
clang_cxx = false
# Additional flags for C compiler.
external_cflags = []
# Additional flags for C++ compiler.
external_cxxflags = []
# Additional flags for C and C++ preprocessor.
external_cppflags = []
# Additional flags for C and C++ linker.
external_ldflags = []
# Set this to true if you want to activate the debug mode.
is_debug = false
# Subdir in platform2 where the package is located.
# TODO(oka): This value is public because it is used in ap/ package for common
# targets to use different default flags based on the package to be built.
# This is hacky, so remove such usages and move this variable back to
# gn_root/BUILD.gn .
platform_subdir = ""
}
import("//common-mk/use.gni")
assert(pkg_config != "", "pkg-config script path must be set")
assert(libbase_ver != -1, "libbase_ver must be set")
assert(libdir != "", "libdir must be set")
if (target_os == "") {
target_os = host_os
}
if (target_cpu == "") {
target_cpu = host_cpu
}
if (current_cpu == "") {
current_cpu = target_cpu
}
if (current_os == "") {
current_os = target_os
}
# Practically sysroot is used as a prefix of paths, e.g.
# "${sysroot}/usr/include". If sysroot is root (= "/"), it will be
# "//usr/include". However, in GN, paths starting with "//" represents the path
# to the GN root, rather than the file system root, which is unexpected.
# To support that case, replace sysroot with "/.", if sysroot is "/".
if (sysroot == "/") {
sysroot = "/."
}
# All binary targets will get this list of configs by default.
_binary_target_configs = [ "//common-mk:compiler_defaults" ]
if (!enable_exceptions) {
_binary_target_configs += [ "//common-mk:no_exceptions" ]
}
if (!clang_cc) {
_binary_target_configs += [ "//common-mk:gcc_cflags_c" ]
}
if (!clang_cxx) {
_binary_target_configs += [ "//common-mk:gcc_cflags_cc" ]
}
set_defaults("executable") {
configs = _binary_target_configs
configs += [ "//common-mk:pie" ]
}
set_defaults("static_library") {
configs = _binary_target_configs
configs += [
"//common-mk:pie",
"//common-mk:use_thin_archive",
]
}
set_defaults("shared_library") {
configs = _binary_target_configs
configs += [ "//common-mk:pic" ]
}
set_defaults("source_set") {
configs = _binary_target_configs
}
set_default_toolchain("//common-mk/toolchain")
# In Chrome OS, pkg-config is commonly and widely used.
# It is not natively supported by GN. Instead, here a few special fields are
# injected to the executable, shared_library and static_library targets
# to support pkg-config.
# src_install and src_test settings are also written in the same way.
#
# Args:
# pkg_deps(optional): A list of package names to be depend.
# A corresponding config is created, and then injected to |configs|.
# public_pkg_deps(optional): Similart to pkg_deps, but injected to
# |public_configs| instead.
# all_dependent_pkg_deps(optional): Similar to pkg_deps, but injected to
# |all_dependent_configs|.
# run_test(optional): A boolean if this is a unittest program that should be
# automatically run. A corresponding metadata is injected to itself.
# test_config(optional): A scope of configs for tests.
# A corresponding metadata is injected to itself.
# install_path(optional): A path to install into.
# A corresponding group is created, and then injected to |deps|.
import("//common-mk/install_config.gni")
import("//common-mk/pkg_config.gni")
template("_generate_config_rule") {
if (defined(invoker.pkg_deps) && invoker.pkg_deps != []) {
_pkg_deps_name = "_${target_name}-pkg_deps-config"
pkg_config(_pkg_deps_name) {
pkg_deps = invoker.pkg_deps
}
}
if (defined(invoker.public_pkg_deps) && invoker.public_pkg_deps != []) {
_public_pkg_deps_name = "_${target_name}-public_pkg_deps-config"
pkg_config(_public_pkg_deps_name) {
pkg_deps = invoker.public_pkg_deps
}
}
if (defined(invoker.all_dependent_pkg_deps) &&
invoker.all_dependent_pkg_deps != []) {
_all_dependent_pkg_deps_name =
"_${target_name}-all_dependent_pkg_deps-config"
pkg_config(_all_dependent_pkg_deps_name) {
pkg_deps = invoker.all_dependent_pkg_deps
}
}
if (defined(invoker.install_path)) {
_install_config_name = "_${target_name}-install_config"
source_name = invoker.target_name
if (defined(invoker.output_name)) {
source_name = invoker.output_name
}
source_dir = invoker.root_build_dir
if (defined(invoker.output_dir)) {
source_dir = invoker.output_dir
}
install_config(_install_config_name) {
if (defined(invoker.target_type)) {
type = invoker.target_type
}
if (invoker.target_type == "shared_library") {
sources = [ "${source_dir}/lib/${source_name}.so" ]
} else if (invoker.target_type == "static_library") {
sources = [ "${source_dir}/${source_name}.a" ]
} else {
sources = [ "${source_dir}/${source_name}" ]
}
install_path = invoker.install_path
}
}
target(invoker.target_type, target_name) {
forward_variables_from(invoker,
"*",
[
"all_dependent_pkg_deps",
"install_path",
"metadata",
"pkg_deps",
"public_pkg_deps",
"run_test",
"target_type",
"test_config",
])
if (defined(_pkg_deps_name)) {
if (!defined(configs)) {
configs = []
}
configs += [ ":${_pkg_deps_name}" ]
}
if (defined(_public_pkg_deps_name)) {
if (!defined(public_configs)) {
public_configs = []
}
public_configs += [ ":${_public_pkg_deps_name}" ]
}
if (defined(_all_dependent_pkg_deps_name)) {
if (!defined(all_dependent_configs)) {
all_dependent_configs = []
}
all_dependent_configs += [ ":${_all_dependent_pkg_deps_name}" ]
}
if (defined(_install_config_name)) {
if (!defined(deps)) {
deps = []
}
deps += [ ":${_install_config_name}" ]
}
_run_test = defined(invoker.run_test) && invoker.run_test
if (defined(invoker.metadata) || _run_test) {
metadata = {
if (defined(invoker.metadata)) {
forward_variables_from(invoker.metadata, "*")
}
if (_run_test) {
_run_test = [ true ]
if (defined(invoker.test_config)) {
_test_config = [ invoker.test_config ]
}
}
}
}
}
}
template("executable") {
_generate_config_rule(target_name) {
forward_variables_from(invoker, "*")
target_type = "executable"
}
}
template("shared_library") {
_generate_config_rule(target_name) {
forward_variables_from(invoker, "*")
target_type = "shared_library"
}
}
template("static_library") {
_generate_config_rule(target_name) {
forward_variables_from(invoker, "*")
target_type = "static_library"
}
}