blob: 79cdadfc39285b9ddd67248f924034d521aab74b [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 Tucci7a40e4d2017-12-06 09:51:09 +000015import("//gn/standalone/android.gni")
16import("//gn/standalone/sanitizers/sanitizers.gni")
Primiano Tucci8b3feb42019-07-04 03:17:31 +010017import("//gn/standalone/wasm.gni")
Primiano Tucciae2879e2017-09-27 11:02:09 +090018
19config("extra_warnings") {
Primiano Tucci0825bc82017-09-28 18:50:23 +010020 cflags = [
Primiano Tucci3cbb10a2018-04-10 17:52:40 +010021 "-Wall",
Primiano Tucci0825bc82017-09-28 18:50:23 +010022 "-Wextra",
Sami Kyostila1c76dff2020-01-15 16:32:21 +000023 "-Wpedantic",
Primiano Tucci0825bc82017-09-28 18:50:23 +010024 ]
Primiano Tucci8a5b9a82018-12-28 13:18:21 +010025
Lalit Magantib4eaf212020-01-16 18:34:41 +000026 # Disable variadic macro warning as we make extensive use of them in trace
27 # processor and client API.
28 if (is_clang) {
29 cflags += [ "-Wno-gnu-zero-variadic-macro-arguments" ]
30 }
31
Primiano Tucci8a5b9a82018-12-28 13:18:21 +010032 # Disable Weverything on fuzzers to avoid breakages when new versions of clang
33 # are rolled into OSS-fuzz.
34 if (is_clang && !is_fuzzer) {
Primiano Tucciae2879e2017-09-27 11:02:09 +090035 cflags += [
36 "-Weverything",
Sami Kyostila3a946ae2017-09-29 14:56:36 +010037 "-Wno-c++98-compat-pedantic",
Primiano Tucci13331342017-10-25 17:08:13 +010038 "-Wno-c++98-compat",
Primiano Tucci4bdc4c42018-05-10 15:52:33 +010039 "-Wno-disabled-macro-expansion",
Primiano Tucciae2879e2017-09-27 11:02:09 +090040 "-Wno-gnu-include-next",
41 "-Wno-gnu-statement-expression",
42 "-Wno-padded",
43 "-Wno-reserved-id-macro",
Primiano Tucci91c4a412019-03-20 09:49:32 +000044 "-Wno-unknown-sanitizers",
Primiano Tucciae2879e2017-09-27 11:02:09 +090045 ]
46 }
47}
48
Primiano Tucci0825bc82017-09-28 18:50:23 +010049config("no_exceptions") {
Primiano Tuccie1d76382018-04-04 09:39:06 +020050 cflags_cc = [ "-fno-exceptions" ]
Primiano Tucci0825bc82017-09-28 18:50:23 +010051}
52
53config("no_rtti") {
Primiano Tuccie1d76382018-04-04 09:39:06 +020054 cflags_cc = [ "-fno-rtti" ]
Primiano Tucci0825bc82017-09-28 18:50:23 +010055}
56
Florian Mayer475bd7e2018-08-07 20:04:03 +010057config("c++11") {
58 cflags_cc = [ "-std=c++11" ]
59}
60
61# This is needed to compile libunwindstack.
62config("c++17") {
63 cflags_cc = [ "-std=c++17" ]
64}
65
Primiano Tucci5aab7582017-12-07 12:22:03 +000066config("visibility_hidden") {
67 cflags = [ "-fvisibility=hidden" ]
68}
69
Primiano Tucciae2879e2017-09-27 11:02:09 +090070config("default") {
71 asmflags = []
72 cflags = []
73 cflags_c = []
74 cflags_cc = []
75 defines = []
76 ldflags = []
77 libs = []
78
Primiano Tucciae2879e2017-09-27 11:02:09 +090079 cflags += [
Primiano Tucciae2879e2017-09-27 11:02:09 +090080 "-fstrict-aliasing",
81 "-fstack-protector",
82 "-fPIC",
Primiano Tuccibc8318e2017-12-19 09:29:37 +010083 "-g",
Primiano Tucciae2879e2017-09-27 11:02:09 +090084 "-Wformat",
Primiano Tucciae2879e2017-09-27 11:02:09 +090085 ]
86
Florian Mayer7010f3a2019-09-09 10:48:12 +010087 if (!is_fuzzer) {
88 cflags += [ "-Werror" ]
89 }
90
Hector Dearman32c32ad2017-10-18 11:53:32 +010091 if (is_clang) {
Primiano Tuccid7d1be02017-10-30 17:41:34 +000092 cflags += [
Primiano Tucci3cbb10a2018-04-10 17:52:40 +010093 # Color compiler output, see https://github.com/ninja-build/ninja/wiki/FAQ
Primiano Tuccid7d1be02017-10-30 17:41:34 +000094 "-fcolor-diagnostics",
Florian Mayer18614fe2018-03-29 17:51:20 +010095 "-fdiagnostics-show-template-tree",
Primiano Tuccid7d1be02017-10-30 17:41:34 +000096 ]
Hector Dearman32c32ad2017-10-18 11:53:32 +010097 }
98
Primiano Tucci8c3f40a2018-09-01 08:31:50 +020099 if (is_lto) {
100 cflags += [ "-flto=full" ]
101 ldflags += [ "-flto=full" ]
102 }
103
Primiano Tucciae2879e2017-09-27 11:02:09 +0900104 if (current_cpu == "arm") {
105 cflags += [
106 "-march=armv7-a",
107 "-mfpu=neon",
108 "-mthumb",
109 ]
110 } else if (current_cpu == "x86") {
111 asmflags += [ "-m32" ]
112 cflags += [
113 "-m32",
114 "-msse2",
115 "-mfpmath=sse",
116 ]
Florian Mayer27985ac2019-09-13 16:56:56 +0100117 ldflags += [
118 "-m32",
119 "-lgcc",
120 ]
Primiano Tucci5aab7582017-12-07 12:22:03 +0000121 } else if (current_cpu == "arm64") {
122 cflags += [ "-fno-omit-frame-pointer" ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900123 }
124
125 if (is_linux) {
Primiano Tucci7278dea2017-10-31 11:50:32 +0000126 libs += [
127 "pthread",
128 "rt",
129 ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900130 }
131
Florian Mayer6aba66d2018-02-02 10:53:28 +0000132 if (is_debug) {
133 libs += [ "dl" ]
134 }
135
Primiano Tucci0825bc82017-09-28 18:50:23 +0100136 if (is_android) {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900137 asmflags += [ "--target=$android_abi_target" ]
138 cflags += [
Primiano Tuccib45bfac2017-11-28 14:37:48 +0000139 "--sysroot=$android_compile_sysroot",
140 "-isystem$android_compile_sysroot/$android_compile_sysroot_subdir",
141 "-isystem$android_compile_sysroot",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900142 "-DANDROID",
Florian Mayer46ef9222018-08-22 14:46:01 -0700143 "-D__ANDROID_API__=${android_api_level}",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900144 "--target=$android_abi_target",
145 ]
146 cflags_cc += [
147 "-I$android_ndk_root/sources/cxx-stl/llvm-libc++/include",
148 "-I$android_ndk_root/sources/android/support/include",
149 "-I$android_ndk_root/sources/cxx-stl/llvm-libc++abi/include",
Florian Mayeraa5316b2018-08-20 17:45:12 -0700150
151 # This is needed for NDK libc++. Using -isystem instead of -I above
152 # results in build breakage related to cmath.h.
153 "-Wno-format-nonliteral",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900154 ]
155 ldflags += [
156 "-Wl,-z,nocopyreloc",
157 "-gcc-toolchain",
158 "$android_toolchain_root",
Primiano Tuccib45bfac2017-11-28 14:37:48 +0000159 "--sysroot=$android_ndk_root/$android_link_sysroot_subdir",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900160 "--target=$android_abi_target",
161 "-Wl,--exclude-libs,libunwind.a",
162 "-Wl,--exclude-libs,libgcc.a",
163 "-Wl,--exclude-libs,libc++_static.a",
164 "-Wl,--build-id",
165 "-Wl,--no-undefined",
166 "-Wl,-z,noexecstack",
167 "-Wl,-z,relro",
168 "-Wl,-z,now",
169 "-Wl,--warn-shared-textrel",
170 "-Wl,--fatal-warnings",
171 ]
Florian Mayer475bd7e2018-08-07 20:04:03 +0100172 lib_dirs = [
173 "$android_ndk_root/sources/cxx-stl/llvm-libc++/libs/$android_app_abi",
174 ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900175 libs += [
176 "gcc",
177 "c++_static",
178 "c++abi",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900179 ]
Florian Mayeraa5316b2018-08-20 17:45:12 -0700180
181 if (current_cpu == "arm") {
182 # New NDKs don't have libandroid_support for arm64.
183 libs += [ "android_support" ]
184 }
Primiano Tucciae2879e2017-09-27 11:02:09 +0900185 }
186}
187
188config("debug_symbols") {
Primiano Tuccibc8318e2017-12-19 09:29:37 +0100189 cflags = [ "-O0" ]
Primiano Tucci5aab7582017-12-07 12:22:03 +0000190 if (is_android || is_linux) {
191 cflags += [ "-funwind-tables" ]
Primiano Tucci0825bc82017-09-28 18:50:23 +0100192 }
193}
194
Primiano Tucciae2879e2017-09-27 11:02:09 +0900195config("release") {
196 cflags = [
Primiano Tucciae2879e2017-09-27 11:02:09 +0900197 "-fdata-sections",
198 "-ffunction-sections",
199 ]
Primiano Tucci5aab7582017-12-07 12:22:03 +0000200 if (is_android) {
Ryan Savitskif9291072019-09-24 16:49:13 +0100201 cflags += [ "-O2" ]
Florian Mayer2e480712018-12-07 16:25:41 +0000202 } else if (is_fuzzer) {
Primiano Tuccia65497e2018-09-26 19:53:58 +0100203 cflags += [ "-O1" ]
Primiano Tucci5aab7582017-12-07 12:22:03 +0000204 } else {
205 cflags += [ "-O3" ]
206 }
Primiano Tucciae2879e2017-09-27 11:02:09 +0900207 if (is_mac) {
208 ldflags = [ "-dead_strip" ]
209 } else {
Primiano Tucci5aab7582017-12-07 12:22:03 +0000210 ldflags = [
Primiano Tucci5aab7582017-12-07 12:22:03 +0000211 "-Wl,--gc-sections",
212 "-Wl,--icf=all",
213 "-Wl,-O1",
214 ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900215 }
216 defines = [ "NDEBUG" ]
217}
218
Primiano Tucci0825bc82017-09-28 18:50:23 +0100219config("shared_library") {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900220 if (is_android || is_linux) {
Primiano Tucci0825bc82017-09-28 18:50:23 +0100221 ldflags = [ "-fPIC" ]
222 }
223}
224
225config("executable") {
Primiano Tucci7278dea2017-10-31 11:50:32 +0000226 ldflags = []
227
228 # Android will refuse to run executables if they aren't position independent.
229 # Instead on Linux there isn't any need and they break ASan (goo.gl/paFR6K).
Primiano Tucci0825bc82017-09-28 18:50:23 +0100230 if (is_android) {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900231 asmflags = [ "-fPIE" ]
232 cflags = [ "-fPIE" ]
Primiano Tucci7278dea2017-10-31 11:50:32 +0000233 ldflags += [ "-pie" ]
234 }
235
236 # -rpath stores the path to the linked shared libraries into the binary, so
237 # that they can be launched without passing any LD_LIBRARY_PATH. It's
238 # supported only by Linux, not Android. But concretely we need this only when
239 # use_custom_libcxx=true && custom_libcxx_is_static=false, which happens only
240 # on Linux right now.
241 if (is_linux) {
242 ldflags += [
243 "-Wl,-rpath=\$ORIGIN/.",
244 "-Wl,-rpath-link=.",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900245 ]
246 }
247}
Ryan Savitskia3da9be2019-01-30 17:45:53 +0000248
249# This config is only added to certain leaf target types (see BUILDCONFIG.gn).
250# This allows us to remove the config (and thus the dependency) on a per-target
251# basis. If the config was applied to source_sets, then they would unavoidably
252# carry the dependency onto liblog to the final target.
253config("android_liblog") {
254 if (is_android) {
255 libs = [ "log" ]
256 }
257}
Primiano Tucci00da64a2019-02-22 14:51:10 +0000258
259config("gen_include_path") {
260 include_dirs = [ root_gen_dir ]
261}
262
263# This action generates a perfetto_version.gen.h which contains the git SHA1
264# of HEAD. The file can be included from C/C++ sources and exposes a
265# PERFETTO_GET_GIT_REVISION() macro that contains the git revision.
266action("gen_git_revision") {
267 script = "gen_git_revision.py"
268 generated_header = "${root_gen_dir}/perfetto_version.gen.h"
269 args = [ rebase_path(generated_header, root_build_dir) ]
270 inputs = []
271 outputs = [
272 generated_header,
273 ]
274 public_configs = [ ":gen_include_path" ]
275}