blob: 7eb09b79c4c22d4d1febf989ce63c31264f0cbd6 [file] [log] [blame]
Michael Spangefa630b2020-07-08 22:23:08 -04001# Copyright (c) 2020 Project CHIP Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15declare_args() {
16 # Debug build. Set this to false to remove development features.
17 is_debug = true
18}
19
20if (target_os == "") {
21 target_os = host_os
22}
23
24if (target_cpu == "") {
25 target_cpu = host_cpu
26}
27
28if (current_cpu == "") {
29 current_cpu = target_cpu
30}
31if (current_os == "") {
32 current_os = target_os
33}
34
Łukasz Duda4e1faf22021-01-27 17:47:25 +010035_build_overrides = {
36 import("//build_overrides/build.gni")
Michael Spangefa630b2020-07-08 22:23:08 -040037}
38
39_pigweed_overrides = {
40 import("//build_overrides/pigweed.gni")
41}
42
43_chip_defaults = {
Łukasz Duda4e1faf22021-01-27 17:47:25 +010044 import("${_build_overrides.build_root}/config/defaults.gni")
Michael Spangefa630b2020-07-08 22:23:08 -040045}
46
47declare_args() {
48 # Toolchain to use for host. This is usually set by default.
49 host_toolchain = ""
50}
51
52if (host_toolchain == "") {
53 if (_chip_defaults.is_clang) {
Łukasz Duda4e1faf22021-01-27 17:47:25 +010054 host_toolchain = "${_build_overrides.build_root}/toolchain/host:${host_os}_${host_cpu}_clang"
Michael Spangefa630b2020-07-08 22:23:08 -040055 } else {
Łukasz Duda4e1faf22021-01-27 17:47:25 +010056 host_toolchain = "${_build_overrides.build_root}/toolchain/host:${host_os}_${host_cpu}_gcc"
Michael Spangefa630b2020-07-08 22:23:08 -040057 }
58}
59
Karsten Sperling3902c352023-05-03 15:41:32 +120060_custom_toolchain = {
61 import("${_build_overrides.build_root}/toolchain/custom/custom.gni")
62}
63
Michael Spangefa630b2020-07-08 22:23:08 -040064if (_chip_defaults.custom_toolchain != "") {
Karsten Sperling3902c352023-05-03 15:41:32 +120065 if (filter_include([ _chip_defaults.custom_toolchain ], [ "/*" ]) == []) {
66 # Interpret relative toolchain names relative to ${build_root}/toolchain/
67 _default_toolchain = "${_build_overrides.build_root}/toolchain/${_chip_defaults.custom_toolchain}"
68 } else {
69 _default_toolchain = _chip_defaults.custom_toolchain
70 }
Michael Spangefa630b2020-07-08 22:23:08 -040071} else if (target_os == "all") {
Rob Mohr41c76b62021-06-02 12:43:21 -070072 _default_toolchain = "${_pigweed_overrides.dir_pw_toolchain}/default"
Michael Spang1e6d70b2021-08-31 20:41:54 -040073} else if (target_os == "linux") {
74 if (_chip_defaults.is_clang) {
75 _target_compiler = "clang"
76 } else {
77 _target_compiler = "gcc"
78 }
Michael Spang1e6d70b2021-08-31 20:41:54 -040079 _default_toolchain = "${_build_overrides.build_root}/toolchain/linux:linux_${target_cpu}_${_target_compiler}"
Karsten Sperling36f9ff62024-02-29 18:05:02 +130080} else if (host_os == "mac" && (target_os == "mac" || target_os == "ios")) {
81 # On Mac the host toolchain supports building for all mac and ios targets
82 _default_toolchain = host_toolchain
83} else if (target_os == host_os && target_cpu == host_cpu) {
Michael Spang1e6d70b2021-08-31 20:41:54 -040084 _default_toolchain = host_toolchain
Michael Spangefa630b2020-07-08 22:23:08 -040085} else if (target_os == "freertos") {
Michael Spang2c6acd52022-04-29 14:29:53 -040086 if (_chip_defaults.is_clang) {
87 _target_compiler = "clang"
88 } else {
89 _target_compiler = "gcc"
90 }
91
Michael Spangefa630b2020-07-08 22:23:08 -040092 if (target_cpu == "arm") {
Michael Spang2c6acd52022-04-29 14:29:53 -040093 _default_toolchain =
94 "${_build_overrides.build_root}/toolchain/arm_${_target_compiler}"
jczhang77736661382022-04-04 21:33:18 +080095 } else if (target_cpu == "riscv") {
96 _default_toolchain = "${_build_overrides.build_root}/toolchain/riscv_gcc"
Michael Spangefa630b2020-07-08 22:23:08 -040097 } else {
98 assert(false, "Unsupported target_cpu: ${target_cpu}")
99 }
randyrossi90988b62020-08-19 13:39:57 -0400100} else if (target_os == "android") {
randyrossi90988b62020-08-19 13:39:57 -0400101 if (current_cpu == "arm") {
Łukasz Duda4e1faf22021-01-27 17:47:25 +0100102 _default_toolchain =
103 "${_build_overrides.build_root}/toolchain/android:android_arm"
Andrei Litvin823cf8d2020-08-31 22:32:21 -0400104 } else if (current_cpu == "arm64") {
Łukasz Duda4e1faf22021-01-27 17:47:25 +0100105 _default_toolchain =
106 "${_build_overrides.build_root}/toolchain/android:android_arm64"
Michael Spangfdc49a32020-09-03 18:33:20 -0400107 } else if (current_cpu == "x64") {
Łukasz Duda4e1faf22021-01-27 17:47:25 +0100108 _default_toolchain =
109 "${_build_overrides.build_root}/toolchain/android:android_x64"
Andrei Litvin823cf8d2020-08-31 22:32:21 -0400110 } else if (current_cpu == "x86") {
Łukasz Duda4e1faf22021-01-27 17:47:25 +0100111 _default_toolchain =
112 "${_build_overrides.build_root}/toolchain/android:android_x86"
randyrossi90988b62020-08-19 13:39:57 -0400113 } else {
114 assert(false, "Unsupported target_cpu: ${current_cpu}")
115 }
Wootak Junge945d162021-09-13 10:39:32 +0900116} else if (target_os == "tizen") {
117 _default_toolchain =
118 "${_build_overrides.build_root}/toolchain/tizen:tizen_${target_cpu}"
sungmok shinb3c37992022-03-02 02:55:12 +0900119} else if (target_os == "webos") {
120 if (target_cpu == "arm" || target_cpu == "arm64") {
nxptest2d0c5292022-06-24 19:04:49 +0800121 _default_toolchain = "${_build_overrides.build_root}/toolchain/webos"
sungmok shinb3c37992022-03-02 02:55:12 +0900122 } else {
123 assert(false,
124 "Unsupported target_cpu: ${current_cpu}. Shall be arm for webOS")
125 }
Michael Spangefa630b2020-07-08 22:23:08 -0400126} else {
Boris Zbarsky40fc3ea2024-02-21 13:03:41 -0500127 assert(
128 false,
129 "No toolchain specified, please specify custom_toolchain for host_os='${host_os}', target_os='${target_os}', host_cpu='${host_cpu}', target_cpu='${target_cpu}'")
Michael Spangefa630b2020-07-08 22:23:08 -0400130}
131
132set_default_toolchain(_default_toolchain)
133
134set_defaults("static_library") {
135 configs = _chip_defaults.default_configs
136}
137set_defaults("source_set") {
138 configs = _chip_defaults.default_configs
139}
140set_defaults("executable") {
141 configs =
142 _chip_defaults.default_configs + _chip_defaults.executable_default_configs
143}
144set_defaults("shared_library") {
145 configs = _chip_defaults.default_configs
146}
147set_defaults("loadable_module") {
148 configs = _chip_defaults.default_configs
149}