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} 24 25# ============================================== 26# PLEASE DO NOT ADD MORE THINGS TO THIS LIST 27# ============================================== 28# 29# Legacy feature defines applied to all targets. 30# 31# These are applied to every single compile in the build and most of them are 32# only relevant to a few files. This bloats command lines and causes 33# unnecessary recompiles when flags are flipped. 34# 35# To pass defines to source code from the build, use the buildflag system which 36# will write headers containing the defines you need. This isolates the define 37# and means its definition can participate in the build graph, only recompiling 38# things when it actually changes. 39# 40# See //build/buildflag_header.gni for instructions on generating headers. 41# 42# This will also allow you to scope your build flag to a BUILD.gn file (or a 43# .gni file if you need it from more than one place) rather than making global 44# flags. See //build/config/BUILDCONFIG.gn for advice on where to define 45# build flags. 46config("feature_flags") { 47 # Don't use deprecated V8 APIs anywhere. 48 defines = [ "V8_DEPRECATION_WARNINGS" ] 49 if (use_udev) { 50 defines += [ "USE_UDEV" ] 51 } 52 if (is_win || is_linux) { 53 defines += [ "USE_AURA=1" ] 54 } 55 if (is_linux) { 56 defines += [ 57 "USE_GLIB=1", 58 "USE_NSS_CERTS=1", 59 "USE_X11=1", 60 ] 61 } 62 63 if ((is_asan || is_lsan || is_tsan || is_msan) && using_sanitizer) { 64 defines += [ 65 "MEMORY_TOOL_REPLACES_ALLOCATOR", 66 "MEMORY_SANITIZER_INITIAL_SIZE", 67 ] 68 } 69 if (is_asan && using_sanitizer) { 70 defines += [ "ADDRESS_SANITIZER" ] 71 } 72 if (is_lsan) { 73 defines += [ "LEAK_SANITIZER" ] 74 } 75 if (is_tsan) { 76 defines += [ 77 "THREAD_SANITIZER", 78 "DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL=1", 79 "WTF_USE_DYNAMIC_ANNOTATIONS_NOIMPL=1", 80 ] 81 } 82 if (is_msan) { 83 defines += [ "MEMORY_SANITIZER" ] 84 } 85 if (is_ubsan || is_ubsan_null || is_ubsan_vptr || is_ubsan_security) { 86 defines += [ "UNDEFINED_SANITIZER" ] 87 } 88 if (use_clang_coverage) { 89 defines += [ "CLANG_COVERAGE" ] 90 } 91 if (is_official_build) { 92 defines += [ "OFFICIAL_BUILD" ] 93 } 94 95 # ============================================== 96 # PLEASE DO NOT ADD MORE THINGS TO THIS LIST 97 # ============================================== 98 # 99 # See the comment at the top. 100} 101 102# Debug/release ---------------------------------------------------------------- 103 104config("debug") { 105 defines = [ 106 "DYNAMIC_ANNOTATIONS_ENABLED=1", 107 "WTF_USE_DYNAMIC_ANNOTATIONS=1", 108 ] 109 110 if (is_nacl) { 111 defines += [ "DYNAMIC_ANNOTATIONS_PREFIX=NACL_" ] 112 } 113 114 if (is_win) { 115 if (!enable_iterator_debugging) { 116 # Iterator debugging is enabled by default by the compiler on debug 117 # builds, and we have to tell it to turn it off. 118 defines += [ "_HAS_ITERATOR_DEBUGGING=0" ] 119 } 120 } else if (is_linux && current_cpu == "x64" && enable_iterator_debugging) { 121 # Enable libstdc++ debugging facilities to help catch problems early, see 122 # http://crbug.com/65151 . 123 # defines += [ "_GLIBCXX_DEBUG=1" ] 124 } 125} 126 127config("release") { 128 defines = [ "NDEBUG" ] 129 130 # Sanitizers. 131 if (is_tsan) { 132 defines += [ 133 "DYNAMIC_ANNOTATIONS_ENABLED=1", 134 "WTF_USE_DYNAMIC_ANNOTATIONS=1", 135 ] 136 } else { 137 defines += [ "NVALGRIND" ] 138 if (!is_nacl) { 139 # NaCl always enables dynamic annotations. Currently this value is set to 140 # 1 for all .nexes. 141 defines += [ "DYNAMIC_ANNOTATIONS_ENABLED=0" ] 142 } 143 } 144} 145 146# Default libraries ------------------------------------------------------------ 147 148# This config defines the default libraries applied to all targets. 149config("default_libs") { 150 if (is_win) { 151 libs = [ 152 "advapi32.lib", 153 "comdlg32.lib", 154 "dbghelp.lib", 155 "dnsapi.lib", 156 "gdi32.lib", 157 "msimg32.lib", 158 "odbc32.lib", 159 "odbccp32.lib", 160 "oleaut32.lib", 161 "psapi.lib", 162 "shell32.lib", 163 "shlwapi.lib", 164 "user32.lib", 165 "usp10.lib", 166 "uuid.lib", 167 "version.lib", 168 "wininet.lib", 169 "winmm.lib", 170 "winspool.lib", 171 "ws2_32.lib", 172 173 # Please don't add more stuff here. We should actually be making this 174 # list smaller, since all common things should be covered. If you need 175 # some extra libraries, please just add a libs = [ "foo.lib" ] to your 176 # target that needs it. 177 ] 178 if (current_os == "winuwp") { 179 # These libraries are needed for Windows UWP (i.e. store apps). 180 libs += [ 181 "dloadhelper.lib", 182 "WindowsApp.lib", 183 ] 184 } else { 185 # These libraries are not compatible with Windows UWP (i.e. store apps.) 186 libs += [ 187 "delayimp.lib", 188 "kernel32.lib", 189 "ole32.lib", 190 ] 191 } 192 } else if (is_ohos) { 193 libs = [ 194 "dl", 195 "m", 196 ] 197 } else if (is_mac) { 198 # Targets should choose to explicitly link frameworks they require. Since 199 # linking can have run-time side effects, nothing should be listed here. 200 libs = [] 201 } else if (is_linux) { 202 libs = [ 203 "dl", 204 "pthread", 205 "rt", 206 ] 207 } 208} 209 210# Only //build/config/BUILDCONFIG.gn should reference this. 211group("common_deps") { 212 public_deps = [] 213 214 if (using_sanitizer) { 215 public_deps += [ "//build/config/sanitizers:deps" ] 216 } 217 218 if (use_custom_libcxx) { 219 if (is_double_framework) { 220 public_deps += [ "${asdk_libs_dir}/ndk/libcxx:libcxx" ] 221 } else { 222 public_deps += [ "//third_party/libcxx:libcxx" ] 223 } 224 } 225 226 if (use_afl) { 227 public_deps += [ "//third_party/afl" ] 228 } 229 230 if (is_ohos && use_order_profiling) { 231 public_deps += [] 232 } 233 234 if (use_musl && current_toolchain != host_toolchain && !is_mingw) { 235 public_deps += [ "//third_party/musl:soft_shared_libs" ] 236 } 237} 238 239group("executable_deps") { 240 public_deps = [ ":common_deps" ] 241 if (export_libcxxabi_from_executables) { 242 if (!is_double_framework) { 243 public_deps += [ "//third_party/libcxxabi:libc++abi" ] 244 } 245 } 246} 247 248group("loadable_module_deps") { 249 public_deps = [ ":common_deps" ] 250} 251 252group("shared_library_deps") { 253 public_deps = [ ":common_deps" ] 254} 255 256group("rust_library_deps") { 257 public_deps = [ ":common_deps" ] 258} 259 260group("rust_proc_macro_deps") { 261 public_deps = [ ":common_deps" ] 262} 263 264group("static_library_deps") { 265 if (use_musl && current_toolchain != host_toolchain && !is_mingw) { 266 public_deps = [ "//third_party/musl:musl_headers" ] 267 } 268} 269 270group("source_set_deps") { 271 if (use_musl && current_toolchain != host_toolchain && !is_mingw) { 272 public_deps = [ "//third_party/musl:musl_headers" ] 273 } 274} 275 276# Executable configs ----------------------------------------------------------- 277 278# Windows linker setup for EXEs and DLLs. 279if (is_win) { 280 _windows_linker_configs = [ 281 "//build/config/win:sdk_link", 282 "//build/config/win:common_linker_setup", 283 ] 284} 285 286# This config defines the configs applied to all executables. 287config("executable_config") { 288 configs = [] 289 290 if (is_win) { 291 configs += _windows_linker_configs 292 293 # Currently only turn on linker CFI for executables. 294 configs += [ "//build/config/win:cfi_linker" ] 295 } else if (is_mac) { 296 configs += [ "//build/config/mac:mac_dynamic_flags" ] 297 } else if (is_linux || is_ohos || current_os == "aix") { 298 configs += [ "//build/config/gcc:executable_ldconfig" ] 299 if (is_ohos) { 300 configs += [ "//build/config/ohos:executable_config" ] 301 } else if (is_linux) { 302 configs += [ "//build/config/linux:executable_config" ] 303 } 304 } 305 306 # If we're using the prebuilt instrumented libraries with the sanitizers, we 307 # need to add ldflags to every binary to make sure they are picked up. 308 if (prebuilt_instrumented_libraries_available) { 309 configs += [ "//third_party/instrumented_libraries:prebuilt_ldflags" ] 310 } 311 if (use_locally_built_instrumented_libraries) { 312 configs += [ "//third_party/instrumented_libraries:locally_built_ldflags" ] 313 } 314 configs += [ "//build/config/sanitizers:link_executable" ] 315} 316 317# Shared library configs ------------------------------------------------------- 318 319# This config defines the configs applied to all shared libraries. 320config("shared_library_config") { 321 configs = [] 322 323 if (is_win) { 324 configs += _windows_linker_configs 325 } else if (is_mac) { 326 configs += [ "//build/config/mac:mac_dynamic_flags" ] 327 } 328 329 # If we're using the prebuilt instrumented libraries with the sanitizers, we 330 # need to add ldflags to every binary to make sure they are picked up. 331 if (prebuilt_instrumented_libraries_available) { 332 configs += [ "//third_party/instrumented_libraries:prebuilt_ldflags" ] 333 } 334 if (use_locally_built_instrumented_libraries) { 335 configs += [ "//third_party/instrumented_libraries:locally_built_ldflags" ] 336 } 337 configs += [ "//build/config/sanitizers:link_shared_library" ] 338} 339