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