1# Copyright 2018 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 5# ============================================================================= 6# WHAT IS THIS FILE? 7# ============================================================================= 8# 9# This is the master GN build configuration. This file is loaded after the 10# build args (args.gn) for the build directory and after the toplevel ".gn" 11# file (which points to this file as the build configuration). 12# 13# This file will be executed and the resulting context will be used to execute 14# every other file in the build. So variables declared here (that don't start 15# with an underscore) will be implicitly global. 16 17# ============================================================================= 18# PLATFORM SELECTION 19# ============================================================================= 20# 21# There are two main things to set: "os" and "cpu". The "toolchain" is the name 22# of the GN thing that encodes combinations of these things. 23# 24# Users typically only set the variables "target_os" and "target_cpu" in "gn 25# args", the rest are set up by our build and internal to GN. 26# 27# There are three different types of each of these things: The "host" 28# represents the computer doing the compile and never changes. The "target" 29# represents the main thing we're trying to build. The "current" represents 30# which configuration is currently being defined, which can be either the 31# host, the target, or something completely different. 32 33if (target_os == "") { 34 target_os = host_os 35} 36if (target_cpu == "") { 37 target_cpu = host_cpu 38} 39if (current_cpu == "") { 40 current_cpu = target_cpu 41} 42if (current_os == "") { 43 current_os = target_os 44} 45 46# ============================================================================= 47# BUILD FLAGS 48# ============================================================================= 49# 50# This block lists input arguments to the build, along with their default 51# values. 52# 53# If a value is specified on the command line, it will overwrite the defaults 54# given in a declare_args block, otherwise the default will be used. 55# 56# YOU SHOULD ALMOST NEVER NEED TO ADD FLAGS TO THIS FILE. GN allows any file in 57# the build to declare build flags. If you need a flag for a single component, 58# you can just declare it in the corresponding BUILD.gn file. 59 60default_clang_base_path = "//third_party/llvm-build/Release+Asserts" 61 62declare_args() { 63 # Debug build. Most global debug build flags are declared in 64 # //build/config/BUILD.gn. 65 is_debug = false 66 67 # By default, we use the clang compiler on both Mac and Linux. To use the 68 # gcc compiler on Linux instead, set is_gcc to true. 69 is_gcc = false 70 clang_base_path = default_clang_base_path 71 72 # This would not normally be set as a build argument, but rather is used as a 73 # default value during the first parse of this config. All other toolchains 74 # that cause this file to be re-parsed will already have this set. For 75 # further explanation, see 76 # https://gn.googlesource.com/gn/+/refs/heads/master/docs/reference.md#toolchain-overview 77 host_toolchain = "" 78 79 # Must be enabled for fuzzing targets. 80 use_libfuzzer = false 81} 82 83declare_args() { 84 is_clang = !is_gcc 85} 86 87# ============================================================================== 88# TOOLCHAIN SETUP 89# ============================================================================== 90# 91# Here we set the host and default toolchains. Currently only Mac and POSIX are 92# defined. 93if (host_toolchain == "") { 94 if (current_os == "chromeos" || current_os == "linux") { 95 if (is_clang) { 96 host_toolchain = "//build/toolchain/linux:clang_$host_cpu" 97 } else { 98 host_toolchain = "//build/toolchain/linux:gcc_$host_cpu" 99 } 100 } else if (current_os == "mac") { 101 host_toolchain = "//build/toolchain/mac:clang" 102 } else { 103 # TODO(miu): Windows, and others. 104 assert(false, "Toolchain for current_os is not defined.") 105 } 106} 107 108_default_toolchain = "" 109if (target_os == "chromeos" || target_os == "linux") { 110 if (is_clang) { 111 _default_toolchain = "//build/toolchain/linux:clang_$target_cpu" 112 } else { 113 _default_toolchain = "//build/toolchain/linux:gcc_$target_cpu" 114 } 115} else if (target_os == "mac") { 116 assert(host_os == "mac", "Cross-compiling on Mac is not supported.") 117 _default_toolchain = "//build/toolchain/mac:clang" 118} else { 119 assert(false, "Toolchain for target_os is not defined.") 120} 121set_default_toolchain(_default_toolchain) 122 123# ============================================================================= 124# OS DEFINITIONS 125# ============================================================================= 126# 127# We set these various is_FOO booleans for convenience in writing OS-based 128# conditions. 129 130if (current_os == "chromeos" || current_os == "linux") { 131 is_linux = true 132 is_mac = false 133 is_posix = true 134} else if (current_os == "mac") { 135 is_linux = false 136 is_mac = true 137 is_posix = true 138} else { 139 # TODO(miu): Windows, and others. 140 assert(false, "is_FOO booleans not defined for current_os.") 141} 142 143# ============================================================================= 144# TARGET DEFAULTS 145# ============================================================================= 146# 147# Set up the default configuration for every build target of the given type. 148# The values configured here will be automatically set on the scope of the 149# corresponding target. Target definitions can add or remove to the settings 150# here as needed. 151 152# All binary targets will get this list of configs by default. 153_shared_binary_target_configs = [ 154 "//build/config:openscreen_code", 155 "//build/config:no_exceptions", 156 "//build/config:no_rtti", 157 "//build/config:symbol_visibility_hidden", 158 "//build/config:default_sanitizers", 159 "//build/config:default_coverage", 160 "//build/config:compiler_defaults", 161 "//build/config:compiler_cpu_abi", 162 "//build/config:default_optimization", 163 "//build/config:sysroot_runtime_libraries", 164 "//build/config:operating_system_defines", 165] 166 167# Apply that default list to the binary target types. 168set_defaults("executable") { 169 configs = _shared_binary_target_configs 170} 171set_defaults("static_library") { 172 configs = _shared_binary_target_configs 173} 174set_defaults("shared_library") { 175 configs = _shared_binary_target_configs 176} 177set_defaults("source_set") { 178 configs = _shared_binary_target_configs 179} 180