Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 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 | |
Primiano Tucci | 7a40e4d | 2017-12-06 09:51:09 +0000 | [diff] [blame] | 15 | import("//gn/standalone/android.gni") |
| 16 | import("//gn/standalone/sanitizers/sanitizers.gni") |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 17 | |
| 18 | config("extra_warnings") { |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 19 | cflags = [ |
| 20 | "-Wextra", |
Primiano Tucci | 765b326 | 2017-11-09 09:47:32 +0000 | [diff] [blame] | 21 | "-Wno-unused-parameter", |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 22 | ] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 23 | if (is_clang) { |
| 24 | cflags += [ |
| 25 | "-Weverything", |
Sami Kyostila | 3a946ae | 2017-09-29 14:56:36 +0100 | [diff] [blame] | 26 | "-Wno-c++98-compat-pedantic", |
Primiano Tucci | 1333134 | 2017-10-25 17:08:13 +0100 | [diff] [blame] | 27 | "-Wno-c++98-compat", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 28 | "-Wno-gnu-include-next", |
| 29 | "-Wno-gnu-statement-expression", |
Primiano Tucci | 1333134 | 2017-10-25 17:08:13 +0100 | [diff] [blame] | 30 | "-Wno-gnu-zero-variadic-macro-arguments", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 31 | "-Wno-padded", |
| 32 | "-Wno-reserved-id-macro", |
Primiano Tucci | ce72002 | 2017-10-30 12:50:06 +0000 | [diff] [blame] | 33 | "-Wno-weak-vtables", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 34 | ] |
| 35 | } |
| 36 | } |
| 37 | |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 38 | config("no_exceptions") { |
| 39 | cflags = [ "-fno-exceptions" ] |
| 40 | } |
| 41 | |
| 42 | config("no_rtti") { |
| 43 | cflags = [ "-fno-rtti" ] |
| 44 | } |
| 45 | |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 46 | config("visibility_hidden") { |
| 47 | cflags = [ "-fvisibility=hidden" ] |
| 48 | } |
| 49 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 50 | config("default") { |
| 51 | asmflags = [] |
| 52 | cflags = [] |
| 53 | cflags_c = [] |
| 54 | cflags_cc = [] |
| 55 | defines = [] |
| 56 | ldflags = [] |
| 57 | libs = [] |
| 58 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 59 | cflags_cc += [ "-std=c++11" ] |
| 60 | |
| 61 | cflags += [ |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 62 | "-fstrict-aliasing", |
| 63 | "-fstack-protector", |
| 64 | "-fPIC", |
| 65 | "-Wa,--noexecstack", |
| 66 | "-Wformat", |
| 67 | "-Wall", |
| 68 | "-Werror", |
| 69 | ] |
| 70 | |
Hector Dearman | 32c32ad | 2017-10-18 11:53:32 +0100 | [diff] [blame] | 71 | # Color compiler output, see https://github.com/ninja-build/ninja/wiki/FAQ |
| 72 | if (is_clang) { |
Primiano Tucci | d7d1be0 | 2017-10-30 17:41:34 +0000 | [diff] [blame] | 73 | cflags += [ |
| 74 | "-fcolor-diagnostics", |
| 75 | "-Wno-unknown-warning-option", |
| 76 | ] |
Primiano Tucci | 7278dea | 2017-10-31 11:50:32 +0000 | [diff] [blame] | 77 | } else { |
| 78 | cflags += [ "-Wno-unknown-warning" ] |
Hector Dearman | 32c32ad | 2017-10-18 11:53:32 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 81 | 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 Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 95 | } else if (current_cpu == "arm64") { |
| 96 | cflags += [ "-fno-omit-frame-pointer" ] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | if (is_linux) { |
Primiano Tucci | 7278dea | 2017-10-31 11:50:32 +0000 | [diff] [blame] | 100 | libs += [ |
| 101 | "pthread", |
| 102 | "rt", |
| 103 | ] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | if (is_android) { |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 107 | libs += [ "log" ] |
| 108 | } |
| 109 | |
| 110 | if (is_android) { |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 111 | asmflags += [ "--target=$android_abi_target" ] |
| 112 | cflags += [ |
Primiano Tucci | b45bfac | 2017-11-28 14:37:48 +0000 | [diff] [blame] | 113 | "--sysroot=$android_compile_sysroot", |
| 114 | "-isystem$android_compile_sysroot/$android_compile_sysroot_subdir", |
| 115 | "-isystem$android_compile_sysroot", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 116 | "-DANDROID", |
Primiano Tucci | b45bfac | 2017-11-28 14:37:48 +0000 | [diff] [blame] | 117 | "-D__ANDROID_API__=21", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 118 | "--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 Tucci | b45bfac | 2017-11-28 14:37:48 +0000 | [diff] [blame] | 129 | "--sysroot=$android_ndk_root/$android_link_sysroot_subdir", |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 130 | "--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 Tucci | b45bfac | 2017-11-28 14:37:48 +0000 | [diff] [blame] | 142 | lib_dirs = [ "$android_ndk_root/sources/cxx-stl/llvm-libc++/libs/$android_app_abi" ] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 143 | libs += [ |
| 144 | "gcc", |
| 145 | "c++_static", |
| 146 | "c++abi", |
| 147 | "android_support", |
| 148 | ] |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | config("debug_symbols") { |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 153 | cflags = [ |
| 154 | "-g", |
| 155 | "-O0", |
| 156 | ] |
| 157 | if (is_android || is_linux) { |
| 158 | cflags += [ "-funwind-tables" ] |
| 159 | ldflags = [ "-rdynamic" ] |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 163 | config("release") { |
| 164 | cflags = [ |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 165 | "-fdata-sections", |
| 166 | "-ffunction-sections", |
| 167 | ] |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 168 | if (is_android) { |
| 169 | cflags += [ "-Oz" ] |
| 170 | } else { |
| 171 | cflags += [ "-O3" ] |
| 172 | } |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 173 | if (is_mac) { |
| 174 | ldflags = [ "-dead_strip" ] |
| 175 | } else { |
Primiano Tucci | 5aab758 | 2017-12-07 12:22:03 +0000 | [diff] [blame] | 176 | ldflags = [ |
| 177 | "-fuse-ld=gold", |
| 178 | "-Wl,--gc-sections", |
| 179 | "-Wl,--icf=all", |
| 180 | "-Wl,-O1", |
| 181 | ] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 182 | } |
| 183 | defines = [ "NDEBUG" ] |
| 184 | } |
| 185 | |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 186 | config("shared_library") { |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 187 | if (is_android || is_linux) { |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 188 | ldflags = [ "-fPIC" ] |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | config("executable") { |
Primiano Tucci | 7278dea | 2017-10-31 11:50:32 +0000 | [diff] [blame] | 193 | 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 Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 197 | if (is_android) { |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 198 | asmflags = [ "-fPIE" ] |
| 199 | cflags = [ "-fPIE" ] |
Primiano Tucci | 7278dea | 2017-10-31 11:50:32 +0000 | [diff] [blame] | 200 | 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 Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 212 | ] |
| 213 | } |
| 214 | } |