1 # Copyright (c) 2014 The Native Client 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.
5 # =============================================================================
7 # =============================================================================
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.
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.
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.
20 # The current NaCl libc and preps stage, none for trusted toolchains.
28 use_nacl_x86 = (cpu_arch == "x86")
29 use_nacl_x64 = ((cpu_arch == "x64") || (os == "win"))
30 use_nacl_arm = (cpu_arch == "arm")
32 is_android_webview_build = false
34 # How many symbols to include in the build. This affects the performance of
35 # the build since the symbols are large and dealing with them is slow.
36 # 2 means regular build with symbols.
37 # 1 means minimal symbols, usually enough for backtraces only.
42 is_component_build = false
46 # Set to true when compiling with the Clang compiler. Typically this is used
47 # to configure warnings.
50 # Forces a 64-bit build on Windows. Does nothing on other platforms. Normally
51 # we build 32-bit on Windows regardless of the current host OS bit depth.
52 # Setting this flag will override this logic and generate 64-bit toolchains.
54 # Normally this would get set automatically when you specify a target using
55 # the 64-bit toolchain. You can also set this on the command line to convert
56 # the default toolchain to 64-bit.
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
64 # Select the desired branding flavor. False means normal Chromium branding,
65 # true means official Google Chrome branding (requires extra Google-internal
67 is_chrome_branded = false
69 # Compile for Address Sanitizer to find memory bugs.
72 # Compile for Leak Sanitizer to find leaks.
75 # Compile for Memory Sanitizer to find uninitialized reads.
78 # Compile for Thread Sanitizer to find threading bugs.
82 # =============================================================================
84 # =============================================================================
86 # We set these various is_FOO booleans for convenience in writing OS-based
89 # - is_android, is_chromeos, is_ios, and is_win should be obvious.
90 # - is_mac is set only for desktop Mac. It is not set on iOS.
91 # - is_posix is true for mac and any Unix-like system (basically everything
93 # - is_linux is true for desktop Linux and ChromeOS, but not Android (which is
94 # generally too different despite being based on the Linux kernel).
96 # Do not add more is_* variants here for random lesser-used Unix systems like
97 # aix or one of the BSDs. If you need to check these, just check the os value
109 } else if (os == "mac") {
119 is_clang = true # Always use clang on Mac.
121 } else if (os == "android") {
130 } else if (os == "chromeos") {
139 } else if (os == "nacl") {
140 # os == "nacl" will be passed by the nacl toolchain definition. It is not
141 # set by default or on the command line. We treat is as a Posix variant.
150 } else if (os == "ios") {
159 if (!is_gyp_xcode_generator) {
160 # Always use clang on iOS when using ninja
163 } else if (os == "linux") {
174 is_desktop_linux = is_linux && !is_chromeos
176 # =============================================================================
178 # =============================================================================
181 # Always use 32-bit on Windows, even when compiling on a 64-bit host OS,
182 # unless the override flag is specified.
190 # =============================================================================
192 # =============================================================================
194 # These patterns filter out platform-specific files when assigning to the
195 # sources variable. The magic variable |sources_assignment_filter| is applied
196 # to each assignment or appending to the sources variable and matches are
197 # automatcally removed.
199 # Note that the patterns are NOT regular expressions. Only "*" and "\b" (path
200 # boundary = end of string or slash) are supported, and the entire string
201 # muct match the pattern (so you need "*.cc" to match all .cc files, for
204 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
206 sources_assignment_filter = []
208 sources_assignment_filter += [
211 "*_posix_unittest.h",
212 "*_posix_unittest.cc",
217 sources_assignment_filter += [
226 sources_assignment_filter += [
237 "*_cocoa_unittest.h",
238 "*_cocoa_unittest.cc",
239 "*_cocoa_unittest.mm",
244 sources_assignment_filter += [
254 if (!is_mac && !is_ios) {
255 sources_assignment_filter += [
260 sources_assignment_filter += [
263 "*_linux_unittest.h",
264 "*_linux_unittest.cc",
269 sources_assignment_filter += [
272 "*_android_unittest.h",
273 "*_android_unittest.cc",
278 sources_assignment_filter += [
281 "*_chromeos_unittest.h",
282 "*_chromeos_unittest.cc",
286 # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
289 # Actually save this list.
291 # These patterns are executed for every file in the source tree of every run.
292 # Therefore, adding more patterns slows down the build for everybody. We should
293 # only add automatic patterns for configurations affecting hundreds of files
294 # across many projects in the tree.
296 # Therefore, we only add rules to this list corresponding to platforms on the
297 # Chromium waterfall. This is not for non-officially-supported platforms
298 # (FreeBSD, etc.) toolkits, (X11, GTK, etc.), or features. For these cases,
299 # write a conditional in the target to remove the file(s) from the list when
300 # your platform/toolkit/feature doesn't apply.
301 set_sources_assignment_filter(sources_assignment_filter)
303 # =============================================================================
305 # =============================================================================
307 if (is_component_build) {
308 component_mode = "shared_library"
310 component_mode = "source_set"
313 # These Sanitizers all imply using the Clang compiler. On Windows they either
314 # don't work or work differently.
315 if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) {
319 # ==============================================================================
321 # ==============================================================================
323 # Here we set the default toolchain, as well as the variable host_toolchain
324 # which will identify the toolchain corresponding to the local system when
325 # doing cross-compiles. When not cross-compiling, this will be the same as the
329 if (build_os == "mac") {
330 host_toolchain = "//native_client/build/toolchain/mac:clang"
333 host_toolchain = "//native_client/build/toolchain/${build_os}:${build_cpu_arch}"
336 # TODO(brettw) name the toolchains the same as cpu_arch as with Linux below
337 # to eliminate these conditionals.
338 if (build_cpu_arch == "x64") {
339 host_toolchain = "//native_client/build/toolchain/win:64"
340 } else if (build_cpu_arch == "x86") {
341 host_toolchain = "//native_client/build/toolchain/win:32"
344 if (cpu_arch == "x64") {
345 set_default_toolchain("//native_client/build/toolchain/win:64")
346 } else if (cpu_arch == "x86") {
347 set_default_toolchain("//native_client/build/toolchain/win:32")
349 } else if (is_linux) {
350 host_toolchain = "//native_client/build/toolchain/linux:$build_cpu_arch"
351 set_default_toolchain("//native_client/build/toolchain/linux:$cpu_arch")
353 host_toolchain = "//native_client/build/toolchain/mac:clang"
354 set_default_toolchain(host_toolchain)
356 host_toolchain = "//native_client/build/toolchain/mac:host_clang"
357 set_default_toolchain("//native_client/build/toolchain/mac:clang")
360 # =============================================================================
362 # =============================================================================
364 # Set up the default configuration for every build target of the given type.
365 # The values configured here will be automatically set on the scope of the
366 # corresponding target. Target definitions can add or remove to the settings
370 # For NaCl targets, we inject a dependency on prepping the library for cooked
371 # toolchain targets. For raw targets we inject a dependency on untarring.
373 _nacl_compiler_configs = [
374 "//native_client/build/config/nacl:nacl_defines",
375 "//native_client/build/config/nacl:nexe_defines"
378 # Holds all configs used for making native executables and libraries, to avoid
379 # duplication in each target below.
380 _native_compiler_configs = [
381 "//native_client/build/config/nacl:nacl_defines",
382 "//native_client/build/config/compiler:compiler",
383 "//native_client/build/config/compiler:default_warnings",
384 "//native_client/build/config/compiler:no_rtti",
388 _native_compiler_configs += [ "//native_client/build/config/clang:find_bad_constructs" ]
391 # Optimizations and debug checking.
393 _native_compiler_configs += [ "//native_client/build/config:debug" ]
394 default_optimization_config = "//native_client/build/config/compiler:no_optimize"
396 native_compiler_configs += [ "//native_client/build/config:release" ]
397 _default_optimization_config = "//native_client/build/config/compiler:optimize"
400 _native_compiler_configs += [ default_optimization_config ]
403 if (is_clang && is_linux) {
404 # Clang creates chubby debug information, which makes linking very slow.
405 # For now, don't create debug information with clang.
406 # See http://crbug.com/70000
407 # TODO(brettw) This just copies GYP. Why not do this on Mac as well?
408 default_symbols_config = "//native_client/build/config/compiler:no_symbols"
409 } else if (symbol_level == 2) {
410 default_symbols_config = "//native_client/build/config/compiler:symbols"
411 } else if (symbol_level == 1) {
412 default_symbols_config = "//native_client/build/config/compiler:minimal_symbols"
413 } else if (symbol_level == 0) {
414 default_symbols_config = "//native_client/build/config/compiler:no_symbols"
416 assert(false, "Bad value for symbol_level.")
418 _native_compiler_configs += [ default_symbols_config ]
420 # Windows linker setup for EXEs and DLLs.
423 _default_incremental_linking_config =
424 "//native_client/build/config/win:incremental_linking"
426 _default_incremental_linking_config =
427 "//native_client/build/config/win:no_incremental_linking"
429 _windows_linker_configs = [
430 _default_incremental_linking_config,
431 "//native_client/build/config/win:sdk_link",
432 "//native_client/build/config/win:common_linker_setup",
433 # Default to console-mode apps. Most of our targets are tests and such
434 # that shouldn't use the windows subsystem.
435 "//native_client/build/config/win:console",
439 set_defaults("executable") {
442 configs = _native_compiler_configs + [
443 "//native_client/build/config:default_libs",
446 configs += _windows_linker_configs
449 # "///native_clientbuild/config/mac:mac_dynamic_flags",
450 # "//native_client/build/config/mac:mac_executable_flags" ]
451 } else if (is_linux) {
452 # configs += [ "//native_client/build/config/linux:executable_ldconfig" ]
455 configs = _nacl_compiler_configs
459 set_defaults("static_library") {
462 configs += _native_compiler_configs
464 configs += _nacl_compiler_configs
468 set_defaults("shared_library") {
471 configs += _native_compiler_configs + [
472 "//native_client/build/config:default_libs",
475 configs += _windows_linker_configs
477 configs += [ "//native_client/build/config/mac:mac_dynamic_flags" ]
480 configs = _nacl_compiler_configs
484 set_defaults("source_set") {
487 configs = _native_compiler_configs
489 configs = _nacl_compiler_configs