blob: fc50a216ab1d198b4d4979067feb080e9e7d8226 [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.
import("//build_overrides/chip.gni")
import("//build_overrides/pigweed.gni")
import("//build/config/compiler/compiler.gni")
if (current_cpu == "arm") {
import("//build/config/arm.gni")
}
config("release") {
defines = [ "NDEBUG" ]
}
config("debug_default") {
if (!is_debug) {
configs = [ ":release" ]
}
}
config("abi_default") {
cflags = []
if (current_cpu == "arm") {
if (arm_arch != "") {
cflags += [ "-march=${arm_arch}" ]
}
if (arm_cpu != "") {
cflags += [ "-mcpu=${arm_cpu}" ]
}
if (arm_tune != "") {
cflags += [ "-mtune=${arm_tune}" ]
}
if (arm_abi != "") {
cflags += [ "-mabi=${arm_abi}" ]
}
if (arm_fpu != "") {
cflags += [ "-mfpu=${arm_fpu}" ]
}
if (arm_float_abi != "") {
cflags += [ "-mfloat-abi=${arm_float_abi}" ]
}
if (arm_use_thumb) {
cflags += [ "-mthumb" ]
}
}
ldflags = cflags
}
config("optimize_zero") {
cflags = [ "-O0" ]
ldflags = cflags
}
config("optimize_default") {
if (is_debug) {
if (optimize_debug) {
configs = [ "$dir_pw_build:optimize_debugging" ]
} else {
configs = [ ":optimize_zero" ]
}
} else {
if (optimize_for_size) {
configs = [ "$dir_pw_build:optimize_size" ]
} else {
configs = [ "$dir_pw_build:optimize_speed" ]
}
if (current_os != "mac") {
ldflags = [
"-Wl,-O2",
"-Wl,--gc-sections",
]
}
}
}
config("disabled_warnings") {
cflags = [
"-Wno-unused-parameter",
"-Wno-unused-function",
"-Wno-unused-variable",
"-Wno-format",
"-Wno-missing-field-initializers",
"-Wno-expansion-to-defined",
"-Wno-implicit-fallthrough",
"-Wno-deprecated-declarations",
]
cflags_cc = [
"-Wno-non-virtual-dtor",
"-Wno-deprecated-copy",
]
if (!is_clang) {
cflags += [
"-Wno-cast-function-type",
"-Wno-maybe-uninitialized",
"-Wno-unknown-warning-option",
]
}
}
config("strict_warnings") {
cflags = [
"-Wall",
"-Werror",
]
}
config("warnings_default") {
configs = [
":strict_warnings",
":disabled_warnings",
]
if (current_os != "mac") {
ldflags = [ "-Wl,--fatal-warnings" ]
}
}
config("symbols_default") {
cflags = [ "-g${symbol_level}" ]
}
config("gnu11") {
cflags_c = [ "-std=gnu11" ]
cflags_cc = [ "-std=gnu++11" ]
}
config("std_default") {
configs = [ ":gnu11" ]
}
config("cosmetic_default") {
configs = [ "$dir_pw_build:colorize_output" ]
}
config("runtime_default") {
if (is_clang) {
configs = [
"$dir_pw_toolchain/host_clang:no_system_libcpp",
"$dir_pw_toolchain/host_clang:xcode_sysroot",
]
}
if (current_os == "linux") {
libs = [
"dl",
"pthread",
"rt",
]
}
}
config("sanitize_default") {
}
config("fuzzing_default") {
}
config("no_rtti") {
cflags_cc = [ "-fno-rtti" ]
}
config("rtti") {
cflags_cc = [ "-frtti" ]
}
config("rtti_default") {
configs = [ ":no_rtti" ]
}
config("no_exceptions") {
cflags = [ "-fno-exceptions" ]
}
config("exceptions") {
cflags = [ "-fexceptions" ]
}
config("exceptions_default") {
configs = [ ":no_exceptions" ]
}
config("unwind_tables_default") {
cflags = [
"-fno-unwind-tables",
"-fno-asynchronous-unwind-tables",
]
}
config("size_default") {
cflags = [
"-fno-common",
"-ffunction-sections",
"-fdata-sections",
]
}
config("stack_protector_default") {
cflags = [ "-fno-stack-protector" ]
}
config("pic_default") {
cflags = [ "-fPIC" ]
ldflags = cflags
}
config("pie_default") {
if (current_os == "linux") {
ldflags = [ "-pie" ]
}
}
config("aliasing_default") {
cflags = [ "-fno-strict-aliasing" ]
}
config("specs_default") {
if (current_cpu == "arm" && current_os == "freertos") {
cflags = [
"--specs=nosys.specs",
"--specs=nano.specs",
]
libs = [ "nosys" ]
ldflags = cflags
}
}