blob: a6455efbe75fa6c107f7a2c117381e381dab66dd [file] [log] [blame]
Primiano Tucciae2879e2017-09-27 11:02:09 +09001# Copyright (C) 2017 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Primiano Tucci69132a12020-02-07 22:33:06 +000015import("//gn/perfetto_check_build_deps.gni")
Primiano Tucci7a40e4d2017-12-06 09:51:09 +000016import("//gn/standalone/android.gni")
Primiano Tucci2f811552020-12-07 16:48:22 +010017import("//gn/standalone/libc++/libc++.gni")
Primiano Tucci7a40e4d2017-12-06 09:51:09 +000018import("//gn/standalone/sanitizers/sanitizers.gni")
Primiano Tucci2f811552020-12-07 16:48:22 +010019import("//gn/standalone/toolchain/msvc.gni")
Primiano Tucci8b3feb42019-07-04 03:17:31 +010020import("//gn/standalone/wasm.gni")
Primiano Tucciae2879e2017-09-27 11:02:09 +090021
Primiano Tuccifbcfeeb2020-01-28 00:46:43 +000022# These warnings have been introduced with the newest version of clang (only in
23# the hermetic build) and are enabled just with -Werror.
Florian Mayer39e40d42020-07-16 14:52:07 +020024hermetic_clang_suppressions = [ "-Wno-c99-designator" ]
Primiano Tuccifbcfeeb2020-01-28 00:46:43 +000025
Primiano Tucci2f811552020-12-07 16:48:22 +010026# We deal with three toolchains here:
27# 1. Clang, used in most cases.
28# 2. GCC, used in some Linux cases.
29# 3. MSVC, used in some Windows cases.
30# Clang vs gcc is typically not a problem: both support roughly the same
31# switches. -Wno-unknown-warning-option fixes the mismatching ones.
32# The situation on Windows is a bit trickier: clang-cl.exe really pretends to be
33# cl.exe (MSVC), so we should use MSVC-style switches (e.g. /W2). However,
34# clang-cl.exe still supports some -Wclang-style-switches for flags that don't
35# have a corresponding version in MSVC.
36#
37# In the rules below, the conditionals should be interpreted as follows:
38# is_win -> can be either clang-cl.exe or cl.exe (MSVC). Only MSVC-style
39# switches (the common denominator) should be used.
40# is_clang -> could be clang-on-linux, clang-on-mac or clang-cl.exe.
41
Primiano Tucciae2879e2017-09-27 11:02:09 +090042config("extra_warnings") {
Primiano Tucci2f811552020-12-07 16:48:22 +010043 if (is_win) {
44 cflags = [
45 "/W2",
46 "/wd4244", # conversion from 'float' to 'int', possible loss of data
47 "/wd4267", # conversion from 'size_t' to 'int', possible loss of data
48 ]
49 if (is_clang) {
50 cflags += [
51 "-Wno-float-equal",
52 "-Wno-unused-macros",
53 "-Wno-old-style-cast",
54 ]
55 }
56 } else {
57 # Clang or Gcc. On linux, Android and Mac.
58 cflags = [
59 "-Wall",
60 "-Wextra",
61 "-Wpedantic",
62 ]
63 }
Primiano Tucci8a5b9a82018-12-28 13:18:21 +010064
Lalit Magantib4eaf212020-01-16 18:34:41 +000065 # Disable variadic macro warning as we make extensive use of them in trace
66 # processor and client API.
67 if (is_clang) {
Lalit Maganticf684cb2024-02-14 19:00:55 +000068 # Only enable -Weverything on hermetic clang as system clang might be quite
69 # out of date.
70 if (is_hermetic_clang && current_toolchain == host_toolchain &&
71 !is_fuzzer) {
Primiano Tucci2f811552020-12-07 16:48:22 +010072 # Disable Weverything on fuzzers to avoid breakages when new versions of
73 # clang are rolled into OSS-fuzz.
74 cflags += [ "-Weverything" ]
75 }
Primiano Tucciae2879e2017-09-27 11:02:09 +090076 cflags += [
Sami Kyostila3a946ae2017-09-29 14:56:36 +010077 "-Wno-c++98-compat-pedantic",
Primiano Tucci13331342017-10-25 17:08:13 +010078 "-Wno-c++98-compat",
Primiano Tucci4bdc4c42018-05-10 15:52:33 +010079 "-Wno-disabled-macro-expansion",
Primiano Tucci2f811552020-12-07 16:48:22 +010080 "-Wno-documentation-unknown-command",
Primiano Tucciae2879e2017-09-27 11:02:09 +090081 "-Wno-gnu-include-next",
82 "-Wno-gnu-statement-expression",
Primiano Tucci2f811552020-12-07 16:48:22 +010083 "-Wno-gnu-zero-variadic-macro-arguments",
Primiano Tucciae2879e2017-09-27 11:02:09 +090084 "-Wno-padded",
Primiano Tucci2f811552020-12-07 16:48:22 +010085 "-Wno-poison-system-directories",
Primiano Tucci6c75b642024-03-14 15:21:05 +000086 "-Wno-pre-c11-compat",
Primiano Tucciae2879e2017-09-27 11:02:09 +090087 "-Wno-reserved-id-macro",
Primiano Tucci8652a852021-09-08 14:56:19 +010088 "-Wno-reserved-identifier",
Manoj Guptae76dcfd2023-04-14 19:37:58 -070089 "-Wno-shadow-uncaptured-local",
Primiano Tucci91c4a412019-03-20 09:49:32 +000090 "-Wno-unknown-sanitizers",
Primiano Tuccif68444a2020-08-05 11:53:39 +020091 "-Wno-unknown-warning-option",
Anna Mayzner8e211f02023-02-06 16:59:12 +000092 "-Wno-unsafe-buffer-usage",
Primiano Tucci6f077022024-02-15 18:19:16 +000093
94 # TODO(primiano): -Wswitch-default could be useful but will require a mass
95 # codebase cleanup.
96 "-Wno-switch-default",
Primiano Tucciae2879e2017-09-27 11:02:09 +090097 ]
Kirill Timofeev6dd9c8b2024-11-01 00:41:20 +000098
99 if (perfetto_thread_safety_annotations) {
100 cflags += [
101 "-Wthread-safety",
102 "-Wno-thread-safety-negative",
103 ]
104 }
Ivan Chong88f5bd22024-06-26 14:48:26 +0000105 } else if (is_gcc) {
Primiano Tucci2f811552020-12-07 16:48:22 +0100106 # Use return std::move(...) for compatibility with old GCC compilers.
Daniele Di Proietto3b5b77c2022-06-20 11:05:17 +0100107 cflags_cc = [ "-Wno-redundant-move" ]
Lalit Maganti8e6f9f22022-11-03 00:56:16 +0000108
109 # Use after free detection in GCC is still not good enough: it still fails
110 # on very obvious false-positives in trace processor.
Daniele Di Proietto3b5b77c2022-06-20 11:05:17 +0100111 cflags_cc += [ "-Wno-use-after-free" ]
Lalit Maganti03f5a972023-03-27 17:08:15 +0100112
113 # GCC 7's handling of uninitialized std::optional is flaky at best and
114 # causes many false positives.
115 # TODO(lalitm): remove this when we upgrade to a GCC version which is good
116 # enough to handle this.
117 cflags_cc += [ "-Wno-maybe-uninitialized" ]
Lalit Magantiaf7ad1a2023-04-26 12:56:46 +0100118
119 # GCC's handling of detecting infinite recursion is flaky at best and
120 # causes some false positives.
121 # TODO(lalitm): remove this when we upgrade to a GCC version which is good
122 # enough to handle this.
123 cflags_cc += [ "-Wno-infinite-recursion" ]
124
125 # GCC's handling of detecting non null arguments is flaky at best and
126 # causes some false positives.
127 # TODO(lalitm): remove this when we upgrade to a GCC version which is good
128 # enough to handle this.
129 cflags_cc += [ "-Wno-nonnull" ]
Sami Kyostila2b626d92020-04-28 12:16:29 +0100130 }
Primiano Tucciae2879e2017-09-27 11:02:09 +0900131}
132
Primiano Tucci0825bc82017-09-28 18:50:23 +0100133config("no_exceptions") {
Primiano Tucci2f811552020-12-07 16:48:22 +0100134 # Exceptions are disabled by default on Windows (Use /EHsc to enable them).
135 if (!is_win) {
136 cflags_cc = [ "-fno-exceptions" ]
137 }
Primiano Tucci0825bc82017-09-28 18:50:23 +0100138}
139
140config("no_rtti") {
Primiano Tucci2f811552020-12-07 16:48:22 +0100141 if (is_win) {
142 cflags_cc = [ "/GR-" ]
143 } else {
144 cflags_cc = [ "-fno-rtti" ]
145 }
Primiano Tucci0825bc82017-09-28 18:50:23 +0100146}
147
Ryan Savitskie65c4052022-03-24 18:22:19 +0000148# Used in buildtools dependencies for standalone builds.
Florian Mayer475bd7e2018-08-07 20:04:03 +0100149config("c++17") {
Primiano Tucci2f811552020-12-07 16:48:22 +0100150 if (is_win) {
151 cflags_cc = [ "/std:c++17" ]
152 } else {
153 cflags_cc = [ "-std=c++17" ]
154 }
Florian Mayer475bd7e2018-08-07 20:04:03 +0100155}
156
Lalit Magantibdddf762022-11-02 20:23:03 +0000157# Used in buildtools dependencies for standalone builds.
158config("c++20") {
159 visibility = [ "//buildtools:libc++config" ]
160 if (is_win) {
161 cflags_cc = [ "/std:c++20" ]
162 } else {
163 cflags_cc = [ "-std=c++20" ]
164 }
165}
166
Primiano Tucci5aab7582017-12-07 12:22:03 +0000167config("visibility_hidden") {
Primiano Tucci2f811552020-12-07 16:48:22 +0100168 if (!is_win) {
169 cflags = [ "-fvisibility=hidden" ]
170 }
171}
172
173config("win32_lean_and_mean") {
174 if (is_win) {
175 defines = [ "WIN32_LEAN_AND_MEAN" ]
176 }
Primiano Tucci5aab7582017-12-07 12:22:03 +0000177}
178
Primiano Tucciae2879e2017-09-27 11:02:09 +0900179config("default") {
180 asmflags = []
181 cflags = []
182 cflags_c = []
183 cflags_cc = []
184 defines = []
Primiano Tucci2f811552020-12-07 16:48:22 +0100185 include_dirs = []
Primiano Tucciae2879e2017-09-27 11:02:09 +0900186 ldflags = []
187 libs = []
188
Primiano Tucci7e9865c2021-01-10 23:55:15 +0100189 if ((is_android || is_linux) && !is_wasm) {
Primiano Tucci0b3de742023-11-09 22:55:33 +0000190 ldflags += [
191 "-Wl,--build-id",
192 "-Wl,-z,max-page-size=16384",
193 ]
Florian Mayer5d016a52020-09-14 21:06:36 +0100194 }
195
Primiano Tucci2f811552020-12-07 16:48:22 +0100196 if (is_clang || !is_win) { # Clang or GCC, but not MSVC.
197 cflags += [
198 "-fstrict-aliasing",
199 "-Wformat",
200 ]
201 }
Primiano Tucciae2879e2017-09-27 11:02:09 +0900202
Daniele Di Proiettob9a246e2022-09-05 10:59:55 +0100203 if (is_clang && is_win) {
204 # clang-cl from version 16 does not like out-of-line definition of static
205 # constexpr, even in C++14 mode. Disable the deprecated warnings to work
206 # around the problem.
207 cflags += [ "-Wno-deprecated" ]
208 }
209
Primiano Tucci2f811552020-12-07 16:48:22 +0100210 if (is_win) {
211 cflags += [
212 "/bigobj", # Some of our files are bigger than the regular limits.
213 "/Gy", # Enable function-level linking.
Primiano Tucci5f3008e2021-05-19 21:34:45 +0100214 "/FS", # Preserve previous PDB behavior.
215 "/utf-8", # Assume UTF-8 by default to avoid code page dependencies.
Lalit Maganti03d178e2022-11-03 16:18:51 +0000216 "/Zc:__cplusplus", # Allow use of __cplusplus macro.
Primiano Tucci2f811552020-12-07 16:48:22 +0100217 ]
218 defines += [
219 "_CRT_NONSTDC_NO_WARNINGS",
220 "_CRT_SECURE_NO_DEPRECATE",
221 "_CRT_SECURE_NO_WARNINGS", # Disables warnings on some POSIX-compat API.
222 "_SCL_SECURE_NO_DEPRECATE",
223 "NOMINMAX",
224 ]
225 if (!use_custom_libcxx) {
226 defines += [ "_HAS_EXCEPTIONS=0" ] # Disables exceptions in MSVC STL.
227 }
Primiano Tucci7e9865c2021-01-10 23:55:15 +0100228 } else if (!is_wasm) { # !is_win
Primiano Tucci2f811552020-12-07 16:48:22 +0100229 cflags += [
230 "-g",
231 "-fPIC",
232 "-fstack-protector-strong",
233 ]
234 }
235
236 # Treat warnings as errors, but give up on fuzzer builds.
Florian Mayer7010f3a2019-09-09 10:48:12 +0100237 if (!is_fuzzer) {
Primiano Tucci2f811552020-12-07 16:48:22 +0100238 if (is_win) {
239 cflags += [ "/WX" ]
240 } else {
241 cflags += [ "-Werror" ]
242 }
Florian Mayer7010f3a2019-09-09 10:48:12 +0100243 }
244
Hector Dearman32c32ad2017-10-18 11:53:32 +0100245 if (is_clang) {
Primiano Tucci2f811552020-12-07 16:48:22 +0100246 cflags += [ "-fcolor-diagnostics" ]
247 if (!is_win) {
248 cflags += [ "-fdiagnostics-show-template-tree" ]
249 }
Hector Dearman32c32ad2017-10-18 11:53:32 +0100250 }
251
Primiano Tuccifbcfeeb2020-01-28 00:46:43 +0000252 if (is_hermetic_clang && is_linux && !is_wasm) {
253 cflags += hermetic_clang_suppressions
254 } else {
255 not_needed([ "hermetic_clang_suppressions" ])
256 }
257
Lalit Maganti735d1862022-11-07 11:56:17 +0000258 if (non_hermetic_clang_stdlib != "") {
259 if (is_clang && !is_hermetic_clang && !is_wasm) {
260 cflags_cc += [ "-stdlib=" + non_hermetic_clang_stdlib ]
261 ldflags += [ "-stdlib=" + non_hermetic_clang_stdlib ]
262 }
Lalit Maganti4e1484b2022-11-03 13:33:49 +0000263 }
264
Primiano Tucci8c3f40a2018-09-01 08:31:50 +0200265 if (is_lto) {
266 cflags += [ "-flto=full" ]
267 ldflags += [ "-flto=full" ]
268 }
269
Primiano Tucci497c3ed2021-05-24 12:24:39 +0100270 if (is_win) {
271 # We support only x86/x64 builds on Windows.
272 assert(current_cpu == "x64" || current_cpu == "x86")
273 } else if (current_cpu == "arm") {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900274 cflags += [
275 "-march=armv7-a",
276 "-mfpu=neon",
277 "-mthumb",
278 ]
Samuel Holland62a31472023-05-18 14:39:50 -0500279 } else if (current_cpu == "riscv64") {
280 if (!is_clang) {
281 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104338
Lalit Magantic5b13b32023-06-30 19:34:30 +0100282 libs += [ "atomic" ]
Samuel Holland62a31472023-05-18 14:39:50 -0500283 }
Primiano Tucciae2879e2017-09-27 11:02:09 +0900284 } else if (current_cpu == "x86") {
285 asmflags += [ "-m32" ]
286 cflags += [
287 "-m32",
288 "-msse2",
289 "-mfpmath=sse",
290 ]
Primiano Tucci24909032024-03-05 16:45:50 +0000291 ldflags += [ "-m32" ]
Primiano Tucci5aab7582017-12-07 12:22:03 +0000292 } else if (current_cpu == "arm64") {
293 cflags += [ "-fno-omit-frame-pointer" ]
Primiano Tucci2277f062021-11-08 22:24:05 +0000294 } else if (current_cpu == "x64") {
295 cflags += [ "-fno-omit-frame-pointer" ] # For perf profiling.
296 if (enable_perfetto_x64_cpu_opt) {
297 # When updating these flags, the CheckCpuOptimizations() in utils.cc must
298 # be updated accordingly.
299 cflags += [
Lalit Maganti25a45342022-06-14 14:56:48 +0100300 "-mbmi",
301 "-mbmi2",
Primiano Tucci682a9982022-05-20 17:13:28 +0100302 "-mavx2",
Primiano Tucci2277f062021-11-08 22:24:05 +0000303 "-mpopcnt",
304 "-msse4.2",
305 ]
306 }
Primiano Tucciae2879e2017-09-27 11:02:09 +0900307 }
308
Hector Dearmanff9f2eb2023-06-12 10:00:40 +0100309 if (is_wasm) {
310 # As of writing (2023-06-12) WASM 128bit SIMD is supported on
311 # stable Chrome, Safari, and Firefox. See:
312 # - https://webassembly.org/roadmap/
313 # - https://emscripten.org/docs/porting/simd.html
314 cflags += [ "-msimd128" ]
315 }
316
Primiano Tucciae2879e2017-09-27 11:02:09 +0900317 if (is_linux) {
Chinglin Yu1ce890e2022-10-06 17:54:17 +0800318 # Enable LFS (large file support) for stat() and other syscalls.
319 cflags += [
320 "-D_FILE_OFFSET_BITS=64",
321 "-D_LARGEFILE_SOURCE",
322 "-D_LARGEFILE64_SOURCE",
323 ]
Primiano Tucci7278dea2017-10-31 11:50:32 +0000324 libs += [
325 "pthread",
326 "rt",
327 ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900328 }
329
Primiano Tucci2f811552020-12-07 16:48:22 +0100330 if (is_win && !is_clang) {
331 # When using MSVC we need to manually pass the include dirs. clang-cl.exe
332 # doesn't need them because it's smart enough to figure out the right path
333 # by querying the registry on its own.
334 include_dirs = win_msvc_inc_dirs # Defined in msvc.gni.
335 }
336
Lalit Maganti209b5fa2023-11-09 15:52:15 +0000337 if (is_win) {
338 cflags += [ "/Zi" ]
339 }
Florian Mayer6aba66d2018-02-02 10:53:28 +0000340 if (is_debug) {
Primiano Tucci2f811552020-12-07 16:48:22 +0100341 if (is_win) {
Primiano Tucci2f811552020-12-07 16:48:22 +0100342 if (is_clang) {
343 # Required to see symbols in windbg when building with clang-cl.exe.
344 cflags += [ "-gcodeview-ghash" ]
345 ldflags = [ "/DEBUG:GHASH" ]
346 }
347 } else {
348 libs += [ "dl" ]
349 }
Florian Mayer6aba66d2018-02-02 10:53:28 +0000350 }
351
Primiano Tucci0825bc82017-09-28 18:50:23 +0100352 if (is_android) {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900353 asmflags += [ "--target=$android_abi_target" ]
354 cflags += [
Primiano Tuccib45bfac2017-11-28 14:37:48 +0000355 "--sysroot=$android_compile_sysroot",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900356 "-DANDROID",
Florian Mayer46ef9222018-08-22 14:46:01 -0700357 "-D__ANDROID_API__=${android_api_level}",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900358 "--target=$android_abi_target",
359 ]
Primiano Tucci60571c22024-02-22 18:23:56 +0000360 cflags_cc += [ "-isystem$android_compile_sysroot/c++/v1" ]
Lalit Maganti76905222022-05-20 14:24:14 +0100361
Primiano Tucci60571c22024-02-22 18:23:56 +0000362 android_lib_dir = "$android_compile_sysroot/usr/lib/$android_abi_target/$android_api_level"
Primiano Tucciae2879e2017-09-27 11:02:09 +0900363 ldflags += [
364 "-Wl,-z,nocopyreloc",
Primiano Tucci60571c22024-02-22 18:23:56 +0000365 "--sysroot=$android_compile_sysroot",
366 "-B${android_lib_dir}",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900367 "--target=$android_abi_target",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900368 "-Wl,--no-undefined",
369 "-Wl,-z,noexecstack",
370 "-Wl,-z,relro",
371 "-Wl,-z,now",
372 "-Wl,--warn-shared-textrel",
373 "-Wl,--fatal-warnings",
Florian Mayer55926852021-02-17 14:42:32 +0000374
Primiano Tucci60571c22024-02-22 18:23:56 +0000375 # From NDK docs: "although the option uses the name "libstdc++" for
376 # historical reasons, this is correct for libc++ as well.
377 "-static-libstdc++",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900378 ]
Primiano Tucci60571c22024-02-22 18:23:56 +0000379 lib_dirs = [ android_lib_dir ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900380 }
381}
382
Lalit Maganti209b5fa2023-11-09 15:52:15 +0000383config("debug_noopt") {
Primiano Tucci2f811552020-12-07 16:48:22 +0100384 cflags = []
385 if (is_win) {
386 cflags = [ "/Od" ]
387 } else {
388 cflags = [ "-O0" ]
389 }
Primiano Tucci5aab7582017-12-07 12:22:03 +0000390 if (is_android || is_linux) {
391 cflags += [ "-funwind-tables" ]
Primiano Tucci0825bc82017-09-28 18:50:23 +0100392 }
393}
394
Primiano Tucciae2879e2017-09-27 11:02:09 +0900395config("release") {
Primiano Tucci2f811552020-12-07 16:48:22 +0100396 # Compiler flags for release builds.
397 if (is_win) {
398 cflags = [
399 "/O2",
400 "/Zc:inline",
401 ]
402 } else if (is_android) {
403 cflags = [ "-O2" ]
Florian Mayer2e480712018-12-07 16:25:41 +0000404 } else if (is_fuzzer) {
Primiano Tucci2f811552020-12-07 16:48:22 +0100405 cflags = [ "-O1" ]
Primiano Tucci5aab7582017-12-07 12:22:03 +0000406 } else {
Primiano Tucci2f811552020-12-07 16:48:22 +0100407 cflags = [ "-O3" ]
Primiano Tucci5aab7582017-12-07 12:22:03 +0000408 }
Primiano Tucci2f811552020-12-07 16:48:22 +0100409 if (!is_win) {
410 cflags += [
411 "-fdata-sections",
412 "-ffunction-sections",
413 ]
414 }
415
416 # Linker flags for release builds.
417 if (is_win) {
418 ldflags = [
419 "/OPT:REF",
420 "/OPT:ICF",
421 "/INCREMENTAL:NO",
422 "/FIXED:NO",
423 ]
424 } else if (is_mac) {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900425 ldflags = [ "-dead_strip" ]
Primiano Tucci7e9865c2021-01-10 23:55:15 +0100426 } else if (!is_win && !is_wasm) {
Primiano Tucci5aab7582017-12-07 12:22:03 +0000427 ldflags = [
Primiano Tucci5aab7582017-12-07 12:22:03 +0000428 "-Wl,--gc-sections",
429 "-Wl,--icf=all",
430 "-Wl,-O1",
431 ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900432 }
433 defines = [ "NDEBUG" ]
434}
435
Primiano Tucci0825bc82017-09-28 18:50:23 +0100436config("shared_library") {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900437 if (is_android || is_linux) {
Primiano Tucci0825bc82017-09-28 18:50:23 +0100438 ldflags = [ "-fPIC" ]
439 }
440}
441
442config("executable") {
Primiano Tucci7278dea2017-10-31 11:50:32 +0000443 ldflags = []
444
445 # Android will refuse to run executables if they aren't position independent.
446 # Instead on Linux there isn't any need and they break ASan (goo.gl/paFR6K).
Florian Mayera74aaf02021-01-27 17:05:38 +0000447 # The OSS-Fuzz provided AFL library is not PIC, so we we cannot use -fPIE
448 # for the fuzzer executables.
449 if ((is_android || is_linux) && !is_wasm && !is_fuzzer) {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900450 asmflags = [ "-fPIE" ]
451 cflags = [ "-fPIE" ]
Primiano Tucci7278dea2017-10-31 11:50:32 +0000452 ldflags += [ "-pie" ]
453 }
454
455 # -rpath stores the path to the linked shared libraries into the binary, so
456 # that they can be launched without passing any LD_LIBRARY_PATH. It's
457 # supported only by Linux, not Android. But concretely we need this only when
458 # use_custom_libcxx=true && custom_libcxx_is_static=false, which happens only
459 # on Linux right now.
Primiano Tucci7e9865c2021-01-10 23:55:15 +0100460 if (is_linux && !is_wasm) {
Primiano Tucci7278dea2017-10-31 11:50:32 +0000461 ldflags += [
462 "-Wl,-rpath=\$ORIGIN/.",
463 "-Wl,-rpath-link=.",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900464 ]
465 }
466}
Ryan Savitskia3da9be2019-01-30 17:45:53 +0000467
468# This config is only added to certain leaf target types (see BUILDCONFIG.gn).
469# This allows us to remove the config (and thus the dependency) on a per-target
470# basis. If the config was applied to source_sets, then they would unavoidably
471# carry the dependency onto liblog to the final target.
472config("android_liblog") {
473 if (is_android) {
474 libs = [ "log" ]
475 }
476}
Primiano Tucci00da64a2019-02-22 14:51:10 +0000477
Primiano Tucci69132a12020-02-07 22:33:06 +0000478# Checks that tools/install-build-deps has been run since it last changed.
479perfetto_check_build_deps("check_build_deps") {
480 args = []
481}
482
483perfetto_check_build_deps("check_build_deps_android") {
484 args = [ "--android" ]
485}