mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 1 | # Copyright 2016 Google Inc. |
| 2 | # |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | declare_args() { |
Kevin Lubick | 2677a9a | 2017-03-28 15:45:41 -0400 | [diff] [blame] | 7 | extra_asmflags = [] |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 8 | extra_cflags = [] |
| 9 | extra_cflags_c = [] |
| 10 | extra_cflags_cc = [] |
| 11 | extra_ldflags = [] |
mtklein | cab0bb7 | 2016-08-26 13:43:19 -0700 | [diff] [blame] | 12 | |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 13 | malloc = "" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 14 | } |
Mike Klein | 82364ba | 2016-10-24 16:49:15 -0400 | [diff] [blame] | 15 | |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 16 | if (is_ios) { |
Matthew Leibowitz | 3150ec6 | 2017-03-14 16:22:32 -0400 | [diff] [blame] | 17 | if (is_tvos) { |
| 18 | sdk = "appletvos" |
| 19 | if (target_cpu == "x86" || target_cpu == "x64") { |
| 20 | sdk = "appletvsimulator" |
| 21 | } |
| 22 | } else { |
| 23 | sdk = "iphoneos" |
| 24 | if (target_cpu == "x86" || target_cpu == "x64") { |
| 25 | sdk = "iphonesimulator" |
| 26 | } |
Mike Klein | 7a5e0f3 | 2017-03-13 09:25:33 -0700 | [diff] [blame] | 27 | } |
| 28 | ios_sysroot = exec_script("find_ios_sysroot.py", [ sdk ], "trim string") |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 29 | } |
| 30 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 31 | config("default") { |
| 32 | asmflags = [] |
| 33 | cflags = [] |
| 34 | cflags_c = [] |
| 35 | cflags_cc = [] |
| 36 | defines = [] |
| 37 | ldflags = [] |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 38 | libs = [] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 39 | |
| 40 | if (is_win) { |
| 41 | cflags += [ |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 42 | "/bigobj", # Some of our files are bigger than the regular limits. |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 43 | "/WX", # Treat warnings as errors. |
Ben Wagner | e6b274e | 2017-01-03 17:09:59 -0500 | [diff] [blame] | 44 | "/utf-8", # Set Source and Executable character sets to UTF-8. |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 45 | ] |
Mike Klein | a91ec58 | 2017-07-31 16:35:17 -0400 | [diff] [blame] | 46 | if (is_clang) { |
| 47 | cflags += [ "-fms-compatibility-version=19" ] # 2015 |
| 48 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 49 | defines += [ |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 50 | "_CRT_SECURE_NO_WARNINGS", # Disables warnings about sscanf(). |
| 51 | "_HAS_EXCEPTIONS=0", # Disables exceptions in MSVC STL. |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 52 | "WIN32_LEAN_AND_MEAN", |
| 53 | "NOMINMAX", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 54 | ] |
Mike Klein | 98adfa8 | 2017-07-31 15:46:47 -0400 | [diff] [blame] | 55 | |
Brian Osman | d34c4a3 | 2017-12-06 13:26:38 -0500 | [diff] [blame] | 56 | if (msvc == 2015) { |
Brian Osman | 852ca31 | 2017-12-07 16:16:21 -0500 | [diff] [blame] | 57 | _include_dirs = [ "$win_vc/include" ] |
Brian Osman | 5f87262 | 2017-12-06 15:21:44 -0500 | [diff] [blame] | 58 | } else { # 2017 |
Brian Osman | 852ca31 | 2017-12-07 16:16:21 -0500 | [diff] [blame] | 59 | _include_dirs = [ "$win_vc/Tools/MSVC/$win_toolchain_version/include" ] |
Ravi Mistry | f5ab269 | 2017-12-06 21:51:23 +0000 | [diff] [blame] | 60 | } |
Brian Osman | 5f87262 | 2017-12-06 15:21:44 -0500 | [diff] [blame] | 61 | _include_dirs += [ |
| 62 | "$win_sdk/Include/$win_sdk_version/shared", |
| 63 | "$win_sdk/Include/$win_sdk_version/ucrt", |
| 64 | "$win_sdk/Include/$win_sdk_version/um", |
| 65 | "$win_sdk/Include/$win_sdk_version/winrt", |
| 66 | ] |
| 67 | |
Mike Klein | 98adfa8 | 2017-07-31 15:46:47 -0400 | [diff] [blame] | 68 | if (is_clang) { |
| 69 | foreach(dir, _include_dirs) { |
| 70 | cflags += [ |
| 71 | "-imsvc", |
| 72 | dir, |
| 73 | ] |
| 74 | } |
| 75 | } else { |
| 76 | include_dirs = _include_dirs |
| 77 | } |
| 78 | |
Brian Osman | 5f87262 | 2017-12-06 15:21:44 -0500 | [diff] [blame] | 79 | lib_dirs = [ |
| 80 | "$win_sdk/Lib/$win_sdk_version/ucrt/$target_cpu", |
| 81 | "$win_sdk/Lib/$win_sdk_version/um/$target_cpu", |
| 82 | ] |
Brian Osman | d34c4a3 | 2017-12-06 13:26:38 -0500 | [diff] [blame] | 83 | if (msvc == 2015) { |
Brian Osman | d34c4a3 | 2017-12-06 13:26:38 -0500 | [diff] [blame] | 84 | if (target_cpu == "x86") { |
Brian Osman | 852ca31 | 2017-12-07 16:16:21 -0500 | [diff] [blame] | 85 | lib_dirs += [ "$win_vc/lib" ] |
Brian Osman | d34c4a3 | 2017-12-06 13:26:38 -0500 | [diff] [blame] | 86 | } else { |
Brian Osman | 852ca31 | 2017-12-07 16:16:21 -0500 | [diff] [blame] | 87 | lib_dirs += [ "$win_vc/lib/amd64" ] |
Brian Osman | d34c4a3 | 2017-12-06 13:26:38 -0500 | [diff] [blame] | 88 | } |
Brian Osman | 5f87262 | 2017-12-06 15:21:44 -0500 | [diff] [blame] | 89 | } else { # 2017 |
| 90 | lib_dirs += |
Brian Osman | 852ca31 | 2017-12-07 16:16:21 -0500 | [diff] [blame] | 91 | [ "$win_vc/Tools/MSVC/$win_toolchain_version/lib/$target_cpu" ] |
Mike Klein | 0bc5a76 | 2016-10-12 22:42:55 -0400 | [diff] [blame] | 92 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 93 | } else { |
| 94 | cflags += [ |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 95 | "-fstrict-aliasing", |
| 96 | "-fPIC", |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 97 | "-Werror", |
mtklein | 2b3c2a3 | 2016-09-08 08:39:34 -0700 | [diff] [blame] | 98 | ] |
Mike Klein | 28f5b77 | 2017-04-06 23:04:42 -0400 | [diff] [blame] | 99 | cflags_cc += [ "-std=c++11" ] |
Mike Klein | eec23d1 | 2017-03-26 20:11:48 -0400 | [diff] [blame] | 100 | |
| 101 | # The main idea is to slim the exported API, but these flags also improve link time on Mac. |
| 102 | # These would make stack traces worse on Linux, so we don't just set them willy-nilly. |
Mike Klein | 8cb6648 | 2017-03-28 14:16:22 -0400 | [diff] [blame] | 103 | if (is_component_build || is_ios || is_mac) { |
Mike Klein | eec23d1 | 2017-03-26 20:11:48 -0400 | [diff] [blame] | 104 | cflags += [ "-fvisibility=hidden" ] |
| 105 | cflags_cc += [ "-fvisibility-inlines-hidden" ] |
| 106 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 107 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 108 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 109 | if (current_cpu == "arm") { |
| 110 | cflags += [ |
| 111 | "-march=armv7-a", |
| 112 | "-mfpu=neon", |
| 113 | "-mthumb", |
| 114 | ] |
Mike Klein | 4d4b3aa | 2018-03-21 13:07:35 -0400 | [diff] [blame] | 115 | } else if (current_cpu == "x86" && !is_win) { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 116 | asmflags += [ "-m32" ] |
| 117 | cflags += [ |
| 118 | "-m32", |
| 119 | "-msse2", |
| 120 | "-mfpmath=sse", |
| 121 | ] |
| 122 | ldflags += [ "-m32" ] |
| 123 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 124 | |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 125 | if (malloc != "" && !is_win) { |
| 126 | cflags += [ |
| 127 | "-fno-builtin-malloc", |
| 128 | "-fno-builtin-calloc", |
| 129 | "-fno-builtin-realloc", |
| 130 | "-fno-builtin-free", |
| 131 | ] |
| 132 | libs += [ malloc ] |
| 133 | } |
| 134 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 135 | if (is_android) { |
Derek Sollenberger | 19b2a56 | 2017-06-27 11:55:05 -0400 | [diff] [blame] | 136 | asmflags += [ "--target=$ndk_target" ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 137 | cflags += [ |
Derek Sollenberger | 19b2a56 | 2017-06-27 11:55:05 -0400 | [diff] [blame] | 138 | "--sysroot=$ndk/sysroot", |
| 139 | "-isystem$ndk/sysroot/usr/include/$ndk_target", |
| 140 | "-D__ANDROID_API__=$ndk_api", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 141 | "--target=$ndk_target", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 142 | ] |
| 143 | cflags_cc += [ |
Mike Klein | 21b620c | 2018-01-08 17:16:00 -0500 | [diff] [blame] | 144 | "-isystem$ndk/sources/cxx-stl/llvm-libc++/include", |
| 145 | "-isystem$ndk/sources/cxx-stl/llvm-libc++abi/include", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 146 | "-isystem$ndk/sources/android/support/include", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 147 | ] |
| 148 | ldflags += [ |
| 149 | "--sysroot=$ndk/platforms/$ndk_platform", |
| 150 | "--target=$ndk_target", |
| 151 | "-B$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/$ndk_target/bin", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 152 | ] |
| 153 | lib_dirs = [ |
Mike Klein | 21b620c | 2018-01-08 17:16:00 -0500 | [diff] [blame] | 154 | "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 155 | "$ndk/toolchains/$ndk_gccdir-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x", |
| 156 | ] |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 157 | |
Mike Klein | 21b620c | 2018-01-08 17:16:00 -0500 | [diff] [blame] | 158 | libs += [ |
| 159 | "c++_static", |
| 160 | "c++abi", |
| 161 | "android_support", |
| 162 | ] |
mtklein | 2b3c2a3 | 2016-09-08 08:39:34 -0700 | [diff] [blame] | 163 | } |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 164 | |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 165 | if (is_ios) { |
Mike Klein | b48fd3c | 2017-01-23 11:58:53 -0500 | [diff] [blame] | 166 | _target = target_cpu |
| 167 | if (target_cpu == "arm") { |
| 168 | _target = "armv7" |
Mike Klein | 7a5e0f3 | 2017-03-13 09:25:33 -0700 | [diff] [blame] | 169 | } else if (target_cpu == "x86") { |
| 170 | _target = "i386" |
| 171 | } else if (target_cpu == "x64") { |
| 172 | _target = "x86_64" |
Mike Klein | b48fd3c | 2017-01-23 11:58:53 -0500 | [diff] [blame] | 173 | } |
Mike Klein | 4fe2b15 | 2017-02-17 15:36:01 -0500 | [diff] [blame] | 174 | asmflags += [ |
| 175 | "-isysroot", |
| 176 | ios_sysroot, |
| 177 | "-arch", |
| 178 | _target, |
| 179 | ] |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 180 | cflags += [ |
Mike Klein | 6749af4 | 2016-11-07 15:38:48 -0500 | [diff] [blame] | 181 | "-isysroot", |
| 182 | ios_sysroot, |
| 183 | "-arch", |
Mike Klein | b48fd3c | 2017-01-23 11:58:53 -0500 | [diff] [blame] | 184 | _target, |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 185 | ] |
| 186 | cflags_cc += [ "-stdlib=libc++" ] |
| 187 | ldflags += [ |
Mike Klein | 6749af4 | 2016-11-07 15:38:48 -0500 | [diff] [blame] | 188 | "-isysroot", |
| 189 | ios_sysroot, |
| 190 | "-arch", |
Mike Klein | b48fd3c | 2017-01-23 11:58:53 -0500 | [diff] [blame] | 191 | _target, |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 192 | "-stdlib=libc++", |
| 193 | ] |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 194 | libs += [ "objc" ] |
Mike Klein | 7d30288 | 2016-11-03 14:06:31 -0400 | [diff] [blame] | 195 | } |
| 196 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 197 | if (is_linux) { |
Herb Derby | 76073c1 | 2016-12-08 19:00:40 -0500 | [diff] [blame] | 198 | libs += [ "pthread" ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 199 | } |
Mike Klein | 15f46c3 | 2017-12-07 12:48:57 -0500 | [diff] [blame] | 200 | if (is_mac) { |
| 201 | # Disable linker warnings. They're usually just annoyances like, |
| 202 | # ld: warning: text-based stub file |
| 203 | # /System/Library/Frameworks/foo.framework/foo.tbd and library file |
| 204 | # /System/Library/Frameworks/foo.framework/foo are out of sync. |
| 205 | # Falling back to library file for linking. |
| 206 | ldflags += [ "-Wl,-w" ] |
| 207 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 208 | |
| 209 | if (sanitize != "") { |
| 210 | # You can either pass the sanitizers directly, e.g. "address,undefined", |
| 211 | # or pass one of the couple common aliases used by the bots. |
| 212 | sanitizers = sanitize |
Kevin Lubick | d095040 | 2018-03-20 10:10:58 -0400 | [diff] [blame] | 213 | |
| 214 | # fyi_sanitizers only print out stacktraces of their issues |
| 215 | fyi_sanitizers = fyi_sanitize |
Ben Wagner | 314d7c2 | 2018-01-03 11:04:30 -0500 | [diff] [blame] | 216 | if (sanitize == "ASAN" || sanitize == "UBSAN") { |
| 217 | # ASAN implicitly runs all UBSAN checks also. |
| 218 | sanitizers = "bool,float-cast-overflow,integer-divide-by-zero,nonnull-attribute,null,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound" |
Kevin Lubick | d095040 | 2018-03-20 10:10:58 -0400 | [diff] [blame] | 219 | |
| 220 | if (fyi_sanitize == "" && !is_android) { |
| 221 | fyi_sanitizers = "float-divide-by-zero" |
| 222 | } |
| 223 | |
Ben Wagner | 314d7c2 | 2018-01-03 11:04:30 -0500 | [diff] [blame] | 224 | if (!is_mac && !is_win) { |
| 225 | sanitizers += ",function" # Not supported on Mac or Win. |
Mike Klein | 46d6c68 | 2017-10-05 11:22:09 -0400 | [diff] [blame] | 226 | } |
Ben Wagner | 314d7c2 | 2018-01-03 11:04:30 -0500 | [diff] [blame] | 227 | if (!is_win) { |
| 228 | sanitizers += ",vptr" # Not supported on Win. |
| 229 | } |
| 230 | if (!is_debug && !is_win) { |
| 231 | # No-op with somewhat annoying warning at -O0. |
| 232 | # Seems to be broken on Win. |
| 233 | sanitizers += ",object-size" |
| 234 | } |
| 235 | if (sanitize == "ASAN") { |
| 236 | sanitizers += ",address" |
Mike Klein | e4781e9 | 2017-09-28 11:42:28 -0400 | [diff] [blame] | 237 | } |
Kevin Lubick | 4f0f933 | 2018-01-12 14:31:48 -0500 | [diff] [blame] | 238 | if (is_android) { |
| 239 | # Android only easily supports address for now |
| 240 | # UBSAN runs into linking errors |
| 241 | sanitizers = "address" |
| 242 | |
| 243 | # recommended by |
| 244 | # https://github.com/google/sanitizers/wiki/AddressSanitizerOnAndroid |
| 245 | cflags += [ "-fno-omit-frame-pointer" ] |
| 246 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 247 | } else if (sanitize == "TSAN") { |
| 248 | sanitizers = "thread" |
| 249 | } else if (sanitize == "MSAN") { |
| 250 | sanitizers = "memory" |
| 251 | } |
| 252 | |
| 253 | cflags += [ |
Kevin Lubick | d095040 | 2018-03-20 10:10:58 -0400 | [diff] [blame] | 254 | "-fsanitize=$sanitizers,$fyi_sanitizers", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 255 | "-fno-sanitize-recover=$sanitizers", |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 256 | ] |
Kevin Lubick | 3cda39f | 2018-02-01 12:09:55 -0500 | [diff] [blame] | 257 | if (!is_win) { |
| 258 | cflags += [ "-fno-omit-frame-pointer" ] |
Kevin Lubick | 5798c9f | 2018-02-15 09:45:58 -0500 | [diff] [blame] | 259 | } |
| 260 | if (is_linux) { |
Kevin Lubick | 43bd259 | 2018-02-15 09:03:44 -0500 | [diff] [blame] | 261 | cflags_cc += [ "-stdlib=libc++" ] |
| 262 | ldflags += [ "-stdlib=libc++" ] |
Kevin Lubick | 3cda39f | 2018-02-01 12:09:55 -0500 | [diff] [blame] | 263 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 264 | ldflags += [ "-fsanitize=$sanitizers" ] |
| 265 | if (sanitizers == "memory") { |
| 266 | cflags += [ "-fsanitize-memory-track-origins" ] |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
Mike Klein | 6e55fef | 2016-10-26 11:41:47 -0400 | [diff] [blame] | 271 | config("no_exceptions") { |
Mike Klein | 228276d | 2017-08-16 13:20:20 +0000 | [diff] [blame] | 272 | # Exceptions are disabled by default on Windows. (Use /EHsc to enable them.) |
Mike Klein | 6e55fef | 2016-10-26 11:41:47 -0400 | [diff] [blame] | 273 | if (!is_win) { |
| 274 | cflags_cc = [ "-fno-exceptions" ] |
| 275 | } |
| 276 | } |
| 277 | |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 278 | config("warnings") { |
| 279 | cflags = [] |
| 280 | cflags_cc = [] |
Mike Klein | 43c2526 | 2016-10-20 10:17:47 -0400 | [diff] [blame] | 281 | cflags_objc = [] |
Greg Daniel | 6b7e0e2 | 2017-07-12 16:21:09 -0400 | [diff] [blame] | 282 | cflags_objcc = [] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 283 | if (is_win) { |
| 284 | cflags += [ |
| 285 | "/W3", # Turn on lots of warnings. |
| 286 | |
| 287 | # Disable a bunch of warnings: |
| 288 | "/wd4244", # conversion from 'float' to 'int', possible loss of data |
| 289 | "/wd4267", # conversion from 'size_t' to 'int', possible loss of data |
| 290 | "/wd4800", # forcing value to bool 'true' or 'false' (performance warning) |
| 291 | |
| 292 | # Probably only triggers when /EHsc is enabled. |
| 293 | "/wd4291", # no matching operator delete found; |
| 294 | # memory will not be freed if initialization throws an exception |
| 295 | ] |
| 296 | } else { |
| 297 | cflags += [ |
| 298 | "-Wall", |
| 299 | "-Wextra", |
| 300 | "-Winit-self", |
| 301 | "-Wpointer-arith", |
| 302 | "-Wsign-compare", |
| 303 | "-Wvla", |
| 304 | |
| 305 | "-Wno-deprecated-declarations", |
Mike Klein | db402ca | 2016-12-13 12:46:05 -0500 | [diff] [blame] | 306 | "-Wno-maybe-uninitialized", |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 307 | ] |
Ben Wagner | f8a131d | 2018-03-13 16:56:43 -0400 | [diff] [blame] | 308 | cflags_cc += [ |
| 309 | "-Wnon-virtual-dtor", |
| 310 | "-Wno-noexcept-type", |
| 311 | ] |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 312 | } |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 313 | |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 314 | if (is_clang) { |
| 315 | cflags += [ |
| 316 | "-Weverything", |
| 317 | "-Wno-unknown-warning-option", # Let older Clangs ignore newer Clangs' warnings. |
| 318 | ] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 319 | |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 320 | if (target_cpu == "arm" && is_ios) { |
| 321 | # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit iOS. |
| 322 | # We're pretty sure it's actually 8-byte alignment. |
| 323 | cflags += [ "-Wno-over-aligned" ] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 324 | } |
Mike Klein | 0428279 | 2018-01-08 18:23:32 -0500 | [diff] [blame] | 325 | if (target_cpu == "x86" && is_android) { |
| 326 | # Clang seems to think new/malloc will only be 4-byte aligned on 32-bit x86 Android builds. |
| 327 | # We're pretty sure it's actually 8-byte alignment. See OverAlignedTest.cpp for more info. |
| 328 | cflags += [ "-Wno-over-aligned" ] |
| 329 | } |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 330 | |
| 331 | # Shouldn't be necessary for local builds. With distributed Windows builds, files may lose |
| 332 | # their case during copy, causing case-sensitivity mismatch on remote machines. |
| 333 | cflags += [ |
| 334 | "-Wno-nonportable-include-path", |
| 335 | "-Wno-nonportable-system-include-path", |
| 336 | ] |
| 337 | |
| 338 | # TODO: These would all be really great warnings to turn on. |
| 339 | cflags += [ |
| 340 | "-Wno-cast-align", |
| 341 | "-Wno-cast-qual", |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 342 | "-Wno-conversion", |
| 343 | "-Wno-disabled-macro-expansion", |
| 344 | "-Wno-documentation", |
| 345 | "-Wno-documentation-unknown-command", |
| 346 | "-Wno-double-promotion", |
| 347 | "-Wno-exit-time-destructors", # TODO: OK outside libskia |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 348 | "-Wno-float-equal", |
| 349 | "-Wno-format-nonliteral", |
| 350 | "-Wno-global-constructors", # TODO: OK outside libskia |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 351 | "-Wno-missing-prototypes", |
| 352 | "-Wno-missing-variable-declarations", |
| 353 | "-Wno-pedantic", |
| 354 | "-Wno-reserved-id-macro", |
| 355 | "-Wno-shadow", |
| 356 | "-Wno-shift-sign-overflow", |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 357 | "-Wno-signed-enum-bitfield", |
| 358 | "-Wno-switch-enum", |
| 359 | "-Wno-undef", |
| 360 | "-Wno-unreachable-code", |
| 361 | "-Wno-unreachable-code-break", |
| 362 | "-Wno-unreachable-code-return", |
| 363 | "-Wno-unused-macros", |
| 364 | "-Wno-unused-member-function", |
| 365 | "-Wno-unused-template", |
| 366 | "-Wno-zero-as-null-pointer-constant", |
| 367 | ] |
| 368 | cflags_cc += [ |
| 369 | "-Wno-abstract-vbase-init", |
| 370 | "-Wno-weak-vtables", |
| 371 | ] |
| 372 | |
| 373 | # We are unlikely to want to fix these. |
| 374 | cflags += [ |
| 375 | "-Wno-covered-switch-default", |
| 376 | "-Wno-deprecated", |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 377 | "-Wno-missing-noreturn", |
| 378 | "-Wno-old-style-cast", |
| 379 | "-Wno-padded", |
Chris Dalton | d1ec410 | 2017-12-04 13:31:21 -0700 | [diff] [blame] | 380 | "-Wno-newline-eof", |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 381 | ] |
| 382 | cflags_cc += [ |
| 383 | "-Wno-c++98-compat", |
| 384 | "-Wno-c++98-compat-pedantic", |
| 385 | "-Wno-undefined-func-template", |
| 386 | ] |
| 387 | cflags_objc += [ |
| 388 | "-Wno-direct-ivar-access", |
| 389 | "-Wno-objc-interface-ivars", |
| 390 | ] |
| 391 | cflags_objcc += [ |
| 392 | "-Wno-direct-ivar-access", |
| 393 | "-Wno-objcc-interface-ivars", |
| 394 | ] |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 395 | } |
Mike Klein | ee77da2 | 2018-02-22 15:36:24 -0500 | [diff] [blame] | 396 | if (!is_win || is_clang) { |
| 397 | cflags += [ "-Wno-implicit-fallthrough" ] |
| 398 | } |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 399 | } |
Mike Klein | 50500ad | 2016-11-16 12:13:44 -0500 | [diff] [blame] | 400 | config("warnings_except_public_headers") { |
Chris Dalton | 1ef8094 | 2017-12-04 12:01:30 -0700 | [diff] [blame] | 401 | if (!is_win || is_clang) { |
Mike Klein | 50500ad | 2016-11-16 12:13:44 -0500 | [diff] [blame] | 402 | cflags = [ "-Wno-unused-parameter" ] |
| 403 | } |
| 404 | } |
Mike Klein | c7165c2 | 2016-10-12 23:58:06 -0400 | [diff] [blame] | 405 | |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 406 | config("extra_flags") { |
Kevin Lubick | 2677a9a | 2017-03-28 15:45:41 -0400 | [diff] [blame] | 407 | asmflags = extra_asmflags |
Mike Klein | 121563e | 2016-10-04 17:09:13 -0400 | [diff] [blame] | 408 | cflags = extra_cflags |
| 409 | cflags_c = extra_cflags_c |
| 410 | cflags_cc = extra_cflags_cc |
| 411 | ldflags = extra_ldflags |
| 412 | } |
| 413 | |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 414 | config("debug_symbols") { |
| 415 | # It's annoying to wait for full debug symbols to push over |
| 416 | # to Android devices. -gline-tables-only is a lot slimmer. |
| 417 | if (is_android) { |
Mike Klein | 1b4602b | 2017-08-30 10:23:01 -0400 | [diff] [blame] | 418 | cflags = [ |
| 419 | "-gline-tables-only", |
| 420 | "-funwind-tables", # Helps make in-process backtraces fuller. |
| 421 | ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 422 | } else if (is_win) { |
Mike Klein | 67a86d5 | 2017-12-15 07:34:27 -0500 | [diff] [blame] | 423 | cflags = [ "/Z7" ] |
Brian Osman | a99d982 | 2017-12-28 14:53:10 -0500 | [diff] [blame] | 424 | ldflags = [ "/DEBUG:FASTLINK" ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 425 | } else { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 426 | cflags = [ "-g" ] |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | config("no_rtti") { |
| 431 | if (sanitize != "ASAN") { # -fsanitize=vptr requires RTTI |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 432 | if (is_win) { |
| 433 | cflags_cc = [ "/GR-" ] |
| 434 | } else { |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 435 | cflags_cc = [ "-fno-rtti" ] |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | config("release") { |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 441 | if (is_win) { |
Mike Klein | 916ca1d | 2016-10-20 13:34:18 -0400 | [diff] [blame] | 442 | cflags = [ |
| 443 | "/O2", |
| 444 | "/Zc:inline", |
| 445 | ] |
Mike Klein | 90a381f | 2016-10-20 13:52:38 -0400 | [diff] [blame] | 446 | ldflags = [ |
| 447 | "/OPT:ICF", |
| 448 | "/OPT:REF", |
| 449 | ] |
Mike Klein | cc300a1 | 2016-10-12 16:25:27 -0400 | [diff] [blame] | 450 | } else { |
Mike Klein | 0bcfeac | 2016-10-19 22:24:10 -0400 | [diff] [blame] | 451 | cflags = [ |
| 452 | "-O3", |
Mike Klein | bd9be4d | 2017-02-10 07:59:39 -0500 | [diff] [blame] | 453 | "-fdata-sections", |
| 454 | "-ffunction-sections", |
Mike Klein | 0bcfeac | 2016-10-19 22:24:10 -0400 | [diff] [blame] | 455 | ] |
Mike Klein | bd9be4d | 2017-02-10 07:59:39 -0500 | [diff] [blame] | 456 | if (is_mac || is_ios) { |
| 457 | ldflags = [ "-dead_strip" ] |
| 458 | } else { |
| 459 | ldflags = [ "-Wl,--gc-sections" ] |
| 460 | } |
Kevin Lubick | ebf648e | 2017-09-21 13:45:16 -0400 | [diff] [blame] | 461 | if (target_cpu == "wasm") { |
| 462 | # The compiler asks us to add an optimization flag to both cflags |
| 463 | # and ldflags to cut down on the local variables, |
| 464 | # for performance reasons. |
| 465 | # The "linking" step is the conversion to javascript. |
| 466 | ldflags += [ "-O3" ] |
| 467 | } |
herb | b6318bf | 2016-09-16 13:29:57 -0700 | [diff] [blame] | 468 | } |
mtklein | b9be979 | 2016-09-16 14:44:18 -0700 | [diff] [blame] | 469 | defines = [ "NDEBUG" ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | config("executable") { |
Mike Klein | c5875fb | 2016-12-06 10:46:02 -0500 | [diff] [blame] | 473 | if (is_android) { |
Mike Klein | 1b4602b | 2017-08-30 10:23:01 -0400 | [diff] [blame] | 474 | ldflags = [ |
| 475 | "-pie", |
| 476 | "-rdynamic", |
| 477 | ] |
Mike Klein | c5875fb | 2016-12-06 10:46:02 -0500 | [diff] [blame] | 478 | } else if (is_mac) { |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 479 | ldflags = [ "-Wl,-rpath,@loader_path/." ] |
| 480 | } else if (is_linux) { |
mtklein | a846c72 | 2016-09-15 10:44:15 -0700 | [diff] [blame] | 481 | ldflags = [ |
| 482 | "-rdynamic", |
| 483 | "-Wl,-rpath,\$ORIGIN", |
| 484 | ] |
Mike Klein | 4b6b503 | 2016-11-06 11:54:19 -0500 | [diff] [blame] | 485 | } else if (is_win) { |
| 486 | ldflags = [ |
| 487 | "/SUBSYSTEM:CONSOLE", # Quiet "no subsystem specified; CONSOLE assumed". |
| 488 | "/INCREMENTAL:NO", # Quiet warnings about failing to incrementally link by never trying to. |
| 489 | ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 490 | } |
| 491 | } |