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# 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 (like nacl). GN will 32# run the same build file multiple times for the different required 33# configuration in the same build. 34# 35# This gives the following variables: 36# - host_os, host_cpu, host_toolchain 37# - target_os, target_cpu, default_toolchain 38# - current_os, current_cpu, current_toolchain. 39# 40# Note the default_toolchain isn't symmetrical (you would expect 41# target_toolchain). This is because the "default" toolchain is a GN built-in 42# concept, and "target" is something our build sets up that's symmetrical with 43# its GYP counterpart. Potentially the built-in default_toolchain variable 44# could be renamed in the future. 45# 46# When writing build files, to do something only for the host: 47# if (current_toolchain == host_toolchain) { ... 48 49check_mac_system_and_cpu_script = 50 rebase_path("//build/scripts/check_mac_system_and_cpu.py") 51check_darwin_system_result = 52 exec_script(check_mac_system_and_cpu_script, [ "system" ], "string") 53 54if (check_darwin_system_result != "") { 55 check_mac_host_cpu_result = 56 exec_script(check_mac_system_and_cpu_script, [ "cpu" ], "string") 57 if (check_mac_host_cpu_result != "") { 58 host_cpu = "arm64" 59 } 60} 61 62declare_args() { 63 product_name = "" 64 device_name = "" 65} 66 67declare_args() { 68 preloader_output_dir = "//out/preloader/${product_name}" 69} 70 71declare_args() { 72 enable_lto_O0 = false 73} 74 75product_build_config = 76 read_file("${preloader_output_dir}/build_config.json", "json") 77 78global_parts_info = 79 read_file("${preloader_output_dir}/parts_config.json", "json") 80 81product_company = product_build_config.product_company 82device_company = product_build_config.device_company 83device_build_path = product_build_config.device_build_path 84target_os = product_build_config.target_os 85target_cpu = product_build_config.target_cpu 86product_toolchain = product_build_config.product_toolchain_label 87if (product_toolchain == "") { 88 product_toolchain = "//build/toolchain/ohos:ohos_clang_$target_cpu" 89} 90if (defined(product_build_config.enable_ramdisk)) { 91 enable_ramdisk = product_build_config.enable_ramdisk 92} else { 93 enable_ramdisk = false 94} 95if (defined(product_build_config.chipprod_config_path)) { 96 chipprod_config_path = product_build_config.chipprod_config_path 97 import("${chipprod_config_path}/chip_product_list.gni") 98} else { 99 chip_product_list = [] 100} 101if (defined(product_build_config.enable_mesa3d)) { 102 enable_mesa3d = product_build_config.enable_mesa3d 103} else { 104 enable_mesa3d = false 105} 106 107if (defined(product_build_config.build_selinux)) { 108 build_selinux = product_build_config.build_selinux 109} else { 110 build_selinux = false 111} 112 113if (defined(product_build_config.build_seccomp)) { 114 build_seccomp = product_build_config.build_seccomp 115} else { 116 build_seccomp = false 117} 118 119if (defined(product_build_config.support_jsapi)) { 120 support_jsapi = product_build_config.support_jsapi 121} else { 122 if (defined(global_parts_info) && !defined(global_parts_info.arkui_napi)) { 123 support_jsapi = false 124 } else { 125 support_jsapi = true 126 } 127} 128 129if (target_os == "") { 130 target_os = "ohos" 131} 132 133if (target_cpu == "") { 134 if (target_os == "ohos") { 135 target_cpu = "arm" 136 } else { 137 target_cpu = host_cpu 138 } 139} 140 141if (current_cpu == "") { 142 current_cpu = target_cpu 143} 144if (current_os == "") { 145 current_os = target_os 146} 147 148declare_args() { 149 is_mini_system = false 150 is_small_system = false 151 is_standard_system = false 152} 153 154if (is_mini_system) { 155 os_level = "mini" 156} 157if (is_small_system) { 158 os_level = "small" 159} 160if (is_standard_system) { 161 os_level = "standard" 162} 163 164declare_args() { 165 is_large_system = !(is_standard_system || is_small_system || is_mini_system) 166} 167 168is_lite_system = is_mini_system || is_small_system 169 170# ============================================================================= 171# BUILD FLAGS 172# ============================================================================= 173# 174# This block lists input arguments to the build, along with their default 175# values. 176# 177# If a value is specified on the command line, it will overwrite the defaults 178# given in a declare_args block, otherwise the default will be used. 179# 180# YOU SHOULD ALMOST NEVER NEED TO ADD FLAGS TO THIS FILE. GN allows any file in 181# the build to declare build flags. If you need a flag for a single component, 182# you can just declare it in the corresponding BUILD.gn file. 183# 184# - If your feature is a single target, say //components/foo, you can put 185# a declare_args() block in //components/foo/BUILD.gn and use it there. 186# Nobody else in the build needs to see the flag. 187# 188# - Defines based on build variables should be implemented via the generated 189# build flag header system. See //build/buildflag_header.gni. You can put 190# the buildflag_header target in the same file as the build flag itself. You 191# should almost never set "defines" directly. 192# 193# - If your flag toggles a target on and off or toggles between different 194# versions of similar things, write a "group" target that forwards to the 195# right target (or no target) depending on the value of the build flag. This 196# group can be in the same BUILD.gn file as the build flag, and targets can 197# depend unconditionally on the group rather than duplicating flag checks 198# across many targets. 199# 200# - If a semi-random set of build files REALLY needs to know about a define and 201# the above pattern for isolating the build logic in a forwarding group 202# doesn't work, you can put the argument in a .gni file. This should be put 203# in the lowest level of the build that knows about this feature (which should 204# almost always be outside of the //build directory!). 205# 206# Other flag advice: 207# 208# - Use boolean values when possible. If you need a default value that expands 209# to some complex thing in the default case (like the location of the 210# compiler which would be computed by a script), use a default value of -1 or 211# the empty string. Outside of the declare_args block, conditionally expand 212# the default value as necessary. 213# 214# - Use a name like "use_foo" or "is_foo" (whatever is more appropriate for 215# your feature) rather than just "foo". 216# 217# - Write good comments directly above the declaration with no blank line. 218# These comments will appear as documentation in "gn args --list". 219# 220# - Don't call exec_script inside declare_args. This will execute the script 221# even if the value is overridden, which is wasteful. See first bullet. 222 223declare_args() { 224 # Set to enable the official build level of optimization. This has nothing 225 # to do with branding, but enables an additional level of optimization above 226 # release (!is_debug). This might be better expressed as a tri-state 227 # (debug, release, official) but for historical reasons there are two 228 # separate flags. 229 is_official_build = false 230 231 # Whether we're a traditional desktop unix. 232 is_desktop_linux = current_os == "linux" 233 234 # Set to true when compiling with the Clang compiler. 235 is_clang = current_os != "linux" || 236 (current_cpu != "s390x" && current_cpu != "s390" && 237 current_cpu != "ppc64" && current_cpu != "ppc" && 238 current_cpu != "mips" && current_cpu != "mips64") 239 240 # Allows the path to a custom target toolchain to be injected as a single 241 # argument, and set as the default toolchain. 242 custom_toolchain = "" 243 244 # This should not normally be set as a build argument. It's here so that 245 # every toolchain can pass through the "global" value via toolchain_args(). 246 host_toolchain = "" 247 248 # target platform 249 target_platform = "phone" 250 251 # Whether it is test. 252 is_test = false 253 254 # Whether it is double framework. 255 is_double_framework = false 256} 257 258declare_args() { 259 use_musl = true 260} 261 262declare_args() { 263 is_emulator = false 264} 265 266asdk_libs_dir = "//prebuilts/asdk_libs" 267 268# Whether it is a phone product. 269is_phone_product = "${target_platform}" == "phone" 270 271# Whether it is a ivi product. 272is_ivi_product = "${target_platform}" == "ivi" 273 274is_wearable_product = "${target_platform}" == "wearable" 275 276is_intellitv_product = "${target_platform}" == "intellitv" 277 278if (target_os == "ohos" && target_cpu == "x86_64") { 279 is_emulator = true 280} 281 282# different host platform tools directory. 283if (host_os == "linux") { 284 host_platform_dir = "linux-x86_64" 285} else if (host_os == "mac") { 286 if (host_cpu == "arm64") { 287 host_platform_dir = "darwin-arm64" 288 } else { 289 host_platform_dir = "darwin-x86_64" 290 } 291} else { 292 assert(false, "Unsupported host_os: $host_os") 293} 294 295declare_args() { 296 # Debug build. Enabling official builds automatically sets is_debug to false. 297 is_debug = false 298} 299 300declare_args() { 301 # Enable mini debug info, it will add .gnu_debugdata 302 # section in each stripped sofile 303 304 # Currently, we don't publish ohos-adapted python on m1 platform, 305 # So that we disable mini debug info on m1 platform until 306 # ohos-adapted python publishing on m1 platform 307 if (host_os == "mac" && host_cpu == "arm64") { 308 full_mini_debug = false 309 } else { 310 full_mini_debug = true 311 } 312} 313 314declare_args() { 315 # Full Debug mode. Setting optimize level to "-O0" and symbol level to "-g3". 316 # It should be used with "is_debug" 317 ohos_full_debug = false 318} 319 320declare_args() { 321 # Specifies which components use the DEBUG compilation level 322 # Using this arg like this, --gn-args 'enable_debug_components="component1,component2"' 323 enable_debug_components = "" 324} 325 326declare_args() { 327 # We use this arg to split "enable_debug_components" to a list 328 debug_components = string_split(enable_debug_components, ",") 329} 330 331declare_args() { 332 build_xts = false 333} 334 335declare_args() { 336 # Component build. Setting to true compiles targets declared as "components" 337 # as shared libraries loaded dynamically. This speeds up development time. 338 # When false, components will be linked statically. 339 # 340 # For more information see 341 # https://chromium.googlesource.com/chromium/src/+/master/docs/component_build.md 342 is_component_build = true 343} 344 345assert(!(is_debug && is_official_build), "Can't do official debug builds") 346 347# ============================================================================== 348# TOOLCHAIN SETUP 349# ============================================================================== 350# 351# Here we set the default toolchain, as well as the variable host_toolchain 352# which will identify the toolchain corresponding to the local system when 353# doing cross-compiles. When not cross-compiling, this will be the same as the 354# default toolchain. 355# 356# We do this before anything else to make sure we complain about any 357# unsupported os/cpu combinations as early as possible. 358 359if (host_toolchain == "") { 360 # This should only happen in the top-level context. 361 # In a specific toolchain context, the toolchain_args() 362 # block should have propagated a value down. 363 364 if (host_os == "linux") { 365 if (target_os != "linux") { 366 host_toolchain = "//build/toolchain/linux:clang_$host_cpu" 367 } else if (is_clang) { 368 host_toolchain = "//build/toolchain/linux:clang_$host_cpu" 369 } else { 370 host_toolchain = "//build/toolchain/linux:$host_cpu" 371 } 372 } else if (host_os == "mac") { 373 host_toolchain = "//build/toolchain/mac:clang_$host_cpu" 374 } else if (host_os == "win") { 375 if (target_cpu == "x86" || target_cpu == "x64") { 376 if (is_clang) { 377 host_toolchain = "//build/toolchain/win:win_clang_$target_cpu" 378 } else { 379 host_toolchain = "//build/toolchain/win:$target_cpu" 380 } 381 } else if (is_clang) { 382 host_toolchain = "//build/toolchain/win:win_clang_$host_cpu" 383 } else { 384 host_toolchain = "//build/toolchain/win:$host_cpu" 385 } 386 } else { 387 assert(false, "Unsupported host_os: $host_os") 388 } 389} 390 391if (is_standard_system) { 392 _default_toolchain = "" 393 394 if (target_os == "ohos") { 395 assert(host_os == "linux" || host_os == "mac", 396 "ohos builds are only supported on Linux and Mac hosts.") 397 _default_toolchain = product_toolchain 398 } else if (target_os == "linux") { 399 if (is_clang) { 400 _default_toolchain = "//build/toolchain/linux:clang_$target_cpu" 401 } else { 402 _default_toolchain = "//build/toolchain/linux:$target_cpu" 403 } 404 } else { 405 assert(false, "Unsupported target_os: $target_os") 406 } 407 408 # If a custom toolchain has been set in the args, set it as default. Otherwise, 409 # set the default toolchain for the platform (if any). 410 if (custom_toolchain != "") { 411 set_default_toolchain(custom_toolchain) 412 } else if (_default_toolchain != "") { 413 set_default_toolchain(_default_toolchain) 414 } 415} 416 417# ============================================================================= 418# OS DEFINITIONS 419# ============================================================================= 420# 421# We set these various is_FOO booleans for convenience in writing OS-based 422# conditions. 423# 424# - is_ohos, is_chromeos, and is_win should be obvious. 425# - is_mac is set only for desktop Mac. 426# - is_posix is true for mac and any Unix-like system (basically everything 427# except Windows). 428# - is_linux is true for desktop Linux and ChromeOS. 429# 430# Do not add more is_* variants here for random lesser-used Unix systems like 431# aix or one of the BSDs. If you need to check these, just check the 432# current_os value directly. 433 434if (current_os == "win" || current_os == "winuwp") { 435 is_aix = false 436 is_ohos = false 437 is_chromeos = false 438 is_linux = false 439 is_mac = false 440 is_nacl = false 441 is_posix = false 442 is_win = true 443 is_mingw = false 444} else if (current_os == "mac") { 445 is_aix = false 446 is_ohos = false 447 is_chromeos = false 448 is_linux = false 449 is_mac = true 450 is_nacl = false 451 is_posix = true 452 is_win = false 453 is_mingw = false 454} else if (current_os == "ohos") { 455 is_aix = false 456 is_ohos = true 457 is_chromeos = false 458 is_linux = false 459 is_mac = false 460 is_nacl = false 461 is_posix = true 462 is_win = false 463 is_mingw = false 464} else if (current_os == "linux") { 465 is_aix = false 466 is_ohos = false 467 is_chromeos = false 468 is_linux = true 469 is_mac = false 470 is_nacl = false 471 is_posix = true 472 is_win = false 473 is_mingw = false 474} else if (current_os == "mingw") { 475 is_aix = false 476 is_ohos = false 477 is_chromeos = false 478 is_linux = false 479 is_mac = false 480 is_nacl = false 481 is_posix = true 482 is_win = false 483 is_mingw = true 484} 485 486# ============================================================================= 487# SOURCES FILTERS 488# ============================================================================= 489# 490# These patterns filter out platform-specific files when assigning to the 491# sources variable. The magic variable |sources_assignment_filter| is applied 492# to each assignment or appending to the sources variable and matches are 493# automatically removed. 494# 495# Note that the patterns are NOT regular expressions. Only "*" and "\b" (path 496# boundary = end of string or slash) are supported, and the entire string 497# must match the pattern (so you need "*.cc" to match all .cc files, for 498# example). 499 500# DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call 501# below. 502sources_assignment_filter = [] 503 504if (!is_win && !is_mingw) { 505 sources_assignment_filter += [ 506 "*_win.cc", 507 "*_win.h", 508 "*_win_unittest.cc", 509 "*\bwin/*", 510 "*.def", 511 ] 512} 513if (!is_mac) { 514 sources_assignment_filter += [ 515 "*_mac.h", 516 "*_mac.cc", 517 "*_mac.mm", 518 "*_mac_unittest.h", 519 "*_mac_unittest.cc", 520 "*_mac_unittest.mm", 521 "*\bmac/*", 522 "*_cocoa.h", 523 "*_cocoa.cc", 524 "*_cocoa.mm", 525 "*_cocoa_unittest.h", 526 "*_cocoa_unittest.cc", 527 "*_cocoa_unittest.mm", 528 "*\bcocoa/*", 529 ] 530} 531if (!is_linux && !is_ohos) { 532 sources_assignment_filter += [ 533 "*_linux.h", 534 "*_linux.cc", 535 "*_linux_unittest.h", 536 "*_linux_unittest.cc", 537 "*\blinux/*", 538 ] 539} 540if (!is_ohos) { 541 sources_assignment_filter += [] 542} 543 544set_sources_assignment_filter(sources_assignment_filter) 545if (is_standard_system) { 546 file_exist = exec_script("//build/scripts/check_file_exist.py", 547 [ "${device_build_path}/config.gni" ], 548 "string") 549 if (file_exist != "") { 550 import("${device_build_path}/config.gni") 551 } 552 553 # ============================================================================= 554 # TARGET DEFAULTS 555 # ============================================================================= 556 # 557 # Set up the default configuration for every build target of the given type. 558 # The values configured here will be automatically set on the scope of the 559 # corresponding target. Target definitions can add or remove to the settings 560 # here as needed. 561 # 562 # WHAT GOES HERE? 563 # 564 # Other than the main compiler and linker configs, the only reason for a config 565 # to be in this list is if some targets need to explicitly override that config 566 # by removing it. This is how targets opt-out of flags. If you don't have that 567 # requirement and just need to add a config everywhere, reference it as a 568 # sub-config of an existing one, most commonly the main "compiler" one. 569 570 # Holds all configs used for running the compiler. 571 default_compiler_configs = [ 572 "//build/config:feature_flags", 573 "//build/config/compiler:afdo", 574 "//build/config/compiler:afdo_optimize_size", 575 "//build/config/compiler:compiler", 576 "//build/config/compiler:compiler_arm_fpu", 577 "//build/config/compiler:compiler_arm_thumb", 578 "//build/config/compiler:chromium_code", 579 "//build/config/compiler:default_include_dirs", 580 "//build/config/compiler:default_optimization", 581 "//build/config/compiler:default_stack_frames", 582 "//build/config/compiler:default_symbols", 583 "//build/config/compiler:export_dynamic", 584 "//build/config/compiler:no_exceptions", 585 "//build/config/compiler:no_rtti", 586 "//build/config/compiler:runtime_library", 587 "//build/config/compiler:thin_archive", 588 "//build/config/compiler:no_common", 589 "//build/config/coverage:default_coverage", 590 "//build/config/sanitizers:default_sanitizer_flags", 591 "//build/config/security:default_security_configs", 592 ] 593 594 if (is_ohos) { 595 default_compiler_configs += [ 596 "//build/config/ohos:default_orderfile_instrumentation", 597 "//build/config/gcc:symbol_visibility_inline_hidden", 598 ] 599 } 600 601 if (is_clang) { 602 default_compiler_configs += [ 603 "//build/config/clang:find_bad_constructs", 604 "//build/config/clang:extra_warnings", 605 ] 606 } 607 608 # Debug/release-related defines. 609 if (is_debug) { 610 default_compiler_configs += [ "//build/config:debug" ] 611 } else { 612 default_compiler_configs += [ "//build/config:release" ] 613 } 614 615 # Static libraries and source sets use only the compiler ones. 616 default_static_library_configs = default_compiler_configs 617 default_source_set_configs = default_compiler_configs 618 619 # Executable defaults. 620 default_executable_configs = default_compiler_configs + [ 621 "//build/config:default_libs", 622 "//build/config:executable_config", 623 ] 624 625 # Shared library and loadable module defaults (also for components in component 626 # mode). 627 default_shared_library_configs = default_compiler_configs + [ 628 "//build/config:default_libs", 629 "//build/config:shared_library_config", 630 ] 631} 632 633# Lite OS use different buildconfig.gn 634if (is_lite_system) { 635 import("//build/lite/ohos_var.gni") 636 import("${device_config_path}/config.gni") 637 target_arch_cflags = board_cflags 638 if (board_arch != "") { 639 target_arch_cflags += [ "-march=$board_arch" ] 640 } 641 if (board_cpu != "") { 642 target_arch_cflags += [ "-mcpu=$board_cpu" ] 643 } 644 645 arch = "arm" 646 if (ohos_kernel_type == "liteos_a") { 647 target_triple = "$arch-liteos-ohos" 648 } else if (ohos_kernel_type == "linux") { 649 target_triple = "$arch-linux-ohos" 650 } 651 652 if (defined(board_configed_sysroot) && board_configed_sysroot != "") { 653 ohos_current_sysroot = board_configed_sysroot 654 } 655 656 # Only gcc available for liteos_m. 657 if (ohos_kernel_type == "liteos_m" || ohos_kernel_type == "linux") { 658 use_board_toolchain = true 659 } 660 661 toolchain_cmd_suffix = "" 662 if (host_os == "win") { 663 toolchain_cmd_suffix = ".exe" 664 } 665 666 # enable ccache if ccache installed. 667 if (ohos_build_enable_ccache) { 668 compile_prefix = "ccache " 669 } else { 670 compile_prefix = "" 671 } 672 673 # Load board adapter dir from board config. 674 if (board_adapter_dir != "") { 675 ohos_board_adapter_dir = board_adapter_dir 676 ohos_vendor_adapter_dir = board_adapter_dir 677 } 678 679 default_compiler_configs = [] 680 681 # Set current toolchain with to board configuration. 682 if (board_toolchain != "" && use_board_toolchain) { 683 ohos_build_compiler = board_toolchain_type 684 if (board_toolchain_path != "") { 685 compile_prefix += "${board_toolchain_path}/${board_toolchain_prefix}" 686 } else { 687 compile_prefix += "${board_toolchain_prefix}" 688 } 689 set_default_toolchain("//build/lite/toolchain:${board_toolchain}") 690 if (board_toolchain_type == "gcc") { 691 ohos_current_cc_command = "${compile_prefix}gcc$toolchain_cmd_suffix" 692 ohos_current_cxx_command = "${compile_prefix}g++$toolchain_cmd_suffix" 693 ohos_current_ar_command = "${compile_prefix}ar$toolchain_cmd_suffix" 694 ohos_current_ld_command = ohos_current_cc_command 695 ohos_current_strip_command = 696 "${compile_prefix}strip$toolchain_cmd_suffix --strip-unneeded" 697 default_compiler_configs += [ "//build/lite/config:gcc_opt" ] 698 } else if (board_toolchain_type == "clang") { 699 ohos_current_cc_command = "${compile_prefix}clang$toolchain_cmd_suffix" 700 ohos_current_cxx_command = "${compile_prefix}clang++$toolchain_cmd_suffix" 701 compile_prefix += "llvm-" 702 ohos_current_ar_command = "${compile_prefix}ar$toolchain_cmd_suffix" 703 ohos_current_ld_command = ohos_current_cc_command 704 ohos_current_strip_command = 705 "${compile_prefix}strip$toolchain_cmd_suffix --strip-unneeded" 706 default_compiler_configs += [ "//build/lite/config:clang_opt" ] 707 } 708 709 # Overwrite ld cmd by customed cmd. 710 if (defined(board_customed_ld_cmd) && board_customed_ld_cmd != "") { 711 ohos_current_ld_command = board_customed_ld_cmd 712 } 713 } else { 714 # OHOS default toolchain 715 ohos_build_compiler = "clang" 716 ohos_clang_toolchain_dir = rebase_path("${ohos_build_compiler_dir}/bin") 717 compile_prefix += "$ohos_clang_toolchain_dir/" 718 ohos_current_cc_command = "${compile_prefix}clang$toolchain_cmd_suffix" 719 ohos_current_cxx_command = "${compile_prefix}clang++$toolchain_cmd_suffix" 720 compile_prefix += "llvm-" 721 ohos_current_ar_command = "${compile_prefix}ar$toolchain_cmd_suffix" 722 ohos_current_ld_command = ohos_current_cxx_command 723 ohos_current_strip_command = 724 "${compile_prefix}strip$toolchain_cmd_suffix --strip-unneeded" 725 if (current_os == "ohos") { 726 set_default_toolchain("//build/lite/toolchain:linux_x86_64_ohos_clang") 727 default_compiler_configs += [ 728 "//build/lite/config:ohos_clang", 729 "//build/lite/config:clang_opt", 730 ] 731 } else { 732 set_default_toolchain("//build/toolchain/linux:clang_$target_cpu") 733 default_compiler_configs += [ 734 "//build/config/sanitizers:default_sanitizer_flags", 735 "//build/config:default_libs", 736 "//build/config:executable_config", 737 "//build/config/compiler:default_include_dirs", 738 "//build/config/compiler:compiler", 739 ] 740 } 741 } 742 if (current_os == "ohos") { 743 default_compiler_configs += [ 744 "//build/lite/config:board_config", 745 "//build/lite/config:cpu_arch", 746 "//build/lite/config:common", 747 "//build/lite/config:default_link_path", 748 ] 749 } 750 751 if (ohos_build_type == "debug") { 752 default_compiler_configs += [ "//build/lite/config:debug" ] 753 } else if (ohos_build_type == "release") { 754 default_compiler_configs += [ "//build/lite/config:release" ] 755 } 756 757 if (ohos_kernel_type == "liteos_a" && current_os == "ohos") { 758 default_compiler_configs += 759 [ "//build/lite/config/kernel/liteos/cortex_a:default" ] 760 } 761 762 if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") { 763 default_compiler_configs += [ 764 "//build/lite/config:security", 765 "//build/lite/config:exceptions", 766 ] 767 } else if (ohos_kernel_type == "liteos_m") { 768 default_compiler_configs += [ "//build/lite/config:stack_protector" ] 769 } 770 771 default_compiler_configs += [ 772 "//build/lite/config:language_c", 773 "//build/lite/config:language_cpp", 774 ] 775 776 if (current_os == "ohos") { 777 default_compiler_configs += [ "//build/lite/config:kernel_macros" ] 778 } 779 780 default_shared_library_configs = 781 default_compiler_configs + [ "//build/lite/config:shared_library_config" ] 782 default_static_library_configs = default_compiler_configs 783 default_executable_configs = default_compiler_configs 784 if (ohos_kernel_type != "liteos_m") { 785 default_static_library_configs += 786 [ "//build/lite/config:static_pie_config" ] 787 default_executable_configs += [ "//build/lite/config:static_pie_config" ] 788 default_executable_configs += 789 [ "//build/lite/config:pie_executable_config" ] 790 } 791 default_executable_configs += [ "//build/lite/config:board_exe_ld_flags" ] 792} 793 794set_defaults("executable") { 795 configs = default_executable_configs 796} 797 798set_defaults("static_library") { 799 configs = default_static_library_configs 800} 801 802set_defaults("shared_library") { 803 configs = default_shared_library_configs 804} 805 806set_defaults("source_set") { 807 configs = default_compiler_configs 808} 809 810# Sets default dependencies for executable and shared_library targets. 811# 812# Variables 813# no_default_deps: If true, no standard dependencies will be added. 814target_type_list = [ 815 "executable", 816 "loadable_module", 817 "shared_library", 818 "static_library", 819 "source_set", 820] 821 822foreach(_target_type, target_type_list) { 823 template(_target_type) { 824 target(_target_type, target_name) { 825 forward_variables_from(invoker, "*", [ "no_default_deps" ]) 826 if (!defined(deps)) { 827 deps = [] 828 } 829 if (!defined(invoker.no_default_deps) || !invoker.no_default_deps) { 830 if (is_lite_system && current_os == "ohos") { 831 deps += [ "//third_party/musl:sysroot_lite" ] 832 } else { 833 deps += [ "//build/config:${_target_type}_deps" ] 834 } 835 } 836 } 837 } 838} 839 840if (is_lite_system && current_os == "ohos") { 841 _target_type_list = [ 842 "action", 843 "action_foreach", 844 ] 845 846 foreach(_target_type, _target_type_list) { 847 template(_target_type) { 848 target(_target_type, target_name) { 849 forward_variables_from(invoker, "*", [ "no_default_deps" ]) 850 if (!defined(deps)) { 851 deps = [] 852 } 853 if (!defined(invoker.no_default_deps) || !invoker.no_default_deps) { 854 deps += [ "//third_party/musl:sysroot_lite" ] 855 } 856 } 857 } 858 } 859} 860