1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193
  194
  195
  196
  197
  198
  199
  200
  201
  202
  203
  204
  205
  206
  207
  208
  209
  210
  211
  212
  213
  214
  215
  216
  217
  218
  219
  220
  221
  222
  223
  224
  225
  226
  227
  228
  229
  230
  231
  232
  233
  234
  235
  236
  237
  238
  239
  240
  241
  242
  243
  244
  245
  246
  247
  248
  249
  250
  251
  252
  253
  254
  255
  256
  257
  258
  259
  260
  261
  262
  263
  264
  265
  266
  267
  268
  269
  270
  271
  272
  273
  274
  275
  276
  277
  278
  279
  280
  281
  282
  283
  284
  285
  286
  287
  288
  289
  290
  291
  292
  293
  294
  295
  296
  297
  298
  299
  300
  301
  302
  303
  304
  305
  306
  307
  308
  309
  310
  311
  312
  313
  314
  315
  316
  317
  318
  319
  320
  321
  322
  323
  324
  325
  326
  327
  328
  329
  330
  331
  332
  333
  334
  335
  336
  337
  338
  339
  340
  341
  342
  343
  344
  345
  346
  347
  348
  349
  350
  351
  352
  353
  354
  355
  356
  357
  358
  359
  360
  361
  362
  363
  364
  365
  366
  367
  368
  369
  370
  371
  372
  373
  374
  375
  376
  377
  378
  379
  380
  381
  382
  383
  384
  385
  386
  387
  388
  389
  390
  391
  392
  393
  394
  395
  396
  397
  398
  399
  400
  401
  402
  403
  404
  405
  406
  407
  408
  409
  410
  411
  412
  413
  414
  415
  416
  417
  418
  419
  420
  421
  422
  423
  424
  425
  426
  427
  428
  429
  430
  431

build / config / BUILD.gn [blame]

# Copyright 2013 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/c++/c++.gni")
import("//build/config/cast.gni")
import("//build/config/chrome_build.gni")
import("//build/config/dcheck_always_on.gni")
import("//build/config/features.gni")

# Subprojects need to override arguments in {mac,ios}_sdk_overrides.gni in their
# .gn config, but those arguments are only used on macOS. Including
# mac_sdk_overrides.gni insures that this doesn't trigger an unused argument
# warning.
import("//build/config/ios/ios_sdk_overrides.gni")
import("//build/config/mac/mac_sdk_overrides.gni")

import("//build/config/pch.gni")
import("//build/config/rust.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/config/ui.gni")
if (is_android) {
  import("//build/config/android/abi.gni")
}

# ==============================================
#   PLEASE DO NOT ADD MORE THINGS TO THIS LIST
# ==============================================
#
# Legacy feature defines applied to all targets.
#
# These are applied to every single compile in the build and most of them are
# only relevant to a few files. This bloats command lines and causes
# unnecessary recompiles when flags are flipped.
#
# To pass defines to source code from the build, use the buildflag system which
# will write headers containing the defines you need. This isolates the define
# and means its definition can participate in the build graph, only recompiling
# things when it actually changes.
#
# See //build/buildflag_header.gni for instructions on generating headers.
#
# This will also allow you to scope your build flag to a BUILD.gn file (or a
# .gni file if you need it from more than one place) rather than making global
# flags. See //build/config/BUILDCONFIG.gn for advice on where to define
# build flags.
config("feature_flags") {
  defines = []
  rustflags = []
  if (dcheck_always_on) {
    defines += [ "DCHECK_ALWAYS_ON=1" ]
    rustflags += [ "-Cdebug-assertions" ]
  }
  if (use_udev) {
    # TODO(brettw) should probably be "=1".
    defines += [ "USE_UDEV" ]
  }
  if (use_aura) {
    defines += [ "USE_AURA=1" ]
  }
  if (use_glib) {
    defines += [ "USE_GLIB=1" ]
  }
  if (use_ozone && !is_android) {
    # Chrome code should check BUILDFLAG(IS_OZONE) instead of
    # defined(USE_OZONE).
    #
    # Note that some Chrome OS builds unconditionally set |use_ozone| to true,
    # but they also build some targets with the Android toolchain. This ensures
    # that Android targets still build with USE_OZONE=0 in such cases.
    #
    # TODO(crbug.com/41385586): Maybe this can be cleaned up if we can avoid
    # setting use_ozone globally.
    defines += [ "USE_OZONE=1" ]
  }
  if (is_asan || is_hwasan || is_lsan || is_tsan || is_msan) {
    defines += [ "MEMORY_TOOL_REPLACES_ALLOCATOR" ]
  }
  if (is_asan) {
    defines += [ "ADDRESS_SANITIZER" ]
  }
  if (is_lsan) {
    defines += [ "LEAK_SANITIZER" ]
  }
  if (is_tsan) {
    defines += [
      "THREAD_SANITIZER",
      "DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL=1",
    ]
  }
  if (is_msan) {
    defines += [ "MEMORY_SANITIZER" ]
  }
  if (is_ubsan_any) {
    defines += [ "UNDEFINED_SANITIZER" ]
  }
  if (is_official_build) {
    defines += [ "OFFICIAL_BUILD" ]
  }

  # ==============================================
  #   PLEASE DO NOT ADD MORE THINGS TO THIS LIST
  # ==============================================
  #
  # See the comment at the top.
}

# Debug/release ----------------------------------------------------------------

config("debug") {
  defines = [
    "_DEBUG",
    "DYNAMIC_ANNOTATIONS_ENABLED=1",
  ]

  if (is_nacl) {
    defines += [ "DYNAMIC_ANNOTATIONS_PREFIX=NACL_" ]
  }

  if (is_win) {
    if (!enable_iterator_debugging && !use_custom_libcxx) {
      # Iterator debugging is enabled by default by the compiler on debug
      # builds, and we have to tell it to turn it off.
      defines += [ "_HAS_ITERATOR_DEBUGGING=0" ]
    }
  } else if ((is_linux || is_chromeos) && current_cpu == "x64" &&
             enable_iterator_debugging) {
    # Enable libstdc++ debugging facilities to help catch problems early, see
    # http://crbug.com/65151 .
    # TODO(phajdan.jr): Should we enable this for all of POSIX?
    defines += [ "_GLIBCXX_DEBUG=1" ]
  }
}

config("release") {
  defines = [ "NDEBUG" ]

  # Sanitizers.
  if (is_tsan) {
    defines += [ "DYNAMIC_ANNOTATIONS_ENABLED=1" ]
  } else {
    defines += [ "NVALGRIND" ]
    if (!is_nacl) {
      # NaCl always enables dynamic annotations. Currently this value is set to
      # 1 for all .nexes.
      defines += [ "DYNAMIC_ANNOTATIONS_ENABLED=0" ]
    }
  }

  if (is_ios) {
    # Disable NSAssert and GTMDevAssert (from Google Toolbox for Mac). This
    # follows XCode's default behavior for Release builds.
    defines += [ "NS_BLOCK_ASSERTIONS=1" ]
  }
}

# Default libraries ------------------------------------------------------------

# This config defines the default libraries applied to all targets.
config("default_libs") {
  if (is_win) {
    # TODO(brettw) this list of defaults should probably be smaller, and
    # instead the targets that use the less common ones (e.g. wininet or
    # winspool) should include those explicitly.
    libs = [
      "advapi32.lib",
      "comdlg32.lib",
      "dbghelp.lib",
      "dnsapi.lib",
      "gdi32.lib",
      "msimg32.lib",
      "odbc32.lib",
      "odbccp32.lib",
      "oleaut32.lib",
      "shell32.lib",
      "shlwapi.lib",
      "user32.lib",
      "usp10.lib",
      "uuid.lib",
      "version.lib",
      "wininet.lib",
      "winmm.lib",
      "winspool.lib",
      "ws2_32.lib",

      # Please don't add more stuff here. We should actually be making this
      # list smaller, since all common things should be covered. If you need
      # some extra libraries, please just add a libs = [ "foo.lib" ] to your
      # target that needs it.
    ]
    if (current_os == "winuwp") {
      # These libraries are needed for Windows UWP (i.e. store apps).
      libs += [
        "dloadhelper.lib",
        "WindowsApp.lib",
      ]
    } else {
      # These libraries are not compatible with Windows UWP (i.e. store apps.)
      libs += [
        "delayimp.lib",
        "kernel32.lib",
        "ole32.lib",
      ]
    }
  } else if (is_android) {
    libs = [
      "dl",
      "m",
    ]
  } else if (is_mac) {
    # Targets should choose to explicitly link frameworks they require. Since
    # linking can have run-time side effects, nothing should be listed here.
    libs = []
  } else if (is_ios) {
    # Targets should choose to explicitly link frameworks they require. Since
    # linking can have run-time side effects, nothing should be listed here.
    libs = []
  } else if (is_linux || is_chromeos) {
    libs = [
      "dl",
      "pthread",
      "rt",
    ]
  }
}

_toolchain_marker_name =
    "toolchain_marker_" + get_label_info(current_toolchain, "name")
group(_toolchain_marker_name) {
  # Can be used as an assert_no_deps target (assert_no_deps ignores toolchains).
}

group("common_deps_without_libcxx") {
  # WARNING: This group is a dependency of **every executable and shared
  # library**.  Please be careful adding new dependencies here.
  public_deps = [ ":$_toolchain_marker_name" ]

  if (using_sanitizer) {
    public_deps += [ "//build/config/sanitizers:deps" ]
  }

  if (use_libfuzzer) {
    public_deps += [ "//build/config/sanitizers:dlclose_shim" ]
  }

  if (use_afl) {
    public_deps += [ "//third_party/afl" ]
  }

  if (is_android && use_order_profiling) {
    public_deps += [ "//base/android/orderfile:orderfile_instrumentation" ]
  }

  if (is_fuchsia) {
    public_deps +=
        [ "//third_party/fuchsia-gn-sdk/src/config:runtime_library_group" ]
    if (is_asan) {
      public_deps += [ "//build/config/fuchsia:asan_runtime_library" ]
    }
  }

  if (is_win) {
    if (build_with_chromium && is_component_build) {
      # To enable allocator_shim for the windows component built chrome,
      # need to make all shared libraries and also executable(i.e.chrome.exe)
      # depend on PartitionAlloc.
      public_deps += [ "//base/allocator/partition_allocator/src/partition_alloc:win_component_build_adapter" ]
    }

    # The CRT runtime is dynamically linked in component builds and needs to
    # be present on bots that run exes or load DLLs. This also includes
    # debugging DLLs in all builds.
    data_deps = [ "//build/win:runtime_libs" ]

    if (host_os == "win") {
      # In order to ensure the ACLing is applied to every binary loaded in an
      # app container sandbox, run the ACL step before any binary is built. We
      # do this because the tool is subject to race conditions if a binary is
      # placed in the out folder while it is running.
      public_deps +=
          [ "//build/config/win:maybe_set_appcontainer_acls($host_toolchain)" ]
    }
  }
}

group("common_deps") {
  visibility = [
    ":executable_deps",
    ":loadable_module_deps",
    ":shared_library_deps",
  ]

  # WARNING: This group is a dependency of **every executable and shared
  # library**.  Please be careful adding new dependencies here.
  public_deps = [ ":common_deps_without_libcxx" ]

  if (use_custom_libcxx) {
    public_deps += [ "//buildtools/third_party/libc++" ]
  }
}

# Only the executable template in BUILDCONFIG.gn should reference this.
group("executable_deps") {
  if (!toolchain_for_rust_host_build_tools) {
    public_deps = [ ":common_deps" ]
    if (export_libcxxabi_from_executables) {
      public_deps += [ "//buildtools/third_party/libc++abi" ]
    }
  }
}

# Only the loadable_module template in BUILDCONFIG.gn should reference this.
group("loadable_module_deps") {
  if (!toolchain_for_rust_host_build_tools) {
    public_deps = [ ":common_deps" ]
  }
}

# Only the shared_library template in BUILDCONFIG.gn should reference this.
group("shared_library_deps") {
  if (!toolchain_for_rust_host_build_tools) {
    public_deps = [ ":common_deps" ]
  }
}

# Executable configs -----------------------------------------------------------

# Windows linker setup for EXEs and DLLs.
if (is_win) {
  _windows_linker_configs = [
    "//build/config/win:sdk_link",
    "//build/config/win:common_linker_setup",
  ]
}

# This config defines the configs applied to all executables.
config("executable_config") {
  configs = []

  if (is_win) {
    configs += _windows_linker_configs
  } else if (is_mac) {
    configs += [ "//build/config/mac:mac_dynamic_flags" ]
  } else if (is_ios) {
    configs += [
      "//build/config/ios:ios_dynamic_flags",
      "//build/config/ios:ios_executable_flags",
    ]
  } else if (is_linux || is_chromeos || is_android || current_os == "aix") {
    configs += [ "//build/config/gcc:executable_config" ]
    if (is_castos || is_cast_android) {
      configs += [ "//build/config/chromecast:executable_config" ]
    }
  }

  # If we're using the prebuilt instrumented libraries with the sanitizers, we
  # need to add ldflags to every binary to make sure they are picked up.
  if (prebuilt_instrumented_libraries_available) {
    configs += [ "//third_party/instrumented_libs:prebuilt_ldflags" ]
  }
  if (use_locally_built_instrumented_libraries) {
    configs += [ "//third_party/instrumented_libs:locally_built_ldflags" ]
  }
}

# Shared library configs -------------------------------------------------------

# This config defines the configs applied to all shared libraries.
config("shared_library_config") {
  configs = []

  if (is_win) {
    configs += _windows_linker_configs
  } else if (is_mac) {
    configs += [ "//build/config/mac:mac_dynamic_flags" ]
  } else if (is_ios) {
    configs += [
      "//build/config/ios:ios_dynamic_flags",
      "//build/config/ios:ios_shared_library_flags",
    ]
  } else if (is_castos || is_cast_android) {
    configs += [ "//build/config/chromecast:shared_library_config" ]
  } else if (is_linux || is_chromeos || current_os == "aix") {
    configs += [ "//build/config/gcc:shared_library_config" ]
  }

  # If we're using the prebuilt instrumented libraries with the sanitizers, we
  # need to add ldflags to every binary to make sure they are picked up.
  if (prebuilt_instrumented_libraries_available) {
    configs += [ "//third_party/instrumented_libs:prebuilt_ldflags" ]
  }
  if (use_locally_built_instrumented_libraries) {
    configs += [ "//third_party/instrumented_libs:locally_built_ldflags" ]
  }
}

# Add this config to your target to enable precompiled headers.
#
# Precompiled headers are done on a per-target basis. If you have just a couple
# of files, the time it takes to precompile (~2 seconds) can actually be longer
# than the time saved. On a Z620, a 100 file target compiles about 2 seconds
# faster with precompiled headers, with greater savings for larger targets.
#
# Recommend precompiled headers for targets with more than 50 .cc files.
config("precompiled_headers") {
  if (enable_precompiled_headers) {
    if (is_win) {
      # This is a string rather than a file GN knows about. It has to match
      # exactly what's in the /FI flag below, and what might appear in the
      # source code in quotes for an #include directive.
      precompiled_header = "build/precompile.h"

      # This is a file that GN will compile with the above header. It will be
      # implicitly added to the sources (potentially multiple times, with one
      # variant for each language used in the target).
      precompiled_source = "//build/precompile.cc"

      # Force include the header.
      cflags = [ "/FI$precompiled_header" ]
    } else if (is_mac || is_linux) {
      precompiled_source = "//build/precompile.h"
    }
  }
}

# Add this config to link steps in order to compress debug sections. This is
# especially useful on 32-bit architectures in order to keep file sizes under
# 4gb.
config("compress_debug_sections") {
  ldflags = [ "-gz" ]
}