blob: 864c67ef3e0d267dbc035648a9a0d008043756b4 [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 Tucciae2879e2017-09-27 11:02:09 +090017
18config("extra_warnings") {
Primiano Tucci0825bc82017-09-28 18:50:23 +010019 cflags = [
20 "-Wextra",
Primiano Tucci765b3262017-11-09 09:47:32 +000021 "-Wno-unused-parameter",
Primiano Tucci0825bc82017-09-28 18:50:23 +010022 ]
Primiano Tucciae2879e2017-09-27 11:02:09 +090023 if (is_clang) {
24 cflags += [
25 "-Weverything",
Sami Kyostila3a946ae2017-09-29 14:56:36 +010026 "-Wno-c++98-compat-pedantic",
Primiano Tucci13331342017-10-25 17:08:13 +010027 "-Wno-c++98-compat",
Primiano Tucciae2879e2017-09-27 11:02:09 +090028 "-Wno-gnu-include-next",
29 "-Wno-gnu-statement-expression",
Primiano Tucci13331342017-10-25 17:08:13 +010030 "-Wno-gnu-zero-variadic-macro-arguments",
Primiano Tucciae2879e2017-09-27 11:02:09 +090031 "-Wno-padded",
32 "-Wno-reserved-id-macro",
Primiano Tuccice720022017-10-30 12:50:06 +000033 "-Wno-weak-vtables",
Primiano Tucciae2879e2017-09-27 11:02:09 +090034 ]
35 }
36}
37
Primiano Tucci0825bc82017-09-28 18:50:23 +010038config("no_exceptions") {
39 cflags = [ "-fno-exceptions" ]
40}
41
42config("no_rtti") {
43 cflags = [ "-fno-rtti" ]
44}
45
Primiano Tucci5aab7582017-12-07 12:22:03 +000046config("visibility_hidden") {
47 cflags = [ "-fvisibility=hidden" ]
48}
49
Primiano Tucciae2879e2017-09-27 11:02:09 +090050config("default") {
51 asmflags = []
52 cflags = []
53 cflags_c = []
54 cflags_cc = []
55 defines = []
56 ldflags = []
57 libs = []
58
Primiano Tucciae2879e2017-09-27 11:02:09 +090059 cflags_cc += [ "-std=c++11" ]
60
61 cflags += [
Primiano Tucciae2879e2017-09-27 11:02:09 +090062 "-fstrict-aliasing",
63 "-fstack-protector",
64 "-fPIC",
65 "-Wa,--noexecstack",
66 "-Wformat",
67 "-Wall",
68 "-Werror",
69 ]
70
Hector Dearman32c32ad2017-10-18 11:53:32 +010071 # Color compiler output, see https://github.com/ninja-build/ninja/wiki/FAQ
72 if (is_clang) {
Primiano Tuccid7d1be02017-10-30 17:41:34 +000073 cflags += [
74 "-fcolor-diagnostics",
75 "-Wno-unknown-warning-option",
76 ]
Primiano Tucci7278dea2017-10-31 11:50:32 +000077 } else {
78 cflags += [ "-Wno-unknown-warning" ]
Hector Dearman32c32ad2017-10-18 11:53:32 +010079 }
80
Primiano Tucciae2879e2017-09-27 11:02:09 +090081 if (current_cpu == "arm") {
82 cflags += [
83 "-march=armv7-a",
84 "-mfpu=neon",
85 "-mthumb",
86 ]
87 } else if (current_cpu == "x86") {
88 asmflags += [ "-m32" ]
89 cflags += [
90 "-m32",
91 "-msse2",
92 "-mfpmath=sse",
93 ]
94 ldflags += [ "-m32" ]
Primiano Tucci5aab7582017-12-07 12:22:03 +000095 } else if (current_cpu == "arm64") {
96 cflags += [ "-fno-omit-frame-pointer" ]
Primiano Tucciae2879e2017-09-27 11:02:09 +090097 }
98
99 if (is_linux) {
Primiano Tucci7278dea2017-10-31 11:50:32 +0000100 libs += [
101 "pthread",
102 "rt",
103 ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900104 }
105
106 if (is_android) {
Primiano Tucci0825bc82017-09-28 18:50:23 +0100107 libs += [ "log" ]
108 }
109
110 if (is_android) {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900111 asmflags += [ "--target=$android_abi_target" ]
112 cflags += [
Primiano Tuccib45bfac2017-11-28 14:37:48 +0000113 "--sysroot=$android_compile_sysroot",
114 "-isystem$android_compile_sysroot/$android_compile_sysroot_subdir",
115 "-isystem$android_compile_sysroot",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900116 "-DANDROID",
Primiano Tuccib45bfac2017-11-28 14:37:48 +0000117 "-D__ANDROID_API__=21",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900118 "--target=$android_abi_target",
119 ]
120 cflags_cc += [
121 "-I$android_ndk_root/sources/cxx-stl/llvm-libc++/include",
122 "-I$android_ndk_root/sources/android/support/include",
123 "-I$android_ndk_root/sources/cxx-stl/llvm-libc++abi/include",
124 ]
125 ldflags += [
126 "-Wl,-z,nocopyreloc",
127 "-gcc-toolchain",
128 "$android_toolchain_root",
Primiano Tuccib45bfac2017-11-28 14:37:48 +0000129 "--sysroot=$android_ndk_root/$android_link_sysroot_subdir",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900130 "--target=$android_abi_target",
131 "-Wl,--exclude-libs,libunwind.a",
132 "-Wl,--exclude-libs,libgcc.a",
133 "-Wl,--exclude-libs,libc++_static.a",
134 "-Wl,--build-id",
135 "-Wl,--no-undefined",
136 "-Wl,-z,noexecstack",
137 "-Wl,-z,relro",
138 "-Wl,-z,now",
139 "-Wl,--warn-shared-textrel",
140 "-Wl,--fatal-warnings",
141 ]
Primiano Tuccib45bfac2017-11-28 14:37:48 +0000142 lib_dirs = [ "$android_ndk_root/sources/cxx-stl/llvm-libc++/libs/$android_app_abi" ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900143 libs += [
144 "gcc",
145 "c++_static",
146 "c++abi",
147 "android_support",
148 ]
149 }
150}
151
152config("debug_symbols") {
Primiano Tucci5aab7582017-12-07 12:22:03 +0000153 cflags = [
154 "-g",
155 "-O0",
156 ]
157 if (is_android || is_linux) {
158 cflags += [ "-funwind-tables" ]
159 ldflags = [ "-rdynamic" ]
Primiano Tucci0825bc82017-09-28 18:50:23 +0100160 }
161}
162
Primiano Tucciae2879e2017-09-27 11:02:09 +0900163config("release") {
164 cflags = [
Primiano Tucciae2879e2017-09-27 11:02:09 +0900165 "-fdata-sections",
166 "-ffunction-sections",
167 ]
Primiano Tucci5aab7582017-12-07 12:22:03 +0000168 if (is_android) {
169 cflags += [ "-Oz" ]
170 } else {
171 cflags += [ "-O3" ]
172 }
Primiano Tucciae2879e2017-09-27 11:02:09 +0900173 if (is_mac) {
174 ldflags = [ "-dead_strip" ]
175 } else {
Primiano Tucci5aab7582017-12-07 12:22:03 +0000176 ldflags = [
177 "-fuse-ld=gold",
178 "-Wl,--gc-sections",
179 "-Wl,--icf=all",
180 "-Wl,-O1",
181 ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900182 }
183 defines = [ "NDEBUG" ]
184}
185
Primiano Tucci0825bc82017-09-28 18:50:23 +0100186config("shared_library") {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900187 if (is_android || is_linux) {
Primiano Tucci0825bc82017-09-28 18:50:23 +0100188 ldflags = [ "-fPIC" ]
189 }
190}
191
192config("executable") {
Primiano Tucci7278dea2017-10-31 11:50:32 +0000193 ldflags = []
194
195 # Android will refuse to run executables if they aren't position independent.
196 # Instead on Linux there isn't any need and they break ASan (goo.gl/paFR6K).
Primiano Tucci0825bc82017-09-28 18:50:23 +0100197 if (is_android) {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900198 asmflags = [ "-fPIE" ]
199 cflags = [ "-fPIE" ]
Primiano Tucci7278dea2017-10-31 11:50:32 +0000200 ldflags += [ "-pie" ]
201 }
202
203 # -rpath stores the path to the linked shared libraries into the binary, so
204 # that they can be launched without passing any LD_LIBRARY_PATH. It's
205 # supported only by Linux, not Android. But concretely we need this only when
206 # use_custom_libcxx=true && custom_libcxx_is_static=false, which happens only
207 # on Linux right now.
208 if (is_linux) {
209 ldflags += [
210 "-Wl,-rpath=\$ORIGIN/.",
211 "-Wl,-rpath-link=.",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900212 ]
213 }
214}