blob: 7eb09b79c4c22d4d1febf989ce63c31264f0cbd6 [file] [log] [blame]
# Copyright (c) 2020 Project CHIP Authors
#
# 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.
declare_args() {
# Debug build. Set this to false to remove development features.
is_debug = true
}
if (target_os == "") {
target_os = host_os
}
if (target_cpu == "") {
target_cpu = host_cpu
}
if (current_cpu == "") {
current_cpu = target_cpu
}
if (current_os == "") {
current_os = target_os
}
_build_overrides = {
import("//build_overrides/build.gni")
}
_pigweed_overrides = {
import("//build_overrides/pigweed.gni")
}
_chip_defaults = {
import("${_build_overrides.build_root}/config/defaults.gni")
}
declare_args() {
# Toolchain to use for host. This is usually set by default.
host_toolchain = ""
}
if (host_toolchain == "") {
if (_chip_defaults.is_clang) {
host_toolchain = "${_build_overrides.build_root}/toolchain/host:${host_os}_${host_cpu}_clang"
} else {
host_toolchain = "${_build_overrides.build_root}/toolchain/host:${host_os}_${host_cpu}_gcc"
}
}
_custom_toolchain = {
import("${_build_overrides.build_root}/toolchain/custom/custom.gni")
}
if (_chip_defaults.custom_toolchain != "") {
if (filter_include([ _chip_defaults.custom_toolchain ], [ "/*" ]) == []) {
# Interpret relative toolchain names relative to ${build_root}/toolchain/
_default_toolchain = "${_build_overrides.build_root}/toolchain/${_chip_defaults.custom_toolchain}"
} else {
_default_toolchain = _chip_defaults.custom_toolchain
}
} else if (target_os == "all") {
_default_toolchain = "${_pigweed_overrides.dir_pw_toolchain}/default"
} else if (target_os == "linux") {
if (_chip_defaults.is_clang) {
_target_compiler = "clang"
} else {
_target_compiler = "gcc"
}
_default_toolchain = "${_build_overrides.build_root}/toolchain/linux:linux_${target_cpu}_${_target_compiler}"
} else if (host_os == "mac" && (target_os == "mac" || target_os == "ios")) {
# On Mac the host toolchain supports building for all mac and ios targets
_default_toolchain = host_toolchain
} else if (target_os == host_os && target_cpu == host_cpu) {
_default_toolchain = host_toolchain
} else if (target_os == "freertos") {
if (_chip_defaults.is_clang) {
_target_compiler = "clang"
} else {
_target_compiler = "gcc"
}
if (target_cpu == "arm") {
_default_toolchain =
"${_build_overrides.build_root}/toolchain/arm_${_target_compiler}"
} else if (target_cpu == "riscv") {
_default_toolchain = "${_build_overrides.build_root}/toolchain/riscv_gcc"
} else {
assert(false, "Unsupported target_cpu: ${target_cpu}")
}
} else if (target_os == "android") {
if (current_cpu == "arm") {
_default_toolchain =
"${_build_overrides.build_root}/toolchain/android:android_arm"
} else if (current_cpu == "arm64") {
_default_toolchain =
"${_build_overrides.build_root}/toolchain/android:android_arm64"
} else if (current_cpu == "x64") {
_default_toolchain =
"${_build_overrides.build_root}/toolchain/android:android_x64"
} else if (current_cpu == "x86") {
_default_toolchain =
"${_build_overrides.build_root}/toolchain/android:android_x86"
} else {
assert(false, "Unsupported target_cpu: ${current_cpu}")
}
} else if (target_os == "tizen") {
_default_toolchain =
"${_build_overrides.build_root}/toolchain/tizen:tizen_${target_cpu}"
} else if (target_os == "webos") {
if (target_cpu == "arm" || target_cpu == "arm64") {
_default_toolchain = "${_build_overrides.build_root}/toolchain/webos"
} else {
assert(false,
"Unsupported target_cpu: ${current_cpu}. Shall be arm for webOS")
}
} else {
assert(
false,
"No toolchain specified, please specify custom_toolchain for host_os='${host_os}', target_os='${target_os}', host_cpu='${host_cpu}', target_cpu='${target_cpu}'")
}
set_default_toolchain(_default_toolchain)
set_defaults("static_library") {
configs = _chip_defaults.default_configs
}
set_defaults("source_set") {
configs = _chip_defaults.default_configs
}
set_defaults("executable") {
configs =
_chip_defaults.default_configs + _chip_defaults.executable_default_configs
}
set_defaults("shared_library") {
configs = _chip_defaults.default_configs
}
set_defaults("loadable_module") {
configs = _chip_defaults.default_configs
}