blob: 0c77ecabca13cbfc5c784ca2bf1a7da2bf74191b [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",
Primiano Tucci0825bc82017-09-28 18:50:23 +010023 ]
Primiano Tucci8a5b9a82018-12-28 13:18:21 +010024
25 # Disable Weverything on fuzzers to avoid breakages when new versions of clang
26 # are rolled into OSS-fuzz.
27 if (is_clang && !is_fuzzer) {
Primiano Tucciae2879e2017-09-27 11:02:09 +090028 cflags += [
29 "-Weverything",
Sami Kyostila3a946ae2017-09-29 14:56:36 +010030 "-Wno-c++98-compat-pedantic",
Primiano Tucci13331342017-10-25 17:08:13 +010031 "-Wno-c++98-compat",
Primiano Tucci4bdc4c42018-05-10 15:52:33 +010032 "-Wno-disabled-macro-expansion",
Primiano Tucciae2879e2017-09-27 11:02:09 +090033 "-Wno-gnu-include-next",
34 "-Wno-gnu-statement-expression",
Primiano Tucci13331342017-10-25 17:08:13 +010035 "-Wno-gnu-zero-variadic-macro-arguments",
Primiano Tucciae2879e2017-09-27 11:02:09 +090036 "-Wno-padded",
37 "-Wno-reserved-id-macro",
Primiano Tucci91c4a412019-03-20 09:49:32 +000038 "-Wno-unknown-sanitizers",
Primiano Tucciae2879e2017-09-27 11:02:09 +090039 ]
40 }
41}
42
Primiano Tucci0825bc82017-09-28 18:50:23 +010043config("no_exceptions") {
Primiano Tuccie1d76382018-04-04 09:39:06 +020044 cflags_cc = [ "-fno-exceptions" ]
Primiano Tucci0825bc82017-09-28 18:50:23 +010045}
46
47config("no_rtti") {
Primiano Tuccie1d76382018-04-04 09:39:06 +020048 cflags_cc = [ "-fno-rtti" ]
Primiano Tucci0825bc82017-09-28 18:50:23 +010049}
50
Florian Mayer475bd7e2018-08-07 20:04:03 +010051config("c++11") {
52 cflags_cc = [ "-std=c++11" ]
53}
54
55# This is needed to compile libunwindstack.
56config("c++17") {
57 cflags_cc = [ "-std=c++17" ]
58}
59
Primiano Tucci5aab7582017-12-07 12:22:03 +000060config("visibility_hidden") {
61 cflags = [ "-fvisibility=hidden" ]
62}
63
Primiano Tucciae2879e2017-09-27 11:02:09 +090064config("default") {
65 asmflags = []
66 cflags = []
67 cflags_c = []
68 cflags_cc = []
69 defines = []
70 ldflags = []
71 libs = []
72
Primiano Tucciae2879e2017-09-27 11:02:09 +090073 cflags += [
Primiano Tucciae2879e2017-09-27 11:02:09 +090074 "-fstrict-aliasing",
75 "-fstack-protector",
76 "-fPIC",
Primiano Tuccibc8318e2017-12-19 09:29:37 +010077 "-g",
Primiano Tucciae2879e2017-09-27 11:02:09 +090078 "-Wformat",
Primiano Tucciae2879e2017-09-27 11:02:09 +090079 ]
80
Florian Mayer7010f3a2019-09-09 10:48:12 +010081 if (!is_fuzzer) {
82 cflags += [ "-Werror" ]
83 }
84
Hector Dearman32c32ad2017-10-18 11:53:32 +010085 if (is_clang) {
Primiano Tuccid7d1be02017-10-30 17:41:34 +000086 cflags += [
Primiano Tucci3cbb10a2018-04-10 17:52:40 +010087 # Color compiler output, see https://github.com/ninja-build/ninja/wiki/FAQ
Primiano Tuccid7d1be02017-10-30 17:41:34 +000088 "-fcolor-diagnostics",
Florian Mayer18614fe2018-03-29 17:51:20 +010089 "-fdiagnostics-show-template-tree",
Primiano Tuccid7d1be02017-10-30 17:41:34 +000090 ]
Hector Dearman32c32ad2017-10-18 11:53:32 +010091 }
92
Primiano Tucci8c3f40a2018-09-01 08:31:50 +020093 if (is_lto) {
94 cflags += [ "-flto=full" ]
95 ldflags += [ "-flto=full" ]
96 }
97
Primiano Tucciae2879e2017-09-27 11:02:09 +090098 if (current_cpu == "arm") {
99 cflags += [
100 "-march=armv7-a",
101 "-mfpu=neon",
102 "-mthumb",
103 ]
104 } else if (current_cpu == "x86") {
105 asmflags += [ "-m32" ]
106 cflags += [
107 "-m32",
108 "-msse2",
109 "-mfpmath=sse",
110 ]
Florian Mayer27985ac2019-09-13 16:56:56 +0100111 ldflags += [
112 "-m32",
113 "-lgcc",
114 ]
Primiano Tucci5aab7582017-12-07 12:22:03 +0000115 } else if (current_cpu == "arm64") {
116 cflags += [ "-fno-omit-frame-pointer" ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900117 }
118
119 if (is_linux) {
Primiano Tucci7278dea2017-10-31 11:50:32 +0000120 libs += [
121 "pthread",
122 "rt",
123 ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900124 }
125
Florian Mayer6aba66d2018-02-02 10:53:28 +0000126 if (is_debug) {
127 libs += [ "dl" ]
128 }
129
Primiano Tucci0825bc82017-09-28 18:50:23 +0100130 if (is_android) {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900131 asmflags += [ "--target=$android_abi_target" ]
132 cflags += [
Primiano Tuccib45bfac2017-11-28 14:37:48 +0000133 "--sysroot=$android_compile_sysroot",
134 "-isystem$android_compile_sysroot/$android_compile_sysroot_subdir",
135 "-isystem$android_compile_sysroot",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900136 "-DANDROID",
Florian Mayer46ef9222018-08-22 14:46:01 -0700137 "-D__ANDROID_API__=${android_api_level}",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900138 "--target=$android_abi_target",
139 ]
140 cflags_cc += [
141 "-I$android_ndk_root/sources/cxx-stl/llvm-libc++/include",
142 "-I$android_ndk_root/sources/android/support/include",
143 "-I$android_ndk_root/sources/cxx-stl/llvm-libc++abi/include",
Florian Mayeraa5316b2018-08-20 17:45:12 -0700144
145 # This is needed for NDK libc++. Using -isystem instead of -I above
146 # results in build breakage related to cmath.h.
147 "-Wno-format-nonliteral",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900148 ]
149 ldflags += [
150 "-Wl,-z,nocopyreloc",
151 "-gcc-toolchain",
152 "$android_toolchain_root",
Primiano Tuccib45bfac2017-11-28 14:37:48 +0000153 "--sysroot=$android_ndk_root/$android_link_sysroot_subdir",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900154 "--target=$android_abi_target",
155 "-Wl,--exclude-libs,libunwind.a",
156 "-Wl,--exclude-libs,libgcc.a",
157 "-Wl,--exclude-libs,libc++_static.a",
158 "-Wl,--build-id",
159 "-Wl,--no-undefined",
160 "-Wl,-z,noexecstack",
161 "-Wl,-z,relro",
162 "-Wl,-z,now",
163 "-Wl,--warn-shared-textrel",
164 "-Wl,--fatal-warnings",
165 ]
Florian Mayer475bd7e2018-08-07 20:04:03 +0100166 lib_dirs = [
167 "$android_ndk_root/sources/cxx-stl/llvm-libc++/libs/$android_app_abi",
168 ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900169 libs += [
170 "gcc",
171 "c++_static",
172 "c++abi",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900173 ]
Florian Mayeraa5316b2018-08-20 17:45:12 -0700174
175 if (current_cpu == "arm") {
176 # New NDKs don't have libandroid_support for arm64.
177 libs += [ "android_support" ]
178 }
Primiano Tucciae2879e2017-09-27 11:02:09 +0900179 }
180}
181
182config("debug_symbols") {
Primiano Tuccibc8318e2017-12-19 09:29:37 +0100183 cflags = [ "-O0" ]
Primiano Tucci5aab7582017-12-07 12:22:03 +0000184 if (is_android || is_linux) {
185 cflags += [ "-funwind-tables" ]
Primiano Tucci0825bc82017-09-28 18:50:23 +0100186 }
187}
188
Primiano Tucciae2879e2017-09-27 11:02:09 +0900189config("release") {
190 cflags = [
Primiano Tucciae2879e2017-09-27 11:02:09 +0900191 "-fdata-sections",
192 "-ffunction-sections",
193 ]
Primiano Tucci5aab7582017-12-07 12:22:03 +0000194 if (is_android) {
Ryan Savitskif9291072019-09-24 16:49:13 +0100195 cflags += [ "-O2" ]
Florian Mayer2e480712018-12-07 16:25:41 +0000196 } else if (is_fuzzer) {
Primiano Tuccia65497e2018-09-26 19:53:58 +0100197 cflags += [ "-O1" ]
Primiano Tucci5aab7582017-12-07 12:22:03 +0000198 } else {
199 cflags += [ "-O3" ]
200 }
Primiano Tucciae2879e2017-09-27 11:02:09 +0900201 if (is_mac) {
202 ldflags = [ "-dead_strip" ]
203 } else {
Primiano Tucci5aab7582017-12-07 12:22:03 +0000204 ldflags = [
Primiano Tucci5aab7582017-12-07 12:22:03 +0000205 "-Wl,--gc-sections",
206 "-Wl,--icf=all",
207 "-Wl,-O1",
208 ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900209 }
210 defines = [ "NDEBUG" ]
211}
212
Primiano Tucci0825bc82017-09-28 18:50:23 +0100213config("shared_library") {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900214 if (is_android || is_linux) {
Primiano Tucci0825bc82017-09-28 18:50:23 +0100215 ldflags = [ "-fPIC" ]
216 }
217}
218
219config("executable") {
Primiano Tucci7278dea2017-10-31 11:50:32 +0000220 ldflags = []
221
222 # Android will refuse to run executables if they aren't position independent.
223 # Instead on Linux there isn't any need and they break ASan (goo.gl/paFR6K).
Primiano Tucci0825bc82017-09-28 18:50:23 +0100224 if (is_android) {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900225 asmflags = [ "-fPIE" ]
226 cflags = [ "-fPIE" ]
Primiano Tucci7278dea2017-10-31 11:50:32 +0000227 ldflags += [ "-pie" ]
228 }
229
230 # -rpath stores the path to the linked shared libraries into the binary, so
231 # that they can be launched without passing any LD_LIBRARY_PATH. It's
232 # supported only by Linux, not Android. But concretely we need this only when
233 # use_custom_libcxx=true && custom_libcxx_is_static=false, which happens only
234 # on Linux right now.
235 if (is_linux) {
236 ldflags += [
237 "-Wl,-rpath=\$ORIGIN/.",
238 "-Wl,-rpath-link=.",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900239 ]
240 }
241}
Ryan Savitskia3da9be2019-01-30 17:45:53 +0000242
243# This config is only added to certain leaf target types (see BUILDCONFIG.gn).
244# This allows us to remove the config (and thus the dependency) on a per-target
245# basis. If the config was applied to source_sets, then they would unavoidably
246# carry the dependency onto liblog to the final target.
247config("android_liblog") {
248 if (is_android) {
249 libs = [ "log" ]
250 }
251}
Primiano Tucci00da64a2019-02-22 14:51:10 +0000252
253config("gen_include_path") {
254 include_dirs = [ root_gen_dir ]
255}
256
257# This action generates a perfetto_version.gen.h which contains the git SHA1
258# of HEAD. The file can be included from C/C++ sources and exposes a
259# PERFETTO_GET_GIT_REVISION() macro that contains the git revision.
260action("gen_git_revision") {
261 script = "gen_git_revision.py"
262 generated_header = "${root_gen_dir}/perfetto_version.gen.h"
263 args = [ rebase_path(generated_header, root_build_dir) ]
264 inputs = []
265 outputs = [
266 generated_header,
267 ]
268 public_configs = [ ":gen_include_path" ]
269}