| # 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 = [ "USE_COBALT_CUSTOMIZATIONS" ] |
| |
| 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", |
| "COBALT_FORCE_CORS", |
| ] |
| } |
| |
| 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 += [ "-latomic" ] |
| |
| if (is_clang) { |
| ldflags += [ |
| "-target", |
| "i386-unknown-linux-gnu", |
| ] |
| } else { |
| ldflags += [ "-m32" ] |
| } |
| } |
| } 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") { |
| if (!sb_is_modular || sb_is_evergreen) { |
| # 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. |
| # For windows based platforms this flag causes a linker error while building with cobalt toolchain |
| if (!(host_os == "win" && sb_is_modular && |
| current_toolchain == cobalt_toolchain)) { |
| cflags = [ "-fPIC" ] |
| } |
| } |
| |
| if (is_starboard) { |
| configs = [ ":starboard" ] |
| } else if (is_native_target_build) { |
| configs = [ ":native_target_build" ] |
| } |
| } |
| } |
| |
| # TODO(b/212641065): Scope global defines migrated from |
| # cobalt_configuration.gypi to only the targets they're necessary in. |
| config("starboard") { |
| if (is_starboardized_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 (is_internal_build) { |
| defines += [ "INTERNAL_BUILD" ] |
| } |
| |
| if (sb_enable_lib) { |
| defines += [ "SB_IS_LIBRARY=1" ] |
| } |
| |
| if (sb_is_modular) { |
| defines += [ "SB_IS_MODULAR=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" ] |
| } |
| |
| defines += [ |
| "STARBOARD_ATOMIC_INCLUDE=\"$starboard_path/atomic_public.h\"", |
| "STARBOARD_CONFIGURATION_INCLUDE=\"$starboard_path/configuration_public.h\"", |
| ] |
| } |
| } |
| |
| config("native_target_build") { |
| defines = [ "NATIVE_TARGET_BUILD" ] |
| } |
| |
| config("starboard_implementation") { |
| # This allows the benchmarks to include internal only header files. |
| defines = [ "STARBOARD_IMPLEMENTATION" ] |
| } |
| |
| config("speed") { |
| if (is_starboardized_toolchain) { |
| if (defined(speed_config_path)) { |
| configs = [ speed_config_path ] |
| } |
| } |
| } |
| |
| config("size") { |
| if (is_starboardized_toolchain) { |
| if (defined(size_config_path)) { |
| configs = [ size_config_path ] |
| } |
| } |
| } |
| |
| config("pedantic_warnings") { |
| if (is_starboardized_toolchain) { |
| if (defined(pedantic_warnings_config_path)) { |
| configs = [ pedantic_warnings_config_path ] |
| } |
| } |
| } |
| |
| config("no_pedantic_warnings") { |
| if (is_starboardized_toolchain || |
| current_toolchain == "//$starboard_path/toolchain:native_target") { |
| 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 (is_starboardized_toolchain && sb_is_modular && |
| current_toolchain == cobalt_toolchain && target_cpu == "arm") { |
| cflags = [ "-mfpu=vfpv3" ] |
| asmflags = cflags |
| } |
| } |