BUILDCONFIG.gn 6.3 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
# 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
}

24
target_arch_cflags = board_cflags
C
Caoruihong 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
if (board_arch != "") {
  target_arch_cflags += [ "-march=$board_arch" ]
}
if (board_cpu != "") {
  target_arch_cflags += [ "-mcpu=$board_cpu" ]
}

arch = "arm"
if (ohos_kernel_type == "liteos_a") {
  target_triple = "$arch-liteos"
} else if (ohos_kernel_type == "linux") {
  target_triple = "$arch-linux-ohosmusl"
}

if (defined(board_configed_sysroot) && board_configed_sysroot != "") {
  ohos_current_sysroot = board_configed_sysroot
}

Z
Zygmunt Krynicki 已提交
43
# Only gcc available for liteos_m.
M
mamingshuai 已提交
44 45 46 47
if (ohos_kernel_type == "liteos_m" || ohos_kernel_type == "linux") {
  use_board_toolchain = true
}

48 49 50 51 52
toolchain_cmd_suffix = ""
if (host_os == "win") {
  toolchain_cmd_suffix = ".exe"
}

Y
yangming_ha 已提交
53 54 55 56 57 58 59
# enable ccache if ccache installed.
if (ohos_build_enable_ccache) {
  compile_prefix = "ccache "
} else {
  compile_prefix = ""
}

60 61 62 63 64 65
# Load board adapter dir from board config.
if (board_adapter_dir != "") {
  ohos_board_adapter_dir = board_adapter_dir
  ohos_vendor_adapter_dir = board_adapter_dir
}

M
mamingshuai 已提交
66 67
# Set current toolchain with to board configuration.
if (board_toolchain != "" && use_board_toolchain) {
C
Caoruihong 已提交
68
  ohos_build_compiler = board_toolchain_type
M
mamingshuai 已提交
69
  if (board_toolchain_path != "") {
Y
yangming_ha 已提交
70
    compile_prefix += "${board_toolchain_path}/${board_toolchain_prefix}"
M
mamingshuai 已提交
71
  } else {
Y
yangming_ha 已提交
72
    compile_prefix += "${board_toolchain_prefix}"
M
mamingshuai 已提交
73 74 75
  }
  set_default_toolchain("//build/lite/toolchain:${board_toolchain}")
  if (board_toolchain_type == "gcc") {
76 77 78
    ohos_current_cc_command = "${compile_prefix}gcc$toolchain_cmd_suffix"
    ohos_current_cxx_command = "${compile_prefix}g++$toolchain_cmd_suffix"
    ohos_current_ar_command = "${compile_prefix}ar$toolchain_cmd_suffix"
M
mamingshuai 已提交
79
    ohos_current_ld_command = ohos_current_cc_command
80 81
    ohos_current_strip_command =
        "${compile_prefix}strip$toolchain_cmd_suffix --strip-unneeded"
M
mamingshuai 已提交
82 83
    default_target_configs = [ "//build/lite/config:gcc_opt" ]
  } else if (board_toolchain_type == "clang") {
84 85
    ohos_current_cc_command = "${compile_prefix}clang$toolchain_cmd_suffix"
    ohos_current_cxx_command = "${compile_prefix}clang++$toolchain_cmd_suffix"
86 87
    compile_prefix += "llvm-"
    ohos_current_ar_command = "${compile_prefix}ar$toolchain_cmd_suffix"
M
mamingshuai 已提交
88
    ohos_current_ld_command = ohos_current_cc_command
89 90
    ohos_current_strip_command =
        "${compile_prefix}strip$toolchain_cmd_suffix --strip-unneeded"
Y
yangming_ha 已提交
91
    default_target_configs = [ "//build/lite/config:clang_opt" ]
M
mamingshuai 已提交
92
  }
93

Y
yangming_ha 已提交
94
  # Overwrite ld cmd by customed cmd.
95
  if (defined(board_customed_ld_cmd) && board_customed_ld_cmd != "") {
Y
yangming_ha 已提交
96 97
    ohos_current_ld_command = board_customed_ld_cmd
  }
M
mamingshuai 已提交
98
} else {
C
Caoruihong 已提交
99
  # OHOS default toolchain
M
mamingshuai 已提交
100 101
  ohos_build_compiler = "clang"
  ohos_clang_toolchain_dir = rebase_path("${ohos_build_compiler_dir}/bin")
102 103 104 105 106
  compile_prefix += "$ohos_clang_toolchain_dir/"
  ohos_current_cc_command = "${compile_prefix}clang$toolchain_cmd_suffix"
  ohos_current_cxx_command = "${compile_prefix}clang++$toolchain_cmd_suffix"
  compile_prefix += "llvm-"
  ohos_current_ar_command = "${compile_prefix}ar$toolchain_cmd_suffix"
C
Caoruihong 已提交
107
  ohos_current_ld_command = ohos_current_cxx_command
108 109
  ohos_current_strip_command =
      "${compile_prefix}strip$toolchain_cmd_suffix --strip-unneeded"
M
mamingshuai 已提交
110
  set_default_toolchain("//build/lite/toolchain:linux_x86_64_ohos_clang")
Y
yangming_ha 已提交
111
  default_target_configs = [ "//build/lite/config:ohos_clang" ]
M
mamingshuai 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  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" ]
}

Y
yangming_ha 已提交
128
if (ohos_kernel_type == "liteos_a") {
129 130
  default_target_configs +=
      [ "//build/lite/config/kernel/liteos/cortex_a:default" ]
Y
yangming_ha 已提交
131 132
}

M
mamingshuai 已提交
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
  default_target_configs += [
    "//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
151
default_executable_configs = default_static_library_configs
M
mamingshuai 已提交
152 153
if (ohos_kernel_type != "liteos_m") {
  default_static_library_configs += [ "//build/lite/config:static_pie_config" ]
154
  default_executable_configs += [ "//build/lite/config:static_pie_config" ]
155
  default_executable_configs += [ "//build/lite/config:pie_executable_config" ]
M
mamingshuai 已提交
156 157 158 159
}

set_defaults("executable") {
  configs = default_executable_configs
160
  configs += [ "//build/lite/config:board_exe_ld_flags" ]
M
mamingshuai 已提交
161 162 163 164 165 166 167 168 169 170 171 172 173
}

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
}
C
Caoruihong 已提交
174

175 176 177 178 179 180 181 182
_target_type_list = [
  "executable",
  "static_library",
  "shared_library",
  "source_set",
  "action",
  "action_foreach",
]
C
Caoruihong 已提交
183

184 185 186 187 188 189
foreach(_target_type, _target_type_list) {
  template(_target_type) {
    target(_target_type, target_name) {
      forward_variables_from(invoker, "*", [ "no_default_deps" ])
      if (!defined(deps)) {
        deps = []
190
      }
191 192
      if (!defined(invoker.no_default_deps) || !invoker.no_default_deps) {
        deps += [ "//build/lite:prebuilts" ]
193 194
      }
    }
C
Caoruihong 已提交
195 196
  }
}