blob: 6e0136fcbba94fbfe24639ddf6de978b3e3884a3 [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
15import("//build/android.gni")
Primiano Tucci0825bc82017-09-28 18:50:23 +010016import("//build/c++.gni")
17import("//build/mac.gni")
18import("//build/sanitizers/sanitizers.gni")
Primiano Tucciae2879e2017-09-27 11:02:09 +090019
20config("extra_warnings") {
Primiano Tucci0825bc82017-09-28 18:50:23 +010021 cflags = [
22 "-Wextra",
23 "-Wno-missing-field-initializers",
24 ]
Primiano Tucciae2879e2017-09-27 11:02:09 +090025 if (is_clang) {
26 cflags += [
27 "-Weverything",
28 "-Wno-c++98-compat-pedantic",
29 "-Wno-c++98-compat",
30 "-Wno-gnu-include-next",
31 "-Wno-gnu-statement-expression",
32 "-Wno-padded",
33 "-Wno-reserved-id-macro",
34 "-Wno-unused-parameter",
35 ]
36 }
37}
38
Primiano Tucci0825bc82017-09-28 18:50:23 +010039config("no_exceptions") {
40 cflags = [ "-fno-exceptions" ]
41}
42
43config("no_rtti") {
44 cflags = [ "-fno-rtti" ]
45}
46
Primiano Tucciae2879e2017-09-27 11:02:09 +090047config("default") {
48 asmflags = []
49 cflags = []
50 cflags_c = []
51 cflags_cc = []
52 defines = []
53 ldflags = []
54 libs = []
55
56 include_dirs = [ ".." ]
57
58 cflags_cc += [ "-std=c++11" ]
59
60 cflags += [
Primiano Tucciae2879e2017-09-27 11:02:09 +090061 "-fstrict-aliasing",
62 "-fstack-protector",
63 "-fPIC",
64 "-Wa,--noexecstack",
65 "-Wformat",
66 "-Wall",
67 "-Werror",
68 ]
69
70 if (current_cpu == "arm") {
71 cflags += [
72 "-march=armv7-a",
73 "-mfpu=neon",
74 "-mthumb",
75 ]
76 } else if (current_cpu == "x86") {
77 asmflags += [ "-m32" ]
78 cflags += [
79 "-m32",
80 "-msse2",
81 "-mfpmath=sse",
82 ]
83 ldflags += [ "-m32" ]
84 }
85
86 if (is_linux) {
87 libs += [ "pthread" ]
88 }
89
90 if (is_android) {
Primiano Tucci0825bc82017-09-28 18:50:23 +010091 libs += [ "log" ]
92 }
93
94 if (is_android) {
Primiano Tucciae2879e2017-09-27 11:02:09 +090095 asmflags += [ "--target=$android_abi_target" ]
96 cflags += [
97 "-isystem$android_ndk_root/$android_sysroot_subdir/usr/include",
98 "--sysroot=$android_ndk_root/$android_sysroot_subdir",
99 "-DANDROID",
100 "--target=$android_abi_target",
101 ]
102 cflags_cc += [
103 "-I$android_ndk_root/sources/cxx-stl/llvm-libc++/include",
104 "-I$android_ndk_root/sources/android/support/include",
105 "-I$android_ndk_root/sources/cxx-stl/llvm-libc++abi/include",
106 ]
107 ldflags += [
108 "-Wl,-z,nocopyreloc",
109 "-gcc-toolchain",
110 "$android_toolchain_root",
111 "--sysroot=$android_ndk_root/$android_sysroot_subdir",
112 "--target=$android_abi_target",
113 "-Wl,--exclude-libs,libunwind.a",
114 "-Wl,--exclude-libs,libgcc.a",
115 "-Wl,--exclude-libs,libc++_static.a",
116 "-Wl,--build-id",
117 "-Wl,--no-undefined",
118 "-Wl,-z,noexecstack",
119 "-Wl,-z,relro",
120 "-Wl,-z,now",
121 "-Wl,--warn-shared-textrel",
122 "-Wl,--fatal-warnings",
123 ]
124 lib_dirs = [
125 "$android_ndk_root/sources/cxx-stl/llvm-libc++/libs/$android_app_abi",
126 "$android_ndk_root/$android_sysroot_subdir/usr/lib",
127 ]
128 libs += [
129 "gcc",
130 "c++_static",
131 "c++abi",
132 "android_support",
133 ]
134 }
135}
136
137config("debug_symbols") {
138 if (is_android) {
139 cflags = [
140 "-gline-tables-only",
141 "-funwind-tables",
142 ]
143 } else {
Primiano Tucci0825bc82017-09-28 18:50:23 +0100144 cflags = [ "-g2" ]
145 }
146}
147
148config("runtime_library") {
149 if (use_custom_libcxx) {
150 defines = [
151 "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
152 "_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
153 ]
154 cflags_cc = [
155 "-nostdinc++",
156 "-isystem" + rebase_path("$libcxx_prefix/include", root_build_dir),
157 "-isystem" + rebase_path("$libcxxabi_prefix/include", root_build_dir),
158 ]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900159 }
160}
161
162config("release") {
163 cflags = [
164 "-O3",
165 "-fdata-sections",
166 "-ffunction-sections",
167 ]
168 if (is_mac) {
169 ldflags = [ "-dead_strip" ]
170 } else {
171 ldflags = [ "-Wl,--gc-sections" ]
172 }
173 defines = [ "NDEBUG" ]
174}
175
Primiano Tucci0825bc82017-09-28 18:50:23 +0100176group("exe_and_shlib_deps") {
177 public_deps = []
178 if (using_sanitizer) {
179 public_deps += [ "//build/sanitizers:deps" ]
180 }
181 if (use_custom_libcxx) {
182 public_deps += [ "//buildtools:libc++" ]
183 }
184}
185
186config("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") {
193 if (is_android) {
Primiano Tucciae2879e2017-09-27 11:02:09 +0900194 asmflags = [ "-fPIE" ]
195 cflags = [ "-fPIE" ]
196 ldflags = [
197 "-fPIE",
198 "-pie",
199 ]
200 }
201}