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 80declare_args() { 81 is_clang = !is_gcc 82} 83 84# ============================================================================== 85# TOOLCHAIN SETUP 86# ============================================================================== 87# 88# Here we set the host and default toolchains. Currently only Mac and POSIX are 89# defined. 90if (host_toolchain == "") { 91 if (current_os == "chromeos" || current_os == "linux") { 92 if (is_clang) { 93 host_toolchain = "//build/toolchain/linux:clang_$host_cpu" 94 } else { 95 host_toolchain = "//build/toolchain/linux:gcc_$host_cpu" 96 } 97 } else if (current_os == "mac") { 98 host_toolchain = "//build/toolchain/mac:clang" 99 } else { 100 # TODO(miu): Windows, and others. 101 assert(false, "Toolchain for current_os is not defined.") 102 } 103} 104 105_default_toolchain = "" 106if (target_os == "chromeos" || target_os == "linux") { 107 if (is_clang) { 108 _default_toolchain = "//build/toolchain/linux:clang_$target_cpu" 109 } else { 110 _default_toolchain = "//build/toolchain/linux:gcc_$target_cpu" 111 } 112} else if (target_os == "mac") { 113 assert(host_os == "mac", "Cross-compiling on Mac is not supported.") 114 _default_toolchain = "//build/toolchain/mac:clang" 115} else { 116 assert(false, "Toolchain for target_os is not defined.") 117} 118set_default_toolchain(_default_toolchain) 119 120# ============================================================================= 121# OS DEFINITIONS 122# ============================================================================= 123# 124# We set these various is_FOO booleans for convenience in writing OS-based 125# conditions. 126 127if (current_os == "chromeos" || current_os == "linux") { 128 is_linux = true 129 is_mac = false 130 is_posix = true 131} else if (current_os == "mac") { 132 is_linux = false 133 is_mac = true 134 is_posix = true 135} else { 136 # TODO(miu): Windows, and others. 137 assert(false, "is_FOO booleans not defined for current_os.") 138} 139 140# ============================================================================= 141# TARGET DEFAULTS 142# ============================================================================= 143# 144# Set up the default configuration for every build target of the given type. 145# The values configured here will be automatically set on the scope of the 146# corresponding target. Target definitions can add or remove to the settings 147# here as needed. 148 149# All binary targets will get this list of configs by default. 150_shared_binary_target_configs = [ 151 "//build/config:openscreen_code", 152 "//build/config:no_exceptions", 153 "//build/config:no_rtti", 154 "//build/config:symbol_visibility_hidden", 155 "//build/config:default_sanitizers", 156 "//build/config:default_coverage", 157 "//build/config:compiler_defaults", 158 "//build/config:compiler_cpu_abi", 159 "//build/config:default_optimization", 160 "//build/config:sysroot_runtime_libraries", 161] 162 163# Apply that default list to the binary target types. 164set_defaults("executable") { 165 configs = _shared_binary_target_configs 166} 167set_defaults("static_library") { 168 configs = _shared_binary_target_configs 169} 170set_defaults("shared_library") { 171 configs = _shared_binary_target_configs 172} 173set_defaults("source_set") { 174 configs = _shared_binary_target_configs 175} 176