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 5 # ============================================================================= 6 # BUILD FLAGS 7 # ============================================================================= 8 # 9 # This block lists input arguments to the build, along with their default 10 # values. GN requires listing them explicitly so it can validate input and have 11 # a central place to manage the build flags. 12 # 13 # If a value is specified on the command line, it will overwrite the defaults 14 # given here, otherwise the default will be injected into the root scope. 15 # 16 # KEEP IN ALPHABETICAL ORDER and write a good description for everything. 17 # Use "is_*" names for intrinsic platform descriptions and build modes, and 18 # "use_*" names for optional features libraries, and configurations. 19 declare_args() { 20 # How many symbols to include in the build. This affects the performance of 21 # the build since the symbols are large and dealing with them is slow. 22 # 2 means regular build with symbols. 23 # 1 means minimal symbols, usually enough for backtraces only. 24 # 0 means no symbols. 25 symbol_level = 2 26 27 # Component build. 28 is_component_build = false 29 # Debug build. 30 is_debug = true 31 32 # Set to true when compiling with the Clang compiler. Typically this is used 33 # to configure warnings. 34 is_clang = false 35 36 # ASH is enabled. 37 # TODO(brettw) this should be moved out of the main build config file. 38 use_ash = false 39 # Aura is enabled. 40 # TODO(brettw) this should be moved out of the main build config file. 41 use_aura = false 42 # Ozone is enabled. 43 # TODO(brettw) this should be moved out of the main build config file. 44 use_ozone = false 45 46 # Forces a 64-bit build on Windows. Does nothing on other platforms. Normally 47 # we build 32-bit on Windows regardless of the current host OS bit depth. 48 # Setting this flag will override this logic and generate 64-bit toolchains. 49 # 50 # Normally this would get set automatically when you specify a target using 51 # the 64-bit toolchain. You can also set this on the command line to convert 52 # the default toolchain to 64-bit. 53 force_win64 = false 54 55 # Set to true on the command line when invoked by GYP. Build files can key 56 # off of this to make any GYP-output-specific changes to the build. 57 is_gyp = false 58 59 # Selects the desired build flavor. Official builds get additional 60 # processing to prepare for release. Normally you will want to develop and 61 # test with this flag off. 62 is_official_build = false 63 64 # Select the desired branding flavor. False means normal Chromium branding, 65 # true means official Google Chrome branding (requires extra Google-internal 66 # resources). 67 is_chrome_branded = false 68 } 69 70 # ============================================================================= 71 # OS DEFINITIONS 72 # ============================================================================= 73 # 74 # We set these various is_FOO booleans for convenience in writing OS-based 75 # conditions. 76 # 77 # - is_android, is_chromeos, is_ios, and is_win should be obvious. 78 # - is_mac is set only for desktop Mac. It is not set on iOS. 79 # - is_posix is true for mac and any Unix-like system (basically everything 80 # except Windows). 81 # - is_linux is true for any Linux variant including Android and ChromeOS. 82 # 83 # Do not add more is_* variants here for random lesser-used Unix systems like 84 # aix or one of the BSDs. If you need to check these, just check the os value 85 # directly. 86 87 if (os == "win") { 88 is_android = false 89 is_chromeos = false 90 is_ios = false 91 is_linux = false 92 is_mac = false 93 is_nacl = false 94 is_posix = false 95 is_win = true 96 } else if (os == "mac") { 97 is_android = false 98 is_chromeos = false 99 is_ios = false 100 is_linux = false 101 is_mac = true 102 is_nacl = false 103 is_posix = true 104 is_win = false 105 is_clang = true # Always use clang on Mac. 106 } else if (os == "android") { 107 is_android = false 108 is_chromeos = false 109 is_ios = false 110 is_linux = true 111 is_mac = false 112 is_nacl = false 113 is_posix = true 114 is_win = false 115 } else if (os == "chromeos") { 116 is_android = false 117 is_chromeos = true 118 is_ios = false 119 is_linux = true 120 is_mac = false 121 is_nacl = false 122 is_posix = true 123 is_win = false 124 } else if (os == "nacl") { 125 # os == "nacl" will be passed by the nacl toolchain definition. It is not 126 # set by default or on the command line. We treat is as a Posix variant. 127 is_android = false 128 is_chromeos = false 129 is_ios = false 130 is_linux = false 131 is_mac = false 132 is_nacl = true 133 is_posix = true 134 is_win = false 135 } else if (os == "ios") { 136 is_android = false 137 is_chromeos = false 138 is_ios = true 139 is_linux = false 140 is_mac = false 141 is_nacl = false 142 is_posix = true 143 is_win = false 144 } else if (os == "linux") { 145 is_android = false 146 is_chromeos = false 147 is_ios = false 148 is_linux = true 149 is_mac = false 150 is_nacl = false 151 is_posix = true 152 is_win = false 153 } 154 155 # ============================================================================= 156 # CPU ARCHITECTURE 157 # ============================================================================= 158 159 if (is_win) { 160 # Always use 32-bit on Windows, even when compiling on a 64-bit host OS, 161 # unless the override flag is specified. 162 if (force_win64) { 163 cpu_arch = "x64" 164 } else { 165 cpu_arch = "x86" 166 } 167 } 168 169 # ============================================================================= 170 # SOURCES FILTERS 171 # ============================================================================= 172 # 173 # These patterns filter out platform-specific files when assigning to the 174 # sources variable. The magic variable |sources_assignment_filter| is applied 175 # to each assignment or appending to the sources variable and matches are 176 # automatcally removed. 177 # 178 # We define lists of filters for each platform for all builds so they can 179 # be used by individual targets if necessary (a target can always change 180 # sources_assignment_filter on itself if it needs something more specific). 181 # 182 # Note that the patterns are NOT regular expressions. Only "*" and "\b" (path 183 # boundary = end of string or slash) are supported, and the entire string 184 # muct match the pattern (so you need "*.cc" to match all .cc files, for 185 # example). 186 187 windows_sources_filters = [ 188 "*_win.cc", 189 "*_win.h", 190 "*_win_unittest.cc", 191 "*\bwin/*", 192 ] 193 mac_sources_filters = [ 194 "*_mac.h", 195 "*_mac.cc", 196 "*_mac.mm", 197 "*_mac_unittest.h", 198 "*_mac_unittest.cc", 199 "*_mac_unittest.mm", 200 "*\bmac/*", 201 "*_cocoa.h", 202 "*_cocoa.cc", 203 "*_cocoa.mm", 204 "*_cocoa_unittest.h", 205 "*_cocoa_unittest.cc", 206 "*_cocoa_unittest.mm", 207 "*\bcocoa/*", 208 ] 209 ios_sources_filters = [ 210 "*_ios.h", 211 "*_ios.cc", 212 "*_ios.mm", 213 "*_ios_unittest.h", 214 "*_ios_unittest.cc", 215 "*_ios_unittest.mm", 216 "*\bios/*", 217 ] 218 objective_c_sources_filters = [ 219 "*.mm", 220 ] 221 linux_sources_filters = [ 222 "*_linux.h", 223 "*_linux.cc", 224 "*_linux_unittest.h", 225 "*_linux_unittest.cc", 226 "*\blinux/*", 227 "*_x11.cc", 228 "*_x11.h", 229 ] 230 android_sources_filters = [ 231 "*_android.h", 232 "*_android.cc", 233 "*_android_unittest.h", 234 "*_android_unittest.cc", 235 "*\bandroid/*", 236 ] 237 posix_sources_filters = [ 238 "*_posix.h", 239 "*_posix.cc", 240 "*_posix_unittest.h", 241 "*_posix_unittest.cc", 242 "*\bposix/*", 243 ] 244 245 # Construct the full list of sources we're using for this platform. 246 sources_assignment_filter = [] 247 if (is_win) { 248 sources_assignment_filter += posix_sources_filters 249 } else { 250 sources_assignment_filter += windows_sources_filters 251 } 252 if (!is_mac) { 253 sources_assignment_filter += mac_sources_filters 254 } 255 if (!is_ios) { 256 sources_assignment_filter += ios_sources_filters 257 } 258 if (!is_mac && !is_ios) { 259 sources_assignment_filter += objective_c_sources_filters 260 } 261 if (!is_linux) { 262 sources_assignment_filter += linux_sources_filters 263 } 264 if (!is_android) { 265 sources_assignment_filter += android_sources_filters 266 } 267 268 # This is the actual set. 269 set_sources_assignment_filter(sources_assignment_filter) 270 271 # ============================================================================= 272 # BUILD OPTIONS 273 # ============================================================================= 274 275 if (is_component_build) { 276 component_mode = "shared_library" 277 } else { 278 component_mode = "static_library" 279 } 280 281 toolkit_uses_gtk = is_linux 282 283 # ============================================================================= 284 # TARGET DEFAULTS 285 # ============================================================================= 286 # 287 # Set up the default configuration for every build target of the given type. 288 # The values configured here will be automatically set on the scope of the 289 # corresponding target. Target definitions can add or remove to the settings 290 # here as needed. 291 292 # Holds all configs used for making native executables and libraries, to avoid 293 # duplication in each target below. 294 native_compiler_configs = [ 295 "//build/config:my_msvs", # TODO(brettw) eraseme 296 297 "//build/config/compiler:compiler", 298 "//build/config/compiler:chromium_code", 299 "//build/config/compiler:default_warnings", 300 "//build/config/compiler:no_rtti", 301 "//build/config/compiler:runtime_library", 302 ] 303 if (is_win) { 304 native_compiler_configs += [ 305 "//build/config/win:sdk", 306 ] 307 } else if (is_clang) { 308 native_compiler_configs += "//build/config/clang:find_bad_constructs" 309 } 310 311 # Optimizations and debug checking. 312 if (is_debug) { 313 native_compiler_configs += "//build/config:debug" 314 default_optimization_config = "//build/config/compiler:no_optimize" 315 } else { 316 native_compiler_configs += "//build/config:release" 317 default_optimization_config = "//build/config/compiler:optimize" 318 } 319 native_compiler_configs += default_optimization_config 320 321 # Symbol setup. 322 if (is_clang && (is_linux || is_android)) { 323 # Clang creates chubby debug information, which makes linking very slow. 324 # For now, don't create debug information with clang. 325 # See http://crbug.com/70000 326 # TODO(brettw) This just copies GYP. Why not do this on Mac as well? 327 default_symbols_config = "//build/config/compiler:no_symbols" 328 } else if (symbol_level == 2) { 329 default_symbols_config = "//build/config/compiler:symbols" 330 } else if (symbol_level == 1) { 331 default_symbols_config = "//build/config/compiler:minimal_symbols" 332 } else if (symbol_level == 0) { 333 default_symbols_config = "//build/config/compiler:no_symbols" 334 } else { 335 assert(false, "Bad value for symbol_level.") 336 } 337 native_compiler_configs += default_symbols_config 338 339 # Windows linker setup for EXEs and DLLs. 340 if (is_win) { 341 if (is_debug) { 342 default_incremental_linking_config = 343 "//build/config/win:incremental_linking" 344 } else { 345 default_incremental_linking_config = 346 "//build/config/win:no_incremental_linking" 347 } 348 windows_linker_configs = [ 349 default_incremental_linking_config, 350 "//build/config/win:sdk_link", 351 "//build/config/win:common_linker_setup", 352 # Default to console-mode apps. Most of our targets are tests and such 353 # that shouldn't use the windows subsystem. 354 "//build/config/win:console", 355 ] 356 } 357 358 set_defaults("executable") { 359 configs = native_compiler_configs 360 if (is_win) { 361 configs += windows_linker_configs 362 } else if (is_mac) { 363 configs += "//build/config/mac:mac_dynamic_flags" 364 } else if (is_linux) { 365 configs += "//build/config/linux:executable_ldconfig" 366 } 367 } 368 369 set_defaults("static_library") { 370 configs = native_compiler_configs 371 } 372 373 set_defaults("shared_library") { 374 configs = native_compiler_configs 375 if (is_win) { 376 configs += windows_linker_configs 377 } else if (is_mac) { 378 configs += "//build/config/mac:mac_dynamic_flags" 379 } 380 } 381 382 set_defaults("source_set") { 383 configs = native_compiler_configs 384 } 385 386 # ============================================================================== 387 # TOOLCHAIN SETUP 388 # ============================================================================== 389 # 390 # Here we set the default toolchain, as well as the variable host_toolchain 391 # which will identify the toolchain corresponding to the local system when 392 # doing cross-compiles. When not cross-compiling, this will be the same as the 393 # default toolchain. 394 395 if (is_win) { 396 if (build_cpu_arch == "x64") { 397 host_toolchain = "//build/toolchain/win:64" 398 } else if (build_cpu_arch == "x86") { 399 host_toolchain = "//build/toolchain/win:32" 400 } 401 402 if (cpu_arch == "x64") { 403 set_default_toolchain("//build/toolchain/win:64") 404 } else if (cpu_arch == "x86") { 405 set_default_toolchain("//build/toolchain/win:32") 406 } 407 } else if (is_linux) { 408 if (build_cpu_arch == "arm") { 409 host_toolchain = "//build/toolchain/linux:arm" 410 } else if (build_cpu_arch == "x86") { 411 host_toolchain = "//build/toolchain/linux:32" 412 } else if (build_cpu_arch == "x64") { 413 host_toolchain = "//build/toolchain/linux:64" 414 } 415 416 if (build_cpu_arch == "arm") { 417 set_default_toolchain("//build/toolchain/linux:arm") 418 } else if (build_cpu_arch == "x86") { 419 set_default_toolchain("//build/toolchain/linux:32") 420 } else if (build_cpu_arch == "x64") { 421 set_default_toolchain("//build/toolchain/linux:64") 422 } 423 } else if (is_mac) { 424 host_toolchain = "//build/toolchain/mac:clang" 425 set_default_toolchain(host_toolchain) 426 } 427