BUILDCONFIG.gn 4.8 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/ohos_var.gni")
import("${device_path}/config.gni")

if (target_os == "") {
  target_os = "ohos"
}

if (target_cpu == "") {
  target_cpu = board_cpu
}

# Only gcc avaiable for liteos_m.
if (ohos_kernel_type == "liteos_m" || ohos_kernel_type == "linux") {
  use_board_toolchain = true
}

# Set current toolchain with to board configuration.
if (board_toolchain != "" && use_board_toolchain) {
  ohos_current_toolchain = board_toolchain
  ohos_current_toolchain_type = board_toolchain_type
  ohos_build_compiler = ohos_current_toolchain_type
  hos_build_compiler = ohos_current_toolchain_type
  if (board_toolchain_path != "") {
    compile_prefix = "${board_toolchain_path}/${board_toolchain_prefix}"
  } else {
    compile_prefix = "${board_toolchain_prefix}"
  }
  ohos_current_toolchain_prefix = compile_prefix
  ohos_current_sysroot = board_configed_sysroot
  set_default_toolchain("//build/lite/toolchain:${board_toolchain}")
  if (board_toolchain_type == "gcc") {
    ohos_current_cc_command = "${compile_prefix}gcc"
    ohos_current_cxx_command = "${compile_prefix}g++"
    ohos_current_ar_command = "${compile_prefix}ar"
    ohos_current_ld_command = ohos_current_cc_command
    ohos_current_strip_command = "${compile_prefix}strip --strip-unneeded"
    default_target_configs = [ "//build/lite/config:gcc_opt" ]
  } else if (board_toolchain_type == "clang") {
    ohos_current_cc_command = "${compile_prefix}clang"
    ohos_current_cxx_command = "${compile_prefix}clang++"
    ohos_current_ar_command = "${compile_prefix}llvm-ar"
    ohos_current_as_command = ohos_current_cc_command
    ohos_current_ld_command = ohos_current_cc_command
    ohos_current_strip_command = "$compile_prefix/llvm-objcopy --strip-all"
    default_target_configs += [ "//build/lite/config:clang_opt" ]
  }
} else {
  # OHOS default toolchain: ohos_clang
  ohos_current_toolchain = "ohos_clang"
  ohos_build_compiler = "clang"
  hos_build_compiler = "clang"
  ohos_clang_toolchain_dir = rebase_path("${ohos_build_compiler_dir}/bin")
  compile_prefix = rebase_path("${ohos_build_compiler_dir}/bin")
  ohos_current_cc_command = "${compile_prefix}/clang"
  ohos_current_cxx_command = "${compile_prefix}/clang++"
  ohos_current_ar_command = "${compile_prefix}/llvm-ar"
  ohos_current_as_command = ohos_current_cc_command
  ohos_current_ld_command = ohos_current_cc_command
J
jady3356 已提交
71
  ohos_current_strip_command =
M
mamingshuai 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
      "$ohos_clang_toolchain_dir/llvm-objcopy --strip-all"
  set_default_toolchain("//build/lite/toolchain:linux_x86_64_ohos_clang")
  default_target_configs = [ "//build/lite/config:clang" ]
  default_target_configs += [ "//build/lite/config:clang_opt" ]
}

default_target_configs += [
  "//build/lite/config:board_config",
  "//build/lite/config:cpu_arch",
  "//build/lite/config:common",
  "//build/lite/config:default_link_path",
]

if (ohos_build_type == "debug") {
  default_target_configs += [ "//build/lite/config:debug" ]
} else if (ohos_build_type == "release") {
  default_target_configs += [ "//build/lite/config:release" ]
}

if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
  default_target_configs += [
    "//build/lite/config/kernel/liteos/cortex_a:default",
    "//build/lite/config:security",
    "//build/lite/config:exceptions",
  ]
} else if (ohos_kernel_type == "liteos_m") {
  default_target_configs += [ "//build/lite/config:stack_protector" ]
}

default_target_configs += [
  "//build/lite/config:language_c",
  "//build/lite/config:language_cpp",
  "//build/lite/config:kernel_macros",
]

default_shared_library_configs =
    default_target_configs + [ "//build/lite/config:shared_library_config" ]
default_static_library_configs = default_target_configs
if (ohos_kernel_type != "liteos_m") {
  default_static_library_configs += [ "//build/lite/config:static_pie_config" ]
}
default_executable_configs = default_static_library_configs +
                             [ "//build/lite/config:pie_executable_config" ]

set_defaults("executable") {
  configs = default_executable_configs
118
  configs += [ "//build/lite/config:board_exe_ld_flags" ]
M
mamingshuai 已提交
119 120 121 122 123 124 125 126 127 128 129 130 131
}

set_defaults("static_library") {
  configs = default_static_library_configs
}

set_defaults("shared_library") {
  configs = default_shared_library_configs
}

set_defaults("source_set") {
  configs = default_target_configs
}