aboutsummaryrefslogtreecommitdiff
path: root/build/config/BUILDCONFIG.gn
blob: 0fa9693520d4cbfb764a46107926a5a7d65088df (plain)
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
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# =============================================================================
# WHAT IS THIS FILE?
# =============================================================================
#
# This is the master GN build configuration. This file is loaded after the
# build args (args.gn) for the build directory and after the toplevel ".gn"
# file (which points to this file as the build configuration).
#
# This file will be executed and the resulting context will be used to execute
# every other file in the build. So variables declared here (that don't start
# with an underscore) will be implicitly global.

# =============================================================================
# PLATFORM SELECTION
# =============================================================================
#
# There are two main things to set: "os" and "cpu". The "toolchain" is the name
# of the GN thing that encodes combinations of these things.
#
# Users typically only set the variables "target_os" and "target_cpu" in "gn
# args", the rest are set up by our build and internal to GN.
#
# There are three different types of each of these things: The "host"
# represents the computer doing the compile and never changes. The "target"
# represents the main thing we're trying to build. The "current" represents
# which configuration is currently being defined, which can be either the
# host, the target, or something completely different.

if (target_os == "") {
  target_os = host_os
}
if (target_cpu == "") {
  target_cpu = host_cpu
}
if (current_cpu == "") {
  current_cpu = target_cpu
}
if (current_os == "") {
  current_os = target_os
}

# =============================================================================
# BUILD FLAGS
# =============================================================================
#
# This block lists input arguments to the build, along with their default
# values.
#
# If a value is specified on the command line, it will overwrite the defaults
# given in a declare_args block, otherwise the default will be used.
#
# YOU SHOULD ALMOST NEVER NEED TO ADD FLAGS TO THIS FILE. GN allows any file in
# the build to declare build flags. If you need a flag for a single component,
# you can just declare it in the corresponding BUILD.gn file.

default_clang_base_path = "//third_party/llvm-build/Release+Asserts"

declare_args() {
  # Debug build.  Most global debug build flags are declared in
  # //build/config/BUILD.gn.
  is_debug = false

  # By default, we use the clang compiler on both Mac and Linux. To use the
  # gcc compiler on Linux instead, set is_gcc to true.
  is_gcc = false
  clang_base_path = default_clang_base_path

  # This would not normally be set as a build argument, but rather is used as a
  # default value during the first parse of this config.  All other toolchains
  # that cause this file to be re-parsed will already have this set.  For
  # further explanation, see
  # https://gn.googlesource.com/gn/+/refs/heads/master/docs/reference.md#toolchain-overview
  host_toolchain = ""

  # Must be enabled for fuzzing targets.
  use_libfuzzer = false
}

declare_args() {
  is_clang = !is_gcc
}

# ==============================================================================
# TOOLCHAIN SETUP
# ==============================================================================
#
# Here we set the host and default toolchains. Currently only Mac and POSIX are
# defined.
if (host_toolchain == "") {
  if (current_os == "chromeos" || current_os == "linux") {
    if (is_clang) {
      host_toolchain = "//build/toolchain/linux:clang_$host_cpu"
    } else {
      host_toolchain = "//build/toolchain/linux:gcc_$host_cpu"
    }
  } else if (current_os == "mac") {
    host_toolchain = "//build/toolchain/mac:clang"
  } else {
    # TODO(miu): Windows, and others.
    assert(false, "Toolchain for current_os is not defined.")
  }
}

_default_toolchain = ""
if (target_os == "chromeos" || target_os == "linux") {
  if (is_clang) {
    _default_toolchain = "//build/toolchain/linux:clang_$target_cpu"
  } else {
    _default_toolchain = "//build/toolchain/linux:gcc_$target_cpu"
  }
} else if (target_os == "mac") {
  assert(host_os == "mac", "Cross-compiling on Mac is not supported.")
  _default_toolchain = "//build/toolchain/mac:clang"
} else {
  assert(false, "Toolchain for target_os is not defined.")
}
set_default_toolchain(_default_toolchain)

# =============================================================================
# OS DEFINITIONS
# =============================================================================
#
# We set these various is_FOO booleans for convenience in writing OS-based
# conditions.

if (current_os == "chromeos" || current_os == "linux") {
  is_linux = true
  is_mac = false
  is_posix = true
} else if (current_os == "mac") {
  is_linux = false
  is_mac = true
  is_posix = true
} else {
  # TODO(miu): Windows, and others.
  assert(false, "is_FOO booleans not defined for current_os.")
}

# =============================================================================
# TARGET DEFAULTS
# =============================================================================
#
# Set up the default configuration for every build target of the given type.
# The values configured here will be automatically set on the scope of the
# corresponding target. Target definitions can add or remove to the settings
# here as needed.

# All binary targets will get this list of configs by default.
_shared_binary_target_configs = [
  "//build/config:openscreen_code",
  "//build/config:no_exceptions",
  "//build/config:no_rtti",
  "//build/config:symbol_visibility_hidden",
  "//build/config:default_sanitizers",
  "//build/config:default_coverage",
  "//build/config:compiler_defaults",
  "//build/config:compiler_cpu_abi",
  "//build/config:default_optimization",
  "//build/config:sysroot_runtime_libraries",
]

# Apply that default list to the binary target types.
set_defaults("executable") {
  configs = _shared_binary_target_configs
}
set_defaults("static_library") {
  configs = _shared_binary_target_configs
}
set_defaults("shared_library") {
  configs = _shared_binary_target_configs
}
set_defaults("source_set") {
  configs = _shared_binary_target_configs
}