blob: aa06b1d6db130390cb1743f71b011e6c5af2def0 [file] [log] [blame]
# Copyright 2021 The Cobalt Authors. All Rights Reserved.
#
# 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/config/compiler/compiler.gni")
config("base") {
defines = []
if (is_debug) {
defines += [
"STARBOARD_BUILD_TYPE_DEBUG",
"COBALT_BUILD_TYPE_DEBUG",
"_DEBUG",
"COBALT_LOGGING_ENABLED",
]
}
if (is_devel) {
defines += [
"STARBOARD_BUILD_TYPE_DEVEL",
"COBALT_BUILD_TYPE_DEVEL",
"_DEBUG",
"COBALT_LOGGING_ENABLED",
]
}
if (is_qa) {
defines += [
"STARBOARD_BUILD_TYPE_QA",
"COBALT_BUILD_TYPE_QA",
"NDEBUG",
]
}
if (is_gold) {
defines += [
"STARBOARD_BUILD_TYPE_GOLD",
"COBALT_BUILD_TYPE_GOLD",
"NDEBUG",
"OFFICIAL_BUILD",
"TRACING_DISABLED",
"COBALT_FORCE_CSP",
]
}
if (enable_in_app_dial) {
defines += [ "DIAL_SERVER" ]
}
}
config("host") {
if (current_toolchain == host_toolchain) {
if (is_linux) {
ldflags = [ "-pthread" ]
cflags_cc = [ "-std=gnu++14" ]
if (target_cpu == "arm" || target_cpu == "x86") {
cflags = [ "-m32" ]
ldflags += [
"-target",
"i386-unknown-linux-gnu",
"-latomic",
]
}
} else if (is_win) {
# A few flags to mute MSVC compiler errors that does not appear on Linux.
cflags = [
"/wd4267", # Possible loss of precision from size_t to a smaller type.
"/wd4715", # Not all control paths return value.
]
}
}
}
config("target") {
if (current_toolchain != host_toolchain) {
if (final_executable_type == "shared_library") {
# Rewrite main() functions into StarboardMain. TODO: This is a
# hack, it would be better to be more surgical, here.
defines = [ "main=StarboardMain" ]
# To link into a shared library on Linux and similar platforms,
# the compiler must be told to generate Position Independent Code.
# This appears to cause errors when linking the code statically,
# however.
cflags = [ "-fPIC" ]
}
if (is_starboard) {
configs = [ ":starboard" ]
}
}
}
# TODO(b/212641065): Scope global defines migrated from
# cobalt_configuration.gypi to only the targets they're necessary in.
config("starboard") {
if (current_toolchain == default_toolchain) {
defines = [
"STARBOARD",
"COBALT", # TODO: See if this can be replaced by STARBOARD macro.
]
if (gl_type == "none") {
defines += [ "SB_GN_GL_TYPE_IS_NONE=1" ]
} else {
defines += [ "SB_GN_GL_TYPE_IS_NONE=0" ]
}
if (!is_gold) {
defines += [
"ENABLE_DEBUGGER",
"ENABLE_DEBUG_COMMAND_LINE_SWITCHES",
"ENABLE_TEST_RUNNER",
"ENABLE_IGNORE_CERTIFICATE_ERRORS",
]
}
if (abort_on_allocation_failure) {
defines += [ "SB_ABORT_ON_ALLOCATION_FAILURE" ]
}
if (sb_allows_memory_tracking) {
defines += [ "STARBOARD_ALLOWS_MEMORY_TRACKING" ]
}
if (sb_enable_lib) {
defines += [ "SB_IS_LIBRARY=1" ]
}
if (sb_is_evergreen) {
defines += [ "SB_IS_EVERGREEN=1" ]
}
if (sb_is_evergreen_compatible) {
defines += [ "SB_IS_EVERGREEN_COMPATIBLE=1" ]
}
if (sb_evergreen_compatible_use_libunwind) {
defines += [ "SB_IS_EVERGREEN_COMPATIBLE_LIBUNWIND=1" ]
}
if (sb_evergreen_compatible_enable_lite) {
defines += [ "SB_IS_EVERGREEN_COMPATIBLE_LITE=1" ]
}
defines += [
"STARBOARD_ATOMIC_INCLUDE=\"$starboard_path/atomic_public.h\"",
"STARBOARD_CONFIGURATION_INCLUDE=\"$starboard_path/configuration_public.h\"",
]
}
}
config("starboard_implementation") {
# This allows the benchmarks to include internal only header files.
defines = [ "STARBOARD_IMPLEMENTATION" ]
}
config("speed") {
if (current_toolchain == default_toolchain) {
if (defined(speed_config_path)) {
configs = [ speed_config_path ]
}
}
}
config("size") {
if (current_toolchain == default_toolchain) {
if (defined(size_config_path)) {
configs = [ size_config_path ]
}
}
}
config("pedantic_warnings") {
if (current_toolchain == default_toolchain) {
if (defined(pedantic_warnings_config_path)) {
configs = [ pedantic_warnings_config_path ]
}
}
}
config("no_pedantic_warnings") {
if (current_toolchain == default_toolchain) {
if (defined(no_pedantic_warnings_config_path)) {
configs = [ no_pedantic_warnings_config_path ]
}
}
}
config("warnings_as_errors") {
if (is_win && treat_warnings_as_errors) {
cflags = [ "/WX" ]
}
}
# This config is defined here and added as a default config so that the flags
# specified in it can be overridden by targets. It's not possible for targets to
# override flags specified in a platform's "platform_configuration" config,
# which is where these particular flags would otherwise naturally fit.
config("default_compiler_flags") {
if (current_toolchain == default_toolchain && sb_is_evergreen &&
target_cpu == "arm") {
cflags = [ "-mfpu=vfpv3" ]
asmflags = cflags
}
}