blob: 902edd2e7e8869ab8b492a9a94407181c16eb2f2 [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 = [
Primiano Tucci3cbb10a2018-04-10 17:52:40 +010020 "-Wall",
Primiano Tucci0825bc82017-09-28 18:50:23 +010021 "-Wextra",
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 Tucciae2879e2017-09-27 11:02:09 +090033 ]
34 }
35}
36
Primiano Tucci0825bc82017-09-28 18:50:23 +010037config("no_exceptions") {
Primiano Tuccie1d76382018-04-04 09:39:06 +020038 cflags_cc = [ "-fno-exceptions" ]
Primiano Tucci0825bc82017-09-28 18:50:23 +010039}
40
41config("no_rtti") {
Primiano Tuccie1d76382018-04-04 09:39:06 +020042 cflags_cc = [ "-fno-rtti" ]
Primiano Tucci0825bc82017-09-28 18:50:23 +010043}
44
Primiano Tucci5aab7582017-12-07 12:22:03 +000045config("visibility_hidden") {
46 cflags = [ "-fvisibility=hidden" ]
47}
48
Primiano Tucciae2879e2017-09-27 11:02:09 +090049config("default") {
50 asmflags = []
51 cflags = []
52 cflags_c = []
53 cflags_cc = []
54 defines = []
55 ldflags = []
56 libs = []
57
Primiano Tucciae2879e2017-09-27 11:02:09 +090058 cflags_cc += [ "-std=c++11" ]
59
60 cflags += [
Primiano Tucciae2879e2017-09-27 11:02:09 +090061 "-fstrict-aliasing",
62 "-fstack-protector",
63 "-fPIC",
Primiano Tuccibc8318e2017-12-19 09:29:37 +010064 "-g",
Primiano Tucciae2879e2017-09-27 11:02:09 +090065 "-Wa,--noexecstack",
66 "-Wformat",
Primiano Tucciae2879e2017-09-27 11:02:09 +090067 "-Werror",
68 ]
69
Hector Dearman32c32ad2017-10-18 11:53:32 +010070 if (is_clang) {
Primiano Tuccid7d1be02017-10-30 17:41:34 +000071 cflags += [
Primiano Tucci3cbb10a2018-04-10 17:52:40 +010072 # Color compiler output, see https://github.com/ninja-build/ninja/wiki/FAQ
Primiano Tuccid7d1be02017-10-30 17:41:34 +000073 "-fcolor-diagnostics",
Florian Mayer18614fe2018-03-29 17:51:20 +010074 "-fdiagnostics-show-template-tree",
Primiano Tuccid7d1be02017-10-30 17:41:34 +000075 ]
Hector Dearman32c32ad2017-10-18 11:53:32 +010076 }
77
Primiano Tucciae2879e2017-09-27 11:02:09 +090078 if (current_cpu == "arm") {
79 cflags += [
80 "-march=armv7-a",
81 "-mfpu=neon",
82 "-mthumb",
83 ]
84 } else if (current_cpu == "x86") {
85 asmflags += [ "-m32" ]
86 cflags += [
87 "-m32",
88 "-msse2",
89 "-mfpmath=sse",
90 ]
91 ldflags += [ "-m32" ]
Primiano Tucci5aab7582017-12-07 12:22:03 +000092 } else if (current_cpu == "arm64") {
93 cflags += [ "-fno-omit-frame-pointer" ]
Primiano Tucciae2879e2017-09-27 11:02:09 +090094 }
95
96 if (is_linux) {
Primiano Tucci7278dea2017-10-31 11:50:32 +000097 libs += [
98 "pthread",
99 "rt",
100 ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900101 }
102
103 if (is_android) {
Primiano Tucci0825bc82017-09-28 18:50:23 +0100104 libs += [ "log" ]
105 }
106
Florian Mayer6aba66d2018-02-02 10:53:28 +0000107 if (is_debug) {
108 libs += [ "dl" ]
109 }
110
Primiano Tucci0825bc82017-09-28 18:50:23 +0100111 if (is_android) {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900112 asmflags += [ "--target=$android_abi_target" ]
113 cflags += [
Primiano Tuccib45bfac2017-11-28 14:37:48 +0000114 "--sysroot=$android_compile_sysroot",
115 "-isystem$android_compile_sysroot/$android_compile_sysroot_subdir",
116 "-isystem$android_compile_sysroot",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900117 "-DANDROID",
Primiano Tuccib45bfac2017-11-28 14:37:48 +0000118 "-D__ANDROID_API__=21",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900119 "--target=$android_abi_target",
120 ]
121 cflags_cc += [
122 "-I$android_ndk_root/sources/cxx-stl/llvm-libc++/include",
123 "-I$android_ndk_root/sources/android/support/include",
124 "-I$android_ndk_root/sources/cxx-stl/llvm-libc++abi/include",
125 ]
126 ldflags += [
127 "-Wl,-z,nocopyreloc",
128 "-gcc-toolchain",
129 "$android_toolchain_root",
Primiano Tuccib45bfac2017-11-28 14:37:48 +0000130 "--sysroot=$android_ndk_root/$android_link_sysroot_subdir",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900131 "--target=$android_abi_target",
132 "-Wl,--exclude-libs,libunwind.a",
133 "-Wl,--exclude-libs,libgcc.a",
134 "-Wl,--exclude-libs,libc++_static.a",
135 "-Wl,--build-id",
136 "-Wl,--no-undefined",
137 "-Wl,-z,noexecstack",
138 "-Wl,-z,relro",
139 "-Wl,-z,now",
140 "-Wl,--warn-shared-textrel",
141 "-Wl,--fatal-warnings",
142 ]
Primiano Tuccib45bfac2017-11-28 14:37:48 +0000143 lib_dirs = [ "$android_ndk_root/sources/cxx-stl/llvm-libc++/libs/$android_app_abi" ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900144 libs += [
145 "gcc",
146 "c++_static",
147 "c++abi",
148 "android_support",
149 ]
150 }
151}
152
153config("debug_symbols") {
Primiano Tuccibc8318e2017-12-19 09:29:37 +0100154 cflags = [ "-O0" ]
Primiano Tucci5aab7582017-12-07 12:22:03 +0000155 if (is_android || is_linux) {
156 cflags += [ "-funwind-tables" ]
Primiano Tucci0825bc82017-09-28 18:50:23 +0100157 }
158}
159
Primiano Tucciae2879e2017-09-27 11:02:09 +0900160config("release") {
161 cflags = [
Primiano Tucciae2879e2017-09-27 11:02:09 +0900162 "-fdata-sections",
163 "-ffunction-sections",
164 ]
Primiano Tucci5aab7582017-12-07 12:22:03 +0000165 if (is_android) {
166 cflags += [ "-Oz" ]
167 } else {
168 cflags += [ "-O3" ]
169 }
Primiano Tucciae2879e2017-09-27 11:02:09 +0900170 if (is_mac) {
171 ldflags = [ "-dead_strip" ]
172 } else {
Primiano Tucci5aab7582017-12-07 12:22:03 +0000173 ldflags = [
174 "-fuse-ld=gold",
175 "-Wl,--gc-sections",
176 "-Wl,--icf=all",
177 "-Wl,-O1",
178 ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900179 }
180 defines = [ "NDEBUG" ]
181}
182
Primiano Tucci0825bc82017-09-28 18:50:23 +0100183config("shared_library") {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900184 if (is_android || is_linux) {
Primiano Tucci0825bc82017-09-28 18:50:23 +0100185 ldflags = [ "-fPIC" ]
186 }
187}
188
189config("executable") {
Primiano Tucci7278dea2017-10-31 11:50:32 +0000190 ldflags = []
191
192 # Android will refuse to run executables if they aren't position independent.
193 # Instead on Linux there isn't any need and they break ASan (goo.gl/paFR6K).
Primiano Tucci0825bc82017-09-28 18:50:23 +0100194 if (is_android) {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900195 asmflags = [ "-fPIE" ]
196 cflags = [ "-fPIE" ]
Primiano Tucci7278dea2017-10-31 11:50:32 +0000197 ldflags += [ "-pie" ]
198 }
199
200 # -rpath stores the path to the linked shared libraries into the binary, so
201 # that they can be launched without passing any LD_LIBRARY_PATH. It's
202 # supported only by Linux, not Android. But concretely we need this only when
203 # use_custom_libcxx=true && custom_libcxx_is_static=false, which happens only
204 # on Linux right now.
205 if (is_linux) {
206 ldflags += [
207 "-Wl,-rpath=\$ORIGIN/.",
208 "-Wl,-rpath-link=.",
Primiano Tucciae2879e2017-09-27 11:02:09 +0900209 ]
210 }
211}