• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 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
15import("//gn/standalone/android.gni")
16import("//gn/standalone/sanitizers/sanitizers.gni")
17
18config("extra_warnings") {
19  cflags = [
20    "-Wall",
21    "-Wextra",
22  ]
23  if (is_clang) {
24    cflags += [
25      "-Weverything",
26      "-Wno-c++98-compat-pedantic",
27      "-Wno-c++98-compat",
28      "-Wno-gnu-include-next",
29      "-Wno-gnu-statement-expression",
30      "-Wno-gnu-zero-variadic-macro-arguments",
31      "-Wno-padded",
32      "-Wno-reserved-id-macro",
33    ]
34  }
35}
36
37config("no_exceptions") {
38  cflags_cc = [ "-fno-exceptions" ]
39}
40
41config("no_rtti") {
42  cflags_cc = [ "-fno-rtti" ]
43}
44
45config("visibility_hidden") {
46  cflags = [ "-fvisibility=hidden" ]
47}
48
49config("default") {
50  asmflags = []
51  cflags = []
52  cflags_c = []
53  cflags_cc = []
54  defines = []
55  ldflags = []
56  libs = []
57
58  cflags_cc += [ "-std=c++11" ]
59
60  cflags += [
61    "-fstrict-aliasing",
62    "-fstack-protector",
63    "-fPIC",
64    "-g",
65    "-Wa,--noexecstack",
66    "-Wformat",
67    "-Werror",
68  ]
69
70  if (is_clang) {
71    cflags += [
72      # Color compiler output, see https://github.com/ninja-build/ninja/wiki/FAQ
73      "-fcolor-diagnostics",
74      "-fdiagnostics-show-template-tree",
75    ]
76  }
77
78  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" ]
92  } else if (current_cpu == "arm64") {
93    cflags += [ "-fno-omit-frame-pointer" ]
94  }
95
96  if (is_linux) {
97    libs += [
98      "pthread",
99      "rt",
100    ]
101  }
102
103  if (is_android) {
104    libs += [ "log" ]
105  }
106
107  if (is_debug) {
108    libs += [ "dl" ]
109  }
110
111  if (is_android) {
112    asmflags += [ "--target=$android_abi_target" ]
113    cflags += [
114      "--sysroot=$android_compile_sysroot",
115      "-isystem$android_compile_sysroot/$android_compile_sysroot_subdir",
116      "-isystem$android_compile_sysroot",
117      "-DANDROID",
118      "-D__ANDROID_API__=21",
119      "--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",
130      "--sysroot=$android_ndk_root/$android_link_sysroot_subdir",
131      "--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    ]
143    lib_dirs = [ "$android_ndk_root/sources/cxx-stl/llvm-libc++/libs/$android_app_abi" ]
144    libs += [
145      "gcc",
146      "c++_static",
147      "c++abi",
148      "android_support",
149    ]
150  }
151}
152
153config("debug_symbols") {
154  cflags = [ "-O0" ]
155  if (is_android || is_linux) {
156    cflags += [ "-funwind-tables" ]
157  }
158}
159
160config("release") {
161  cflags = [
162    "-fdata-sections",
163    "-ffunction-sections",
164  ]
165  if (is_android) {
166    cflags += [ "-Oz" ]
167  } else {
168    cflags += [ "-O3" ]
169  }
170  if (is_mac) {
171    ldflags = [ "-dead_strip" ]
172  } else {
173    ldflags = [
174      "-fuse-ld=gold",
175      "-Wl,--gc-sections",
176      "-Wl,--icf=all",
177      "-Wl,-O1",
178    ]
179  }
180  defines = [ "NDEBUG" ]
181}
182
183config("shared_library") {
184  if (is_android || is_linux) {
185    ldflags = [ "-fPIC" ]
186  }
187}
188
189config("executable") {
190  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).
194  if (is_android) {
195    asmflags = [ "-fPIE" ]
196    cflags = [ "-fPIE" ]
197    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=.",
209    ]
210  }
211}
212