OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import("//build/config/android/config.gni") | 5 import("//build/config/android/config.gni") |
6 import("//build/config/chrome_build.gni") | 6 import("//build/config/chrome_build.gni") |
| 7 import("//build/config/compiler/compiler.gni") |
| 8 import("//build/toolchain/ccache.gni") |
| 9 |
7 if (current_cpu == "arm") { | 10 if (current_cpu == "arm") { |
8 import("//build/config/arm.gni") | 11 import("//build/config/arm.gni") |
9 } | 12 } |
10 if (current_cpu == "mipsel" || current_cpu == "mips64el") { | 13 if (current_cpu == "mipsel" || current_cpu == "mips64el") { |
11 import("//build/config/mips.gni") | 14 import("//build/config/mips.gni") |
12 } | 15 } |
13 if (is_posix) { | 16 if (is_posix) { |
14 import("//build/config/gcc/gcc_version.gni") | 17 import("//build/config/gcc/gcc_version.gni") |
15 } | 18 } |
16 if (is_win) { | 19 if (is_win) { |
17 import("//build/config/win/visual_studio_version.gni") | 20 import("//build/config/win/visual_studio_version.gni") |
18 } | 21 } |
19 | 22 |
20 import("//build/toolchain/ccache.gni") | |
21 import("//build/config/sanitizers/sanitizers.gni") | |
22 | |
23 declare_args() { | 23 declare_args() { |
24 # Normally, Android builds are lightly optimized, even for debug builds, to | 24 # Normally, Android builds are lightly optimized, even for debug builds, to |
25 # keep binary size down. Setting this flag to true disables such optimization | 25 # keep binary size down. Setting this flag to true disables such optimization |
26 android_full_debug = false | 26 android_full_debug = false |
27 | 27 |
28 # Whether to use the binary binutils checked into third_party/binutils. | 28 # Whether to use the binary binutils checked into third_party/binutils. |
29 # These are not multi-arch so cannot be used except on x86 and x86-64 (the | 29 # These are not multi-arch so cannot be used except on x86 and x86-64 (the |
30 # only two architectures that are currently checked in). Turn this off when | 30 # only two architectures that are currently checked in). Turn this off when |
31 # you are using a custom toolchain and need to control -B in cflags. | 31 # you are using a custom toolchain and need to control -B in cflags. |
32 linux_use_bundled_binutils = is_linux && current_cpu == "x64" | 32 linux_use_bundled_binutils = is_linux && current_cpu == "x64" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 # This is a separate config so that third_party code (which would not use the | 77 # This is a separate config so that third_party code (which would not use the |
78 # source root and might have conflicting versions of some headers) can remove | 78 # source root and might have conflicting versions of some headers) can remove |
79 # this and specify their own include paths. | 79 # this and specify their own include paths. |
80 config("default_include_dirs") { | 80 config("default_include_dirs") { |
81 include_dirs = [ | 81 include_dirs = [ |
82 "//", | 82 "//", |
83 root_gen_dir, | 83 root_gen_dir, |
84 ] | 84 ] |
85 } | 85 } |
86 | 86 |
87 # TODO(GYP) bug 527515: is_ubsan, is_ubsan_vptr | |
88 if (!is_win) { | |
89 using_sanitizer = is_asan || is_lsan || is_tsan || is_msan | |
90 } | |
91 | |
92 # compiler --------------------------------------------------------------------- | 87 # compiler --------------------------------------------------------------------- |
93 # | 88 # |
94 # Base compiler configuration. | 89 # Base compiler configuration. |
95 # | 90 # |
96 # See also "runtime_library" below for related stuff and a discussion about | 91 # See also "runtime_library" below for related stuff and a discussion about |
97 # where stuff should go. Put warning related stuff in the "warnings" config. | 92 # where stuff should go. Put warning related stuff in the "warnings" config. |
98 | 93 |
99 config("compiler") { | 94 config("compiler") { |
100 cflags = [] | 95 cflags = [] |
101 cflags_c = [] | 96 cflags_c = [] |
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 cflags += [ "-Wno-incompatible-pointer-types" ] | 1145 cflags += [ "-Wno-incompatible-pointer-types" ] |
1151 } else if (current_cpu == "mipsel") { | 1146 } else if (current_cpu == "mipsel") { |
1152 cflags += [ "-w" ] | 1147 cflags += [ "-w" ] |
1153 } else if (is_chromeos && current_cpu == "arm") { | 1148 } else if (is_chromeos && current_cpu == "arm") { |
1154 cflags += [ "-w" ] | 1149 cflags += [ "-w" ] |
1155 } | 1150 } |
1156 } | 1151 } |
1157 | 1152 |
1158 # Optimization ----------------------------------------------------------------- | 1153 # Optimization ----------------------------------------------------------------- |
1159 # | 1154 # |
1160 # Note that BUILDCONFIG.gn sets up a variable "default_optimization_config" | 1155 # The BUILDCONFIG file sets the "default_optimization" config on targets by |
1161 # which it will assign to the config it implicitly applies to every target. If | 1156 # default. It will be equivalent to either "optimize" (release) or |
1162 # you want to override the optimization level for your target, remove this | 1157 # "no_optimize" (debug) optimization configs. |
1163 # config (which will expand differently for debug or release builds), and then | |
1164 # add back the one you want to override it with: | |
1165 # | 1158 # |
1166 # configs -= default_optimization_config | 1159 # You can override the optimization level on a per-target basis by removing the |
1167 # configs += [ "//build/config/compiler/optimize_max" ] | 1160 # default config and then adding the named one you want: |
| 1161 # |
| 1162 # configs -= [ "//build/config/compiler:default_optimization" ] |
| 1163 # configs += [ "//build/config/compiler:optimize_max" ] |
1168 | 1164 |
1169 # Shared settings for both "optimize" and "optimize_max" configs. | 1165 # Shared settings for both "optimize" and "optimize_max" configs. |
1170 # IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags. | 1166 # IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags. |
1171 if (is_win) { | 1167 if (is_win) { |
1172 common_optimize_on_cflags = [ | 1168 common_optimize_on_cflags = [ |
1173 "/Ob2", # Both explicit and auto inlining. | 1169 "/Ob2", # Both explicit and auto inlining. |
1174 "/Oy-", # Disable omitting frame pointers, must be after /O2. | 1170 "/Oy-", # Disable omitting frame pointers, must be after /O2. |
1175 "/d2Zi+", # Improve debugging of optimized code. | 1171 "/d2Zi+", # Improve debugging of optimized code. |
1176 "/Zc:inline", # Remove unreferenced COMDAT (faster links). | 1172 "/Zc:inline", # Remove unreferenced COMDAT (faster links). |
1177 ] | 1173 ] |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 | 1236 |
1241 if (!using_sanitizer) { | 1237 if (!using_sanitizer) { |
1242 # Functions interposed by the sanitizers can make ld think | 1238 # Functions interposed by the sanitizers can make ld think |
1243 # that some libraries aren't needed when they actually are, | 1239 # that some libraries aren't needed when they actually are, |
1244 # http://crbug.com/234010. As workaround, disable --as-needed. | 1240 # http://crbug.com/234010. As workaround, disable --as-needed. |
1245 common_optimize_on_ldflags += [ "-Wl,--as-needed" ] | 1241 common_optimize_on_ldflags += [ "-Wl,--as-needed" ] |
1246 } | 1242 } |
1247 } | 1243 } |
1248 } | 1244 } |
1249 | 1245 |
1250 # Default "optimization on" config. On Windows, this favors size over speed. | 1246 # Default "optimization on" config. Set up variables so the |
| 1247 # "default_optimization" config can re-use these settings. |
| 1248 if (is_win) { |
| 1249 # Favor size over speed, /O1 must be before the common flags. The GYP |
| 1250 # build also specifies /Os and /GF but these are implied by /O1. |
| 1251 optimize_cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ] |
| 1252 } else if (is_android || is_ios) { |
| 1253 # Favor size over speed. |
| 1254 optimize_cflags = [ "-Os" ] + common_optimize_on_cflags |
| 1255 } else { |
| 1256 # Linux & Mac favor speed over size. |
| 1257 # TODO(brettw) it's weird that Mac and desktop Linux are different. We should |
| 1258 # explore favoring size over speed in this case as well. |
| 1259 optimize_cflags = [ "-O2" ] + common_optimize_on_cflags |
| 1260 } |
| 1261 optimize_ldflags = common_optimize_on_ldflags |
| 1262 |
1251 config("optimize") { | 1263 config("optimize") { |
1252 if (is_win) { | 1264 cflags = optimize_cflags |
1253 # Favor size over speed, /O1 must be before the common flags. The GYP | 1265 ldflags = optimize_ldflags |
1254 # build also specifies /Os and /GF but these are implied by /O1. | |
1255 cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ] | |
1256 } else if (is_android || is_ios) { | |
1257 cflags = [ "-Os" ] + common_optimize_on_cflags # Favor size over speed. | |
1258 } else { | |
1259 cflags = [ "-O2" ] + common_optimize_on_cflags | |
1260 } | |
1261 ldflags = common_optimize_on_ldflags | |
1262 } | 1266 } |
1263 | 1267 |
1264 # Turn off optimizations. | 1268 # Turn off optimizations. Set up variables so the |
| 1269 # "default_optimization" config can re-use these settings. |
| 1270 if (is_win) { |
| 1271 no_optimize_cflags = [ |
| 1272 "/Od", # Disable optimization. |
| 1273 "/Ob0", # Disable all inlining (on by default). |
| 1274 "/RTC1", # Runtime checks for stack frame and uninitialized variables. |
| 1275 ] |
| 1276 no_optimize_ldflags = [] |
| 1277 } else if (is_android && !android_full_debug) { |
| 1278 # On Android we kind of optimize some things that don't affect debugging |
| 1279 # much even when optimization is disabled to get the binary size down. |
| 1280 no_optimize_cflags = [ |
| 1281 "-Os", |
| 1282 "-fdata-sections", |
| 1283 "-ffunction-sections", |
| 1284 ] |
| 1285 if (!using_sanitizer) { |
| 1286 no_optimize_cflags += [ "-fomit-frame-pointer" ] |
| 1287 } |
| 1288 no_optimize_ldflags = common_optimize_on_ldflags |
| 1289 } else { |
| 1290 no_optimize_cflags = [ "-O0" ] |
| 1291 no_optimize_ldflags = [] |
| 1292 } |
| 1293 |
1265 config("no_optimize") { | 1294 config("no_optimize") { |
1266 if (is_win) { | 1295 cflags = no_optimize_cflags |
1267 cflags = [ | 1296 ldflags = no_optimize_ldflags |
1268 "/Od", # Disable optimization. | |
1269 "/Ob0", # Disable all inlining (on by default). | |
1270 "/RTC1", # Runtime checks for stack frame and uninitialized variables. | |
1271 ] | |
1272 } else if (is_android && !android_full_debug) { | |
1273 # On Android we kind of optimize some things that don't affect debugging | |
1274 # much even when optimization is disabled to get the binary size down. | |
1275 cflags = [ | |
1276 "-Os", | |
1277 "-fdata-sections", | |
1278 "-ffunction-sections", | |
1279 ] | |
1280 if (!using_sanitizer) { | |
1281 cflags += [ "-fomit-frame-pointer" ] | |
1282 } | |
1283 ldflags = common_optimize_on_ldflags | |
1284 } else { | |
1285 cflags = [ "-O0" ] | |
1286 } | |
1287 } | 1297 } |
1288 | 1298 |
1289 # Turns up the optimization level. On Windows, this implies whole program | 1299 # Turns up the optimization level. On Windows, this implies whole program |
1290 # optimization and link-time code generation which is very expensive and should | 1300 # optimization and link-time code generation which is very expensive and should |
1291 # be used sparingly. | 1301 # be used sparingly. |
1292 config("optimize_max") { | 1302 config("optimize_max") { |
1293 ldflags = common_optimize_on_ldflags | 1303 ldflags = common_optimize_on_ldflags |
1294 if (is_win) { | 1304 if (is_win) { |
1295 # Favor speed over size, /O2 must be before the common flags. The GYP | 1305 # Favor speed over size, /O2 must be before the common flags. The GYP |
1296 # build also specifies /Ot, /Oi, and /GF, but these are implied by /O2. | 1306 # build also specifies /Ot, /Oi, and /GF, but these are implied by /O2. |
(...skipping 10 matching lines...) Expand all Loading... |
1307 # normal build isn't going to actually be a bug, so the incremental | 1317 # normal build isn't going to actually be a bug, so the incremental |
1308 # value of C4702 for PGO builds is likely very small. | 1318 # value of C4702 for PGO builds is likely very small. |
1309 "/wd4702", | 1319 "/wd4702", |
1310 ] | 1320 ] |
1311 } | 1321 } |
1312 } else { | 1322 } else { |
1313 cflags = [ "-O2" ] + common_optimize_on_cflags | 1323 cflags = [ "-O2" ] + common_optimize_on_cflags |
1314 } | 1324 } |
1315 } | 1325 } |
1316 | 1326 |
| 1327 # The default optimization applied to all targets. This will be equivalent to |
| 1328 # either "optimize" or "no_optimize", depending on the build flags. |
| 1329 config("default_optimization") { |
| 1330 if (is_debug) { |
| 1331 cflags = no_optimize_cflags |
| 1332 ldflags = no_optimize_ldflags |
| 1333 } else { |
| 1334 cflags = optimize_cflags |
| 1335 ldflags = optimize_ldflags |
| 1336 } |
| 1337 } |
| 1338 |
1317 # Symbols ---------------------------------------------------------------------- | 1339 # Symbols ---------------------------------------------------------------------- |
1318 | 1340 |
| 1341 # The BUILDCONFIG file sets the "default_symbols" config on targets by |
| 1342 # default. It will be equivalent to one the three specific symbol levels. |
| 1343 # |
| 1344 # You can override the symbol level on a per-target basis by removing the |
| 1345 # default config and then adding the named one you want: |
| 1346 # |
| 1347 # configs -= [ "//build/config/compiler:default_symbols" ] |
| 1348 # configs += [ "//build/config/compiler:symbols" ] |
| 1349 |
| 1350 # Full symbols. |
| 1351 if (is_win) { |
| 1352 import("//build/toolchain/goma.gni") |
| 1353 if (use_goma) { |
| 1354 symbols_cflags = [ "/Z7" ] # No PDB file |
| 1355 } else { |
| 1356 symbols_cflags = [ "/Zi" ] # Produce PDB file, no edit and continue. |
| 1357 } |
| 1358 if (is_win_fastlink) { |
| 1359 # Tell VS 2015+ to create a PDB that references debug |
| 1360 # information in .obj and .lib files instead of copying |
| 1361 # it all. This flag is incompatible with /PROFILE |
| 1362 symbols_ldflags = [ "/DEBUG:FASTLINK" ] |
| 1363 } else { |
| 1364 symbols_ldflags = [ "/DEBUG" ] |
| 1365 } |
| 1366 } else { |
| 1367 symbols_cflags = [ "-g2" ] |
| 1368 if (use_debug_fission) { |
| 1369 symbols_cflags += [ "-gsplit-dwarf" ] |
| 1370 } |
| 1371 symbols_ldflags = [] |
| 1372 } |
| 1373 |
1319 config("symbols") { | 1374 config("symbols") { |
1320 if (is_win) { | 1375 cflags = symbols_cflags |
1321 import("//build/toolchain/goma.gni") | 1376 ldflags = symbols_ldflags |
1322 if (use_goma) { | 1377 } |
1323 cflags = [ "/Z7" ] # No PDB file | 1378 |
1324 } else { | 1379 # Minimal symbols. |
1325 cflags = [ "/Zi" ] # Produce PDB file, no edit and continue. | 1380 if (is_win) { |
1326 } | 1381 # Linker symbols for backtraces only. |
1327 if (is_win_fastlink) { | 1382 minimal_symbols_cflags = [] |
1328 # Tell VS 2015+ to create a PDB that references debug | 1383 if (is_win_fastlink) { |
1329 # information in .obj and .lib files instead of copying | 1384 # Tell VS 2015+ to create a PDB that references debug |
1330 # it all. This flag is incompatible with /PROFILE | 1385 # information in .obj and .lib files instead of copying |
1331 ldflags = [ "/DEBUG:FASTLINK" ] | 1386 # it all. This flag is incompatible with /PROFILE |
1332 } else { | 1387 minimal_symbols_ldflags = [ "/DEBUG:FASTLINK" ] |
1333 ldflags = [ "/DEBUG" ] | |
1334 } | |
1335 } else { | 1388 } else { |
1336 cflags = [ "-g2" ] | 1389 minimal_symbols_ldflags = [ "/DEBUG" ] |
1337 if (use_debug_fission) { | |
1338 cflags += [ "-gsplit-dwarf" ] | |
1339 } | |
1340 } | 1390 } |
| 1391 } else { |
| 1392 minimal_symbols_cflags = [ "-g1" ] |
| 1393 if (use_debug_fission) { |
| 1394 minimal_symbols_cflags += [ "-gsplit-dwarf" ] |
| 1395 } |
| 1396 minimal_symbols_ldflags = [] |
1341 } | 1397 } |
1342 | 1398 |
1343 config("minimal_symbols") { | 1399 config("minimal_symbols") { |
1344 if (is_win) { | 1400 cflags = minimal_symbols_cflags |
1345 # Linker symbols for backtraces only. | 1401 ldflags = minimal_symbols_ldflags |
1346 if (is_win_fastlink) { | 1402 } |
1347 # Tell VS 2015+ to create a PDB that references debug | 1403 |
1348 # information in .obj and .lib files instead of copying | 1404 # No symbols. |
1349 # it all. This flag is incompatible with /PROFILE | 1405 if (is_win) { |
1350 ldflags = [ "/DEBUG:FASTLINK" ] | 1406 no_symbols_cflags = [] |
1351 } else { | 1407 } else { |
1352 ldflags = [ "/DEBUG" ] | 1408 no_symbols_cflags = [ "-g0" ] |
1353 } | |
1354 } else { | |
1355 cflags = [ "-g1" ] | |
1356 if (use_debug_fission) { | |
1357 cflags += [ "-gsplit-dwarf" ] | |
1358 } | |
1359 } | |
1360 } | 1409 } |
1361 | 1410 |
1362 config("no_symbols") { | 1411 config("no_symbols") { |
1363 if (!is_win) { | 1412 cflags = no_symbols_cflags |
1364 cflags = [ "-g0" ] | 1413 } |
| 1414 |
| 1415 # Default symbols. |
| 1416 config("default_symbols") { |
| 1417 if (symbol_level == 0) { |
| 1418 cflags = no_symbols_cflags |
| 1419 } else if (symbol_level == 1) { |
| 1420 cflags = minimal_symbols_cflags |
| 1421 ldflags = minimal_symbols_ldflags |
| 1422 } else if (symbol_level == 2) { |
| 1423 cflags = symbols_cflags |
| 1424 ldflags = symbols_ldflags |
| 1425 } else { |
| 1426 assert(false) |
1365 } | 1427 } |
1366 } | 1428 } |
OLD | NEW |