BUILD.gn (14254B)
1 # Copyright 2013 The Chromium Authors 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 import("//chromium/build/config/c++/c++.gni") 6 import("//chromium/build/config/cast.gni") 7 import("//chromium/build/config/chrome_build.gni") 8 import("//chromium/build/config/dcheck_always_on.gni") 9 import("//chromium/build/config/features.gni") 10 11 # Subprojects need to override arguments in {mac,ios}_sdk_overrides.gni in their 12 # .gn config, but those arguments are only used on macOS. Including 13 # mac_sdk_overrides.gni insures that this doesn't trigger an unused argument 14 # warning. 15 import("//chromium/build/config/ios/ios_sdk_overrides.gni") 16 import("//chromium/build/config/mac/mac_sdk_overrides.gni") 17 18 import("//chromium/build/config/pch.gni") 19 import("//chromium/build/config/rust.gni") 20 import("//chromium/build/config/sanitizers/sanitizers.gni") 21 import("//chromium/build/config/ui.gni") 22 if (is_android) { 23 import("//chromium/build/config/android/abi.gni") 24 } 25 26 # ============================================== 27 # PLEASE DO NOT ADD MORE THINGS TO THIS LIST 28 # ============================================== 29 # 30 # Legacy feature defines applied to all targets. 31 # 32 # These are applied to every single compile in the build and most of them are 33 # only relevant to a few files. This bloats command lines and causes 34 # unnecessary recompiles when flags are flipped. 35 # 36 # To pass defines to source code from the build, use the buildflag system which 37 # will write headers containing the defines you need. This isolates the define 38 # and means its definition can participate in the build graph, only recompiling 39 # things when it actually changes. 40 # 41 # See //build/buildflag_header.gni for instructions on generating headers. 42 # 43 # This will also allow you to scope your build flag to a BUILD.gn file (or a 44 # .gni file if you need it from more than one place) rather than making global 45 # flags. See //build/config/BUILDCONFIG.gn for advice on where to define 46 # build flags. 47 config("feature_flags") { 48 defines = [] 49 rustflags = [] 50 if (dcheck_always_on) { 51 defines += [ "DCHECK_ALWAYS_ON=1" ] 52 rustflags += [ "-Cdebug-assertions" ] 53 } 54 if (use_udev) { 55 # TODO(brettw) should probably be "=1". 56 defines += [ "USE_UDEV" ] 57 } 58 if (use_aura) { 59 defines += [ "USE_AURA=1" ] 60 } 61 if (use_glib) { 62 defines += [ "USE_GLIB=1" ] 63 } 64 if (use_ozone && !is_android) { 65 # Chrome code should check BUILDFLAG(IS_OZONE) instead of 66 # defined(USE_OZONE). 67 # 68 # Note that some Chrome OS builds unconditionally set |use_ozone| to true, 69 # but they also build some targets with the Android toolchain. This ensures 70 # that Android targets still build with USE_OZONE=0 in such cases. 71 # 72 # TODO(crbug.com/41385586): Maybe this can be cleaned up if we can avoid 73 # setting use_ozone globally. 74 defines += [ "USE_OZONE=1" ] 75 } 76 if (is_asan || is_hwasan || is_lsan || is_tsan || is_msan) { 77 defines += [ "MEMORY_TOOL_REPLACES_ALLOCATOR" ] 78 } 79 if (is_asan) { 80 defines += [ "ADDRESS_SANITIZER" ] 81 } 82 if (is_lsan) { 83 defines += [ "LEAK_SANITIZER" ] 84 } 85 if (is_tsan) { 86 defines += [ 87 "THREAD_SANITIZER", 88 "DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL=1", 89 ] 90 } 91 if (is_msan) { 92 defines += [ "MEMORY_SANITIZER" ] 93 } 94 if (is_ubsan_any) { 95 defines += [ "UNDEFINED_SANITIZER" ] 96 } 97 if (is_official_build) { 98 defines += [ "OFFICIAL_BUILD" ] 99 } 100 101 # ============================================== 102 # PLEASE DO NOT ADD MORE THINGS TO THIS LIST 103 # ============================================== 104 # 105 # See the comment at the top. 106 } 107 108 # Debug/release ---------------------------------------------------------------- 109 110 config("debug") { 111 defines = [ 112 "DYNAMIC_ANNOTATIONS_ENABLED=1", 113 ] 114 if (!is_win) { 115 defines += [ "_DEBUG" ] 116 } 117 if (is_nacl) { 118 defines += [ "DYNAMIC_ANNOTATIONS_PREFIX=NACL_" ] 119 } 120 121 if (is_win) { 122 if (!enable_iterator_debugging && !use_custom_libcxx) { 123 # Iterator debugging is enabled by default by the compiler on debug 124 # builds, and we have to tell it to turn it off. 125 defines += [ "_HAS_ITERATOR_DEBUGGING=0" ] 126 } 127 } else if ((is_linux || is_chromeos) && target_cpu == "x64" && 128 enable_iterator_debugging) { 129 # Enable libstdc++ debugging facilities to help catch problems early, see 130 # http://crbug.com/65151 . 131 # TODO(phajdan.jr): Should we enable this for all of POSIX? 132 #defines += [ "_GLIBCXX_DEBUG=1" ] 133 } 134 } 135 136 config("release") { 137 defines = [ "NDEBUG" ] 138 139 # Sanitizers. 140 if (is_tsan) { 141 defines += [ "DYNAMIC_ANNOTATIONS_ENABLED=1" ] 142 } else { 143 defines += [ "NVALGRIND" ] 144 if (!is_nacl) { 145 # NaCl always enables dynamic annotations. Currently this value is set to 146 # 1 for all .nexes. 147 defines += [ "DYNAMIC_ANNOTATIONS_ENABLED=0" ] 148 } 149 } 150 151 if (is_ios) { 152 # Disable NSAssert and GTMDevAssert (from Google Toolbox for Mac). This 153 # follows XCode's default behavior for Release builds. 154 defines += [ "NS_BLOCK_ASSERTIONS=1" ] 155 } 156 } 157 158 # Default libraries ------------------------------------------------------------ 159 160 # This config defines the default libraries applied to all targets. 161 config("default_libs") { 162 if (is_win) { 163 # TODO(brettw) this list of defaults should probably be smaller, and 164 # instead the targets that use the less common ones (e.g. wininet or 165 # winspool) should include those explicitly. 166 libs = [ 167 "advapi32.lib", 168 "comdlg32.lib", 169 "dbghelp.lib", 170 "dnsapi.lib", 171 "gdi32.lib", 172 "msimg32.lib", 173 "odbc32.lib", 174 "odbccp32.lib", 175 "oleaut32.lib", 176 "shell32.lib", 177 "shlwapi.lib", 178 "user32.lib", 179 "usp10.lib", 180 "uuid.lib", 181 "version.lib", 182 "wininet.lib", 183 "winmm.lib", 184 "winspool.lib", 185 "ws2_32.lib", 186 187 # Please don't add more stuff here. We should actually be making this 188 # list smaller, since all common things should be covered. If you need 189 # some extra libraries, please just add a libs = [ "foo.lib" ] to your 190 # target that needs it. 191 ] 192 if (current_os == "winuwp") { 193 # These libraries are needed for Windows UWP (i.e. store apps). 194 libs += [ 195 "dloadhelper.lib", 196 "WindowsApp.lib", 197 ] 198 } else { 199 # These libraries are not compatible with Windows UWP (i.e. store apps.) 200 libs += [ 201 "delayimp.lib", 202 "kernel32.lib", 203 "ole32.lib", 204 ] 205 } 206 } else if (is_android) { 207 libs = [ 208 "dl", 209 "m", 210 ] 211 } else if (is_mac) { 212 # Targets should choose to explicitly link frameworks they require. Since 213 # linking can have run-time side effects, nothing should be listed here. 214 libs = [] 215 } else if (is_ios) { 216 # Targets should choose to explicitly link frameworks they require. Since 217 # linking can have run-time side effects, nothing should be listed here. 218 libs = [] 219 } else if (is_linux || is_chromeos) { 220 libs = [ 221 "dl", 222 "pthread", 223 "rt", 224 ] 225 } 226 } 227 228 _toolchain_marker_name = 229 "toolchain_marker_" + get_label_info(current_toolchain, "name") 230 group(_toolchain_marker_name) { 231 # Can be used as an assert_no_deps target (assert_no_deps ignores toolchains). 232 } 233 234 group("common_deps_without_libcxx") { 235 # WARNING: This group is a dependency of **every executable and shared 236 # library**. Please be careful adding new dependencies here. 237 public_deps = [ ":$_toolchain_marker_name" ] 238 239 if (using_sanitizer) { 240 public_deps += [ "//chromium/build/config/sanitizers:deps" ] 241 } 242 243 if (use_libfuzzer) { 244 public_deps += [ "//chromium/build/config/sanitizers:dlclose_shim" ] 245 } 246 247 if (use_afl) { 248 public_deps += [ "//third_party/afl" ] 249 } 250 251 if (is_android && use_order_profiling) { 252 public_deps += [ "//base/android/orderfile:orderfile_instrumentation" ] 253 } 254 255 if (is_fuchsia) { 256 public_deps += 257 [ "//third_party/fuchsia-gn-sdk/src/config:runtime_library_group" ] 258 if (is_asan) { 259 public_deps += [ "//chromium/build/config/fuchsia:asan_runtime_library" ] 260 } 261 } 262 263 if (is_win) { 264 if (build_with_chromium && is_component_build) { 265 # To enable allocator_shim for the windows component built chrome, 266 # need to make all shared libraries and also executable(i.e.chrome.exe) 267 # depend on PartitionAlloc. 268 public_deps += [ "//base/allocator/partition_allocator/src/partition_alloc:win_component_build_adapter" ] 269 } 270 271 # The CRT runtime is dynamically linked in component builds and needs to 272 # be present on bots that run exes or load DLLs. This also includes 273 # debugging DLLs in all builds. 274 data_deps = [ "//chromium/build/win:runtime_libs" ] 275 276 if (host_os == "win") { 277 # In order to ensure the ACLing is applied to every binary loaded in an 278 # app container sandbox, run the ACL step before any binary is built. We 279 # do this because the tool is subject to race conditions if a binary is 280 # placed in the out folder while it is running. 281 public_deps += 282 [ "//chromium/build/config/win:maybe_set_appcontainer_acls($host_toolchain)" ] 283 } 284 } 285 } 286 287 group("common_deps") { 288 visibility = [ 289 ":executable_deps", 290 ":loadable_module_deps", 291 ":shared_library_deps", 292 ] 293 294 # WARNING: This group is a dependency of **every executable and shared 295 # library**. Please be careful adding new dependencies here. 296 public_deps = [ ":common_deps_without_libcxx" ] 297 298 if (use_custom_libcxx) { 299 public_deps += [ "//buildtools/third_party/libc++" ] 300 } 301 } 302 303 # Only the executable template in BUILDCONFIG.gn should reference this. 304 group("executable_deps") { 305 if (!toolchain_for_rust_host_build_tools) { 306 public_deps = [ ":common_deps" ] 307 if (export_libcxxabi_from_executables) { 308 public_deps += [ "//buildtools/third_party/libc++abi" ] 309 } 310 } 311 } 312 313 # Only the loadable_module template in BUILDCONFIG.gn should reference this. 314 group("loadable_module_deps") { 315 if (!toolchain_for_rust_host_build_tools) { 316 public_deps = [ ":common_deps" ] 317 } 318 } 319 320 # Only the shared_library template in BUILDCONFIG.gn should reference this. 321 group("shared_library_deps") { 322 if (!toolchain_for_rust_host_build_tools) { 323 public_deps = [ ":common_deps" ] 324 } 325 } 326 327 # Executable configs ----------------------------------------------------------- 328 329 # Windows linker setup for EXEs and DLLs. 330 if (is_win) { 331 _windows_linker_configs = [ 332 "//chromium/build/config/win:sdk_link", 333 "//chromium/build/config/win:common_linker_setup", 334 ] 335 } 336 337 # This config defines the configs applied to all executables. 338 config("executable_config") { 339 configs = [] 340 341 if (is_win) { 342 configs += _windows_linker_configs 343 } else if (is_mac) { 344 configs += [ "//chromium/build/config/mac:mac_dynamic_flags" ] 345 } else if (is_ios) { 346 configs += [ 347 "//chromium/build/config/ios:ios_dynamic_flags", 348 "//chromium/build/config/ios:ios_executable_flags", 349 ] 350 } else if (is_linux || is_chromeos || is_android || current_os == "aix") { 351 configs += [ "//chromium/build/config/gcc:executable_config" ] 352 if (is_castos || is_cast_android) { 353 configs += [ "//chromium/build/config/chromecast:executable_config" ] 354 } 355 } 356 357 # If we're using the prebuilt instrumented libraries with the sanitizers, we 358 # need to add ldflags to every binary to make sure they are picked up. 359 if (prebuilt_instrumented_libraries_available) { 360 configs += [ "//third_party/instrumented_libs:prebuilt_ldflags" ] 361 } 362 if (use_locally_built_instrumented_libraries) { 363 configs += [ "//third_party/instrumented_libs:locally_built_ldflags" ] 364 } 365 } 366 367 # Shared library configs ------------------------------------------------------- 368 369 # This config defines the configs applied to all shared libraries. 370 config("shared_library_config") { 371 configs = [] 372 373 if (is_win) { 374 configs += _windows_linker_configs 375 } else if (is_mac) { 376 configs += [ "//chromium/build/config/mac:mac_dynamic_flags" ] 377 } else if (is_ios) { 378 configs += [ 379 "//chromium/build/config/ios:ios_dynamic_flags", 380 "//chromium/build/config/ios:ios_shared_library_flags", 381 ] 382 } else if (is_castos || is_cast_android) { 383 configs += [ "//chromium/build/config/chromecast:shared_library_config" ] 384 } else if (is_linux || is_chromeos || current_os == "aix") { 385 configs += [ "//chromium/build/config/gcc:shared_library_config" ] 386 } 387 388 # If we're using the prebuilt instrumented libraries with the sanitizers, we 389 # need to add ldflags to every binary to make sure they are picked up. 390 if (prebuilt_instrumented_libraries_available) { 391 configs += [ "//third_party/instrumented_libs:prebuilt_ldflags" ] 392 } 393 if (use_locally_built_instrumented_libraries) { 394 configs += [ "//third_party/instrumented_libs:locally_built_ldflags" ] 395 } 396 } 397 398 # Add this config to your target to enable precompiled headers. 399 # 400 # Precompiled headers are done on a per-target basis. If you have just a couple 401 # of files, the time it takes to precompile (~2 seconds) can actually be longer 402 # than the time saved. On a Z620, a 100 file target compiles about 2 seconds 403 # faster with precompiled headers, with greater savings for larger targets. 404 # 405 # Recommend precompiled headers for targets with more than 50 .cc files. 406 config("precompiled_headers") { 407 if (enable_precompiled_headers) { 408 if (is_win) { 409 # This is a string rather than a file GN knows about. It has to match 410 # exactly what's in the /FI flag below, and what might appear in the 411 # source code in quotes for an #include directive. 412 precompiled_header = "build/precompile.h" 413 414 # This is a file that GN will compile with the above header. It will be 415 # implicitly added to the sources (potentially multiple times, with one 416 # variant for each language used in the target). 417 precompiled_source = "//chromium/build/precompile.cc" 418 419 # Force include the header. 420 cflags = [ "/FI$precompiled_header" ] 421 } else if (is_mac || is_linux) { 422 precompiled_source = "//chromium/build/precompile.h" 423 } 424 } 425 } 426 427 # Add this config to link steps in order to compress debug sections. This is 428 # especially useful on 32-bit architectures in order to keep file sizes under 429 # 4gb. 430 config("compress_debug_sections") { 431 ldflags = [ "-gz" ] 432 }