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 3# found in the LICENSE file. 4 5import("//build/config/allocator.gni") 6import("//build/config/c++/c++.gni") 7import("//build/config/coverage/coverage.gni") 8import("//build/config/features.gni") 9 10import("//build/config/sanitizers/sanitizers.gni") 11 12declare_args() { 13 # When set (the default) enables C++ iterator debugging in debug builds. 14 # Iterator debugging is always off in release builds (technically, this flag 15 # affects the "debug" config, which is always available but applied by 16 # default only in debug builds). 17 # 18 # Iterator debugging is generally useful for catching bugs. But it can 19 # introduce extra locking to check the state of an iterator against the state 20 # of the current object. For iterator- and thread-heavy code, this can 21 # significantly slow execution. 22 enable_iterator_debugging = true 23 enable_predefined_macro = false 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 # Don't use deprecated V8 APIs anywhere. 49 defines = [ "V8_DEPRECATION_WARNINGS" ] 50 if (use_udev) { 51 defines += [ "USE_UDEV" ] 52 } 53 if (is_win || is_linux) { 54 defines += [ "USE_AURA=1" ] 55 } 56 if (is_linux) { 57 defines += [ 58 "USE_GLIB=1", 59 "USE_NSS_CERTS=1", 60 "USE_X11=1", 61 ] 62 } 63 64 if ((is_asan || is_lsan || is_tsan || is_msan) && using_sanitizer) { 65 defines += [ 66 "MEMORY_TOOL_REPLACES_ALLOCATOR", 67 "MEMORY_SANITIZER_INITIAL_SIZE", 68 ] 69 } 70 if (is_asan && using_sanitizer) { 71 defines += [ "ADDRESS_SANITIZER" ] 72 } 73 if (is_lsan) { 74 defines += [ "LEAK_SANITIZER" ] 75 } 76 if (is_tsan) { 77 defines += [ 78 "THREAD_SANITIZER", 79 "DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL=1", 80 "WTF_USE_DYNAMIC_ANNOTATIONS_NOIMPL=1", 81 ] 82 } 83 if (is_msan) { 84 defines += [ "MEMORY_SANITIZER" ] 85 } 86 if (is_ubsan || is_ubsan_null || is_ubsan_vptr || is_ubsan_security) { 87 defines += [ "UNDEFINED_SANITIZER" ] 88 } 89 if (use_clang_coverage) { 90 defines += [ "CLANG_COVERAGE" ] 91 } 92 if (is_official_build) { 93 defines += [ "OFFICIAL_BUILD" ] 94 } 95 96 # ============================================== 97 # PLEASE DO NOT ADD MORE THINGS TO THIS LIST 98 # ============================================== 99 # 100 # See the comment at the top. 101} 102 103# Debug/release ---------------------------------------------------------------- 104 105config("debug") { 106 defines = [ 107 "DYNAMIC_ANNOTATIONS_ENABLED=1", 108 "WTF_USE_DYNAMIC_ANNOTATIONS=1", 109 ] 110 111 if (is_nacl) { 112 defines += [ "DYNAMIC_ANNOTATIONS_PREFIX=NACL_" ] 113 } 114 115 if (is_win) { 116 if (!enable_iterator_debugging) { 117 # Iterator debugging is enabled by default by the compiler on debug 118 # builds, and we have to tell it to turn it off. 119 defines += [ "_HAS_ITERATOR_DEBUGGING=0" ] 120 } 121 } else if (is_linux && current_cpu == "x64" && enable_iterator_debugging) { 122 # Enable libstdc++ debugging facilities to help catch problems early, see 123 # http://crbug.com/65151 . 124 # defines += [ "_GLIBCXX_DEBUG=1" ] 125 } 126} 127 128config("release") { 129 defines = [ "NDEBUG" ] 130 131 # Sanitizers. 132 if (is_tsan) { 133 defines += [ 134 "DYNAMIC_ANNOTATIONS_ENABLED=1", 135 "WTF_USE_DYNAMIC_ANNOTATIONS=1", 136 ] 137 } else { 138 defines += [ "NVALGRIND" ] 139 if (!is_nacl) { 140 # NaCl always enables dynamic annotations. Currently this value is set to 141 # 1 for all .nexes. 142 defines += [ "DYNAMIC_ANNOTATIONS_ENABLED=0" ] 143 } 144 } 145} 146 147# define custom board_config 148config("cust_board_config") { 149 cflags = [] 150 cflags_cc = [] 151 ldflags = [] 152 include_dirs = [] 153 defines = [] 154 asmflags = [] 155 if (defined(cust_board_cflags)) { 156 cflags += cust_board_cflags 157 } 158 if (defined(cust_board_cxx_flags)) { 159 cflags_cc += cust_board_cxx_flags 160 } 161 if (defined(cust_board_ld_flags)) { 162 ldflags += cust_board_ld_flags 163 } 164 if (defined(cust_board_include_dirs)) { 165 include_dirs += cust_board_include_dirs 166 } 167 if (defined(cust_board_macro_defines)) { 168 defines += cust_board_macro_defines 169 } 170 if (defined(cust_board_asmflags)) { 171 asmflags += cust_board_asmflags 172 } 173} 174 175# Default libraries ------------------------------------------------------------ 176 177# This config defines the default libraries applied to all targets. 178config("default_libs") { 179 if (is_win) { 180 libs = [ 181 "advapi32.lib", 182 "comdlg32.lib", 183 "dbghelp.lib", 184 "dnsapi.lib", 185 "gdi32.lib", 186 "msimg32.lib", 187 "odbc32.lib", 188 "odbccp32.lib", 189 "oleaut32.lib", 190 "psapi.lib", 191 "shell32.lib", 192 "shlwapi.lib", 193 "user32.lib", 194 "usp10.lib", 195 "uuid.lib", 196 "version.lib", 197 "wininet.lib", 198 "winmm.lib", 199 "winspool.lib", 200 "ws2_32.lib", 201 202 # Please don't add more stuff here. We should actually be making this 203 # list smaller, since all common things should be covered. If you need 204 # some extra libraries, please just add a libs = [ "foo.lib" ] to your 205 # target that needs it. 206 ] 207 if (current_os == "winuwp") { 208 # These libraries are needed for Windows UWP (i.e. store apps). 209 libs += [ 210 "dloadhelper.lib", 211 "WindowsApp.lib", 212 ] 213 } else { 214 # These libraries are not compatible with Windows UWP (i.e. store apps.) 215 libs += [ 216 "delayimp.lib", 217 "kernel32.lib", 218 "ole32.lib", 219 ] 220 } 221 } else if (is_ohos) { 222 libs = [ 223 "dl", 224 "m", 225 ] 226 } else if (is_mac) { 227 # Targets should choose to explicitly link frameworks they require. Since 228 # linking can have run-time side effects, nothing should be listed here. 229 libs = [] 230 } else if (is_linux) { 231 libs = [ 232 "dl", 233 "pthread", 234 "rt", 235 ] 236 } 237} 238 239# Only //build/config/BUILDCONFIG.gn should reference this. 240group("common_deps") { 241 public_deps = [] 242 243 if (using_sanitizer) { 244 public_deps += [ "//build/config/sanitizers:deps" ] 245 } 246 247 if (use_custom_libcxx) { 248 if (is_double_framework) { 249 public_deps += [ "${asdk_libs_dir}/ndk/libcxx:libcxx" ] 250 } else { 251 public_deps += [ "//third_party/libcxx:libcxx" ] 252 } 253 } 254 255 if (use_afl) { 256 public_deps += [ "//third_party/afl" ] 257 } 258 259 if (is_ohos && use_order_profiling) { 260 public_deps += [] 261 } 262 263 if (use_musl && current_toolchain != host_toolchain && !is_mingw) { 264 public_deps += [ "//third_party/musl:soft_shared_libs" ] 265 } 266 267 if (is_ohos && ohos_indep_compiler_enable && 268 current_toolchain != host_toolchain) { 269 public_deps += [ "//build/common/ubsan:ubsan" ] 270 } 271} 272 273group("executable_deps") { 274 public_deps = [ ":common_deps" ] 275 if (export_libcxxabi_from_executables) { 276 if (!is_double_framework) { 277 public_deps += [ "//third_party/libcxxabi:libc++abi" ] 278 } 279 } 280} 281 282group("loadable_module_deps") { 283 public_deps = [ ":common_deps" ] 284} 285 286group("shared_library_deps") { 287 public_deps = [ ":common_deps" ] 288} 289 290group("rust_library_deps") { 291 public_deps = [ ":common_deps" ] 292} 293 294group("rust_proc_macro_deps") { 295 public_deps = [ ":common_deps" ] 296} 297 298group("static_library_deps") { 299 if (use_musl && current_toolchain != host_toolchain && !is_mingw) { 300 public_deps = [ "//third_party/musl:musl_headers" ] 301 } 302} 303 304group("source_set_deps") { 305 if (use_musl && current_toolchain != host_toolchain && !is_mingw) { 306 public_deps = [ "//third_party/musl:musl_headers" ] 307 } 308} 309 310# Executable configs ----------------------------------------------------------- 311 312# Windows linker setup for EXEs and DLLs. 313if (is_win) { 314 _windows_linker_configs = [ 315 "//build/config/win:sdk_link", 316 "//build/config/win:common_linker_setup", 317 ] 318} 319 320# This config defines the configs applied to all executables. 321config("executable_config") { 322 configs = [] 323 324 if (is_win) { 325 configs += _windows_linker_configs 326 327 # Currently only turn on linker CFI for executables. 328 configs += [ "//build/config/win:cfi_linker" ] 329 } else if (is_mac) { 330 configs += [ "//build/config/mac:mac_dynamic_flags" ] 331 } else if (is_linux || is_ohos || current_os == "aix") { 332 configs += [ "//build/config/gcc:executable_ldconfig" ] 333 if (is_ohos) { 334 configs += [ "//build/config/ohos:executable_config" ] 335 } else if (is_linux) { 336 configs += [ "//build/config/linux:executable_config" ] 337 } 338 } 339 340 # If we're using the prebuilt instrumented libraries with the sanitizers, we 341 # need to add ldflags to every binary to make sure they are picked up. 342 if (prebuilt_instrumented_libraries_available) { 343 configs += [ "//third_party/instrumented_libraries:prebuilt_ldflags" ] 344 } 345 if (use_locally_built_instrumented_libraries) { 346 configs += [ "//third_party/instrumented_libraries:locally_built_ldflags" ] 347 } 348 configs += [ "//build/config/sanitizers:link_executable" ] 349} 350 351# Shared library configs ------------------------------------------------------- 352 353# This config defines the configs applied to all shared libraries. 354config("shared_library_config") { 355 configs = [] 356 357 if (is_win) { 358 configs += _windows_linker_configs 359 } else if (is_mac) { 360 configs += [ "//build/config/mac:mac_dynamic_flags" ] 361 } 362 363 # If we're using the prebuilt instrumented libraries with the sanitizers, we 364 # need to add ldflags to every binary to make sure they are picked up. 365 if (prebuilt_instrumented_libraries_available) { 366 configs += [ "//third_party/instrumented_libraries:prebuilt_ldflags" ] 367 } 368 if (use_locally_built_instrumented_libraries) { 369 configs += [ "//third_party/instrumented_libraries:locally_built_ldflags" ] 370 } 371 configs += [ "//build/config/sanitizers:link_shared_library" ] 372} 373 374config("predefined_macro") { 375 if (enable_predefined_macro) { 376 defines = [] 377 if (is_ohos) { 378 defines += [ "__OHOS__" ] 379 } 380 if (is_mac) { 381 defines += [ "__MAC__" ] 382 } 383 if (is_linux) { 384 defines += [ "__LINUX__" ] 385 } 386 if (is_nacl) { 387 defines += [ "__NACL__" ] 388 } 389 if (is_win) { 390 defines += [ "__WINDOWS__" ] 391 } 392 if (is_mingw) { 393 defines += [ "___MINGW32__" ] 394 } 395 if (is_android) { 396 defines += [ "__ANDROID__" ] 397 } 398 if (is_ios) { 399 defines += [ "__IOS__" ] 400 } 401 if (current_cpu == "x86") { 402 defines += [ "__x86_32__" ] 403 } 404 if (current_cpu == "x86_64") { 405 defines += [ "__x86_64__" ] 406 } 407 if (current_cpu == "arm") { 408 defines += [ "__arm32__" ] 409 } 410 if (current_cpu == "arm64") { 411 defines += [ "__arm64__" ] 412 } 413 } 414} 415