| # 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. |
| |
| config("compiler_flags") { |
| cflags = [] |
| cflags_c = [] |
| cflags_cc = [] |
| defines = [] |
| ldflags = [] |
| |
| if (is_debug) { |
| cflags += [ "-O0" ] |
| } else if (is_devel) { |
| cflags += [ "-O2" ] |
| } else { |
| cflags += [ "-gline-tables-only" ] |
| } |
| |
| if (is_clang) { |
| ldflags += [ "-fuse-ld=lld" ] |
| cflags += [ |
| "-Werror", |
| "-fcolor-diagnostics", |
| |
| # Warn for implicit type conversions that may change a value. |
| "-Wconversion", |
| |
| # Warns on switches on enums that cover all enum values but |
| # also contain a default: branch. Chrome is full of that. |
| "-Wno-covered-switch-default", |
| |
| # protobuf uses hash_map. |
| "-Wno-deprecated", |
| |
| # Don"t warn about the "struct foo f = {0};" initialization pattern. |
| "-Wno-missing-field-initializers", |
| |
| # Do not warn for implicit sign conversions. |
| "-Wno-sign-conversion", |
| "-fno-strict-aliasing", # See http://crbug.com/32204 |
| |
| # Triggered by the COMPILE_ASSERT macro. |
| "-Wno-unused-local-typedef", |
| |
| # Do not warn if a function or variable cannot be implicitly |
| # instantiated. |
| "-Wno-undefined-var-template", |
| |
| # Do not warn about an implicit exception spec mismatch. |
| "-Wno-implicit-exception-spec-mismatch", |
| |
| # Do not warn about unused function params. |
| "-Wno-unused-parameter", |
| ] |
| if (build_with_separate_cobalt_toolchain) { |
| # If we're building modularly, we need visibility. |
| cflags += [ "-fvisibility=default" ] |
| } else { |
| # Default visibility to hidden, to enable dead stripping. |
| cflags += [ "-fvisibility=hidden" ] |
| } |
| |
| if (is_gold) { |
| cflags += [ |
| # Don't generate an eh_frame and eh_frame_hdr section. |
| "-fno-asynchronous-unwind-tables", |
| ] |
| } |
| } |
| |
| if (is_clang_16) { |
| cflags += [ |
| # Do not warn about an implicit conversion from int to float |
| "-Wno-implicit-int-float-conversion", |
| |
| # Do not warn about an implicit conversion from int to char16 |
| "-Wno-implicit-int-conversion", |
| |
| # Do not remove null pointer checks. |
| "-fno-delete-null-pointer-checks", |
| ] |
| } |
| |
| if (!cobalt_fastbuild && (is_debug || is_devel)) { |
| cflags += [ "-g" ] |
| } |
| |
| defines += [ |
| # By default, <EGL/eglplatform.h> pulls in some X11 headers that have some |
| # nasty macros (|Status|, for example) that conflict with Chromium base. |
| "MESA_EGL_NO_X11_HEADERS", |
| ] |
| cflags_c += [ |
| # Limit to C99. This allows Linux to be a canary build for any |
| # C11 features that are not supported on some platforms' compilers. |
| "-std=c99", |
| ] |
| cflags_cc = [ "-std=gnu++14" ] |
| |
| if (use_asan) { |
| cflags += [ |
| "-fsanitize=address", |
| "-fno-omit-frame-pointer", |
| ] |
| ldflags += [ |
| "-fsanitize=address", |
| |
| # Force linking of the helpers in sanitizer_options.cc |
| "-Wl,-u_sanitizer_options_link_helper", |
| ] |
| defines += [ "ADDRESS_SANITIZER" ] |
| if (asan_symbolizer_path != "") { |
| defines += [ "ASAN_SYMBOLIZER_PATH=\"${asan_symbolizer_path}\"" ] |
| } |
| } else if (use_tsan) { |
| cflags += [ |
| "-fsanitize=thread", |
| "-fno-omit-frame-pointer", |
| ] |
| ldflags += [ "-fsanitize=thread" ] |
| defines += [ "THREAD_SANITIZER" ] |
| } |
| } |
| |
| config("platform_configuration") { |
| defines = [] |
| ldflags = [] |
| libs = [ |
| "asound", |
| "dl", |
| "pthread", |
| "rt", |
| ] |
| |
| if (!sb_is_modular) { |
| ldflags += [ "-static-libstdc++" ] |
| } |
| |
| defines += [ |
| # Defined to get format macro constants from <inttypes.h>. |
| "__STDC_FORMAT_MACROS", |
| "COBALT_LINUX", |
| |
| # Enable GNU extensions to get prototypes like ffsl. |
| "_GNU_SOURCE=1", |
| ] |
| |
| if (is_debug) { |
| defines += [ |
| "_GLIBCXX_DEBUG", |
| "_LIBCPP_DEBUG=1", |
| ] |
| configs = [ "//build/config/compiler:rtti" ] |
| } else if (is_devel) { |
| defines += [ |
| "_GLIBCXX_DEBUG", |
| "_LIBCPP_DEBUG=0", |
| ] |
| configs = [ "//build/config/compiler:rtti" ] |
| } |
| } |
| |
| config("libraries") { |
| ldflags = [ "-Wl,--wrap=eglSwapBuffers" ] |
| libs = [ |
| "X11", |
| "Xcomposite", |
| "Xrender", |
| ] |
| } |
| |
| config("speed") { |
| cflags = [ "-O2" ] |
| |
| if (is_qa || is_gold) { |
| cflags += [ |
| # Compile symbols in separate sections |
| "-ffunction-sections", |
| "-fdata-sections", |
| ] |
| } |
| } |
| |
| config("size") { |
| cflags = [ "-Os" ] |
| if (is_qa || is_gold) { |
| cflags += [ |
| # Compile symbols in separate sections |
| "-ffunction-sections", |
| "-fdata-sections", |
| ] |
| } |
| } |
| |
| config("pedantic_warnings") { |
| cflags = [ |
| "-Wall", |
| "-Wextra", |
| "-Wunreachable-code", |
| ] |
| } |
| |
| config("no_pedantic_warnings") { |
| cflags = [ |
| # 'this' pointer cannot be NULL...pointer may be assumed |
| # to always convert to true. |
| "-Wno-undefined-bool-conversion", |
| |
| # Skia doesn't use overrides. |
| "-Wno-inconsistent-missing-override", |
| |
| # Do not warn for implicit type conversions that may change a value. |
| "-Wno-conversion", |
| |
| # shifting a negative signed value is undefined |
| "-Wno-shift-negative-value", |
| |
| # Width of bit-field exceeds width of its type- value will be truncated |
| "-Wno-bitfield-width", |
| "-Wno-undefined-var-template", |
| ] |
| } |