1 # Copyright (c) 2020 Project CHIP Authors
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 import("//build_overrides/build.gni")
16 import("//build_overrides/pigweed.gni")
18 import("${build_root}/config/compiler/compiler.gni")
19 import("${build_root}/config/target.gni")
21 if (current_os == "mac") {
22 import("${build_root}/config/mac/mac_sdk.gni")
26 # Enable -Werror. This can be disabled if using a different compiler
27 # with unfixed or unsupported wanings.
28 treat_warnings_as_errors = true
31 if (current_cpu == "arm" || current_cpu == "arm64") {
32 import("${build_root}/config/arm.gni")
33 } else if (current_cpu == "x86" || current_cpu == "x86_64") {
34 import("${build_root}/config/x86.gni")
38 defines = [ "NDEBUG" ]
41 config("debug_default") {
43 configs = [ ":release" ]
47 config("abi_default") {
49 if (current_os == "mac") {
54 } else if (current_os == "ios") {
55 # iOS ABI currently set by chip_xcode_build_connector.sh
56 } else if (current_cpu == "arm" || current_cpu == "arm64") {
58 cflags += [ "-march=${arm_arch}" ]
61 cflags += [ "-mcpu=${arm_cpu}" ]
64 cflags += [ "-mtune=${arm_tune}" ]
67 cflags += [ "-mabi=${arm_abi}" ]
70 cflags += [ "-mfpu=${arm_fpu}" ]
72 if (arm_float_abi != "") {
73 cflags += [ "-mfloat-abi=${arm_float_abi}" ]
76 cflags += [ "-mthumb" ]
78 } else if (current_cpu == "x86" || current_cpu == "x86_64") {
80 cflags += [ "-march=${x86_arch}" ]
83 cflags += [ "-mcpu=${x86_cpu}" ]
86 cflags += [ "-mtune=${x86_tune}" ]
89 if (current_cpu == "x86_64") {
95 } else if (current_cpu == "x86") {
107 config("target_default") {
108 if (current_toolchain == default_toolchain) {
109 defines = target_defines
110 cflags = target_cflags
111 cflags_c = target_cflags_c
112 cflags_cc = target_cflags_cc
113 ldflags = target_ldflags
117 config("optimize_zero") {
122 config("optimize_default") {
124 if (optimize_debug) {
125 configs = [ "$dir_pw_build:optimize_debugging" ]
127 configs = [ ":optimize_zero" ]
130 if (optimize_for_size) {
131 configs = [ "$dir_pw_build:optimize_size" ]
133 configs = [ "$dir_pw_build:optimize_speed" ]
136 if (current_os != "mac") {
145 config("disabled_warnings") {
147 "-Wno-deprecated-declarations",
148 "-Wno-unknown-warning-option",
149 "-Wno-missing-field-initializers",
150 "-Wno-unused-parameter",
153 # assert() causes unused variable warnings in release.
154 cflags += [ "-Wno-unused" ]
159 "-Wno-cast-function-type",
164 config("strict_warnings") {
169 "-Wunreachable-code",
172 cflags_cc = [ "-Wnon-virtual-dtor" ]
176 if (treat_warnings_as_errors) {
177 cflags += [ "-Werror" ]
178 ldflags += [ "-Werror" ]
183 "-Wimplicit-fallthrough",
188 if (current_os == "linux" || current_os == "android") {
189 ldflags += [ "-Wl,-z,defs" ]
193 config("warnings_default") {
196 ":disabled_warnings",
199 if (current_os != "mac" && current_os != "ios") {
200 ldflags = [ "-Wl,--fatal-warnings" ]
203 if (current_os != "mac" && current_os != "ios" && current_os != "linux" &&
204 current_os != "win") {
205 cflags = [ "-Wstack-usage=8192" ]
209 config("symbols_default") {
210 cflags = [ "-g${symbol_level}" ]
214 cflags_c = [ "-std=gnu11" ]
215 cflags_objc = [ "-std=gnu11" ]
216 cflags_cc = [ "-std=gnu++14" ]
217 cflags_objcc = [ "-std=gnu++14" ]
220 config("std_default") {
221 configs = [ ":gnu14" ]
224 config("cosmetic_default") {
225 configs = [ "$dir_pw_build:colorize_output" ]
228 config("runtime_default") {
231 "$dir_pw_toolchain/host_clang:no_system_libcpp",
232 "$dir_pw_toolchain/host_clang:xcode_sysroot",
235 if (current_os == "linux") {
244 # To use different sanitizer options, use `gn args .` in the out folder and
249 # optimize_for_size=false
251 # is_sanitize_fatal=false
255 # Enable address sanitizer
258 # Enable memory sanitizer
261 # enable undefined behavior sanitizer
264 # Exit on sanitize error. Generally standard libraries may get errors
265 # so not stopping on the first error is often useful
266 is_sanitize_fatal = true
269 config("sanitize_address") {
271 "-fsanitize=address",
272 "-fno-omit-frame-pointer",
277 config("sanitize_memory") {
280 "-fsanitize-memory-track-origins",
281 "-fno-omit-frame-pointer",
286 config("sanitize_undefined_behavior") {
288 "-fvisibility=hidden",
289 "-fsanitize=undefined",
290 "-fsanitize=float-divide-by-zero",
291 "-fsanitize=unsigned-integer-overflow",
292 "-fsanitize=implicit-conversion",
293 "-fsanitize=nullability",
298 config("sanitize_recover_all") {
299 cflags = [ "-fsanitize-recover=all" ]
303 config("sanitize_default") {
307 configs += [ ":sanitize_address" ]
311 configs += [ ":sanitize_memory" ]
315 configs += [ ":sanitize_undefined_behavior" ]
318 if (!is_sanitize_fatal) {
319 configs += [ ":sanitize_recover_all" ]
323 config("fuzzing_default") {
327 cflags_cc = [ "-fno-rtti" ]
331 cflags_cc = [ "-frtti" ]
334 config("rtti_default") {
335 configs = [ ":no_rtti" ]
338 config("no_exceptions") {
339 cflags = [ "-fno-exceptions" ]
342 config("exceptions") {
343 cflags = [ "-fexceptions" ]
346 config("exceptions_default") {
347 configs = [ ":no_exceptions" ]
350 config("unwind_tables") {
351 cflags = [ "-funwind-tables" ]
354 config("no_unwind_tables") {
356 "-fno-unwind-tables",
357 "-fno-asynchronous-unwind-tables",
361 config("unwind_tables_default") {
362 if (exclude_unwind_tables) {
363 configs = [ ":no_unwind_tables" ]
365 configs = [ ":unwind_tables" ]
369 config("size_default") {
372 "-ffunction-sections",
377 config("stack_protector_default") {
378 cflags = [ "-fno-stack-protector" ]
381 config("pic_default") {
388 config("pie_default") {
394 config("aliasing_default") {
395 cflags = [ "-fno-strict-aliasing" ]
398 config("specs_default") {
399 if (current_cpu == "arm" && current_os == "freertos") {
401 "--specs=nosys.specs",
402 "--specs=nano.specs",