Home | History | Annotate | Download | only in compiler
      1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 # Base compiler configuration.
      6 config("compiler") {
      7   includes = [ "//" ]
      8   if (is_win) {
      9     cflags = [
     10       # TODO(brettw) these probably need to be refactored.
     11       "/Od", "/WX", "/Zi", "/Gy", "/GS", "/RTC1", "/EHsc",
     12     ]
     13   } else {
     14     cflags = [
     15       # TODO(brettw) obviously this needs to be parameterized.
     16       "-arch i386",
     17 
     18       # See http://crbug.com/32204
     19       "-fno-strict-aliasing",
     20 
     21       "-fno-threadsafe-statics",
     22       "-fstack-protector-all",
     23       "-fvisibility=hidden",
     24       "-fvisibility-inlines-hidden",
     25     ]
     26     # !!! Please keep additions sorted alphabetically.
     27 
     28     # TODO(brettw) these should be clang-only.
     29     # if (is_clang) {
     30       cflags += [
     31         "-fcolor-diagnostics",
     32       ]
     33     #}
     34 
     35     cflags_c = [
     36       "-std=c99",
     37     ]
     38 
     39     cflags_cc = [
     40       "-fno-exceptions",
     41       "-std=gnu++11",
     42     ]
     43   }
     44 
     45   if (is_mac) {
     46     # These are used for both compiler and linker flags on Mac.
     47     common_mac_flags = [
     48       # TODO(brettw) obviously this needs to be parameterized.
     49       "-arch i386",
     50 
     51       # Set which SDK to use.
     52       # TODO(brettw) this needs to be configurable somehow.
     53       "-isysroot", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk",
     54 
     55       "-mmacosx-version-min=10.6",
     56     ]
     57 
     58     # Mac compiler flags.
     59     cflags += [
     60       # Without this, the constructors and destructors of a C++ object inside
     61       # an Objective C struct won't be called, which is very bad.
     62       "-fobjc-call-cxx-cdtors",
     63     ]
     64     cflags += common_mac_flags
     65 
     66     # Mac linker flags.
     67     ldflags = [
     68       "-L.",
     69 
     70       # TODO(brettW) I don't understand these options.
     71       "-Wl,-rpath,@loader_path/.",
     72       "-Wl,-rpath,@loader_path/../../..",
     73     ]
     74     ldflags += common_mac_flags
     75   }
     76 }
     77 
     78 # runtime_library -------------------------------------------------------------
     79 #
     80 # Sets the runtime library and associated options.
     81 #
     82 # We don't bother making multiple versions that are toggle-able since there
     83 # is more than one axis of control (which makes it complicated) and there's
     84 # no practical reason for anybody to change this since the CRT must agree.
     85 
     86 config("runtime_library") {
     87   if (is_component_build) {
     88     # Component mode: dynamic CRT.
     89     defines = [ "COMPONENT_BUILD" ]
     90     if (is_win) {
     91       # Since the library is shared, it requires exceptions or will give errors
     92       # about things not matching, so keep exceptions on.
     93       if (is_debug) {
     94         cflags = [ "/MDd" ]
     95       } else {
     96         cflags = [ "/MD" ]
     97       }
     98     }
     99   } else {
    100     # Static CRT.
    101     if (is_win) {
    102       # We don't use exceptions, and when we link statically we can just get
    103       # rid of them entirely.
    104       defines = [ "_HAS_EXCEPTIONS=0" ]
    105       if (is_debug) {
    106         cflags = [ "/MTd" ]
    107       } else {
    108         cflags = [ "/MT" ]
    109       }
    110     }
    111   }
    112 
    113   if (is_win) {
    114     defines += [
    115       "__STD_C",
    116       "__STDC_CONSTANT_MACROS",
    117       "__STDC_FORMAT_MACROS",
    118       "_CRT_RAND_S",
    119       "_CRT_SECURE_NO_DEPRECATE",
    120       "_SCL_SECURE_NO_DEPRECATE",
    121       "_UNICODE",
    122       "UNICODE",
    123     ]
    124   }
    125 }
    126 
    127 # chromium_code ---------------------------------------------------------------
    128 #
    129 # Toggles between higher and lower warnings for code that is (or isn't)
    130 # part of Chromium.
    131 
    132 config("chromium_code") {
    133   if (is_win) {
    134     cflags = [
    135       "/W4",  # Warning level 4.
    136     ]
    137   } else if (is_mac) {
    138     cflags = [
    139       "-Wall",
    140       "-Werror",
    141       "-Wextra",
    142     ]
    143   }
    144 }
    145 config("no_chromium_code") {
    146   if (is_win) {
    147     cflags = [
    148       "/W3",  # Warning level 3.
    149       "/wd4800",  # Disable warning when forcing value to bool.
    150     ]
    151     defines = [
    152       "_CRT_NONSTDC_NO_WARNINGS",
    153       "_CRT_NONSTDC_NO_DEPRECATE",
    154     ]
    155   }
    156 }
    157 
    158 # rtti ------------------------------------------------------------------------
    159 #
    160 # Allows turning Run-Time Type Identification on or off.
    161 
    162 config("rtti") {
    163   if (is_win) {
    164     cflags_cc = [ "/GR" ]
    165   }
    166 }
    167 config("no_rtti") {
    168   if (is_win) {
    169     cflags_cc = [ "/GR-" ]
    170   } else {
    171     cflags_cc = [ "-fno-rtti" ]
    172   }
    173 }
    174 
    175 # Warnings ---------------------------------------------------------------------
    176 
    177 config("default_warnings") {
    178   if (is_win) {
    179     # Please keep ordered and add names if you add more.
    180     cflags = [
    181       "/wd4018",  # Comparing signed and unsigned values.
    182       "/wd4100",  # Unreferenced formal function parameter.
    183       "/wd4121",  # Alignment of a member was sensitive to packing.
    184       "/wd4125",  # Decimal digit terminates octal escape sequence.
    185       "/wd4127",  # Conditional expression is constant.
    186       "/wd4130",  # Logical operation on address of string constant.
    187       # TODO(brettw) is this necessary? If so, it should probably be on whoever
    188       # is silly enough to be doing this rather than globally.
    189       #"/wd4131",  # Function uses old-style declarator.
    190       "/wd4189",  # A variable was declared and initialized but never used.
    191       "/wd4201",  # Nonstandard extension used: nameless struct/union.
    192       "/wd4238",  # Nonstandard extension used: class rvalue used as lvalue.
    193       "/wd4244",  # Conversion: possible loss of data.
    194       "/wd4245",  # Conversion: signed/unsigned mismatch,
    195       "/wd4251",  # Class needs to have dll-interface.
    196       "/wd4310",  # Cast truncates constant value.
    197       "/wd4351",  # Elements of array will be default initialized.
    198       "/wd4355",  # 'this' used in base member initializer list.
    199       "/wd4396",  # Inline friend template thing.
    200       "/wd4428",  # Universal character name encountered in source.
    201       "/wd4481",  # Nonstandard extension: override specifier.
    202       "/wd4503",  # Decorated name length exceeded, name was truncated.
    203       "/wd4505",  # Unreferenced local function has been removed.
    204       "/wd4510",  # Default constructor could not be generated.
    205       "/wd4512",  # Assignment operator could not be generated.
    206       "/wd4530",  # Exception handler used, but unwind semantics not enabled.
    207       "/wd4610",  # Class can never be instantiated, constructor required.
    208       "/wd4611",  # C++ object destruction and 'catch'.
    209       "/wd4701",  # Potentially uninitialized local variable name used.
    210       "/wd4702",  # Unreachable code.
    211       "/wd4706",  # Assignment within conditional expression.
    212       "/wd4819",  # Character not in the current code page.
    213     ]
    214   }
    215 
    216   # TODO(brettw) this should probably be if(clang).
    217   if (is_mac) {
    218     cflags = [
    219       # Warn for weird old-style text after an #endif.
    220       "-Wendif-labels",
    221 
    222       "-Wnewline-eof",
    223 
    224       # Don't warn about the "struct foo f = {0};" initialization pattern.
    225       "-Wno-missing-field-initializers",
    226 
    227       # Don't warn about unused function parameters.
    228       "-Wno-unused-parameter",
    229     ]
    230 
    231     # TODO(brettw) Ones below here should be clang-only when we have a flag
    232     # for it.
    233     #if (is_clang) {
    234       cflags += [
    235         "-Wheader-hygiene",
    236 
    237         # This warns on using ints as initializers for floats in
    238         # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|),
    239         # which happens in several places in chrome code. Not sure if
    240         # this is worth fixing.
    241         "-Wno-c++11-narrowing",
    242 
    243         # Don't die on dtoa code that uses a char as an array index.
    244         # This is required solely for base/third_party/dmg_fp/dtoa.cc.
    245         # TODO(brettw) move this to that project then!
    246         "-Wno-char-subscripts",
    247 
    248         # Warns on switches on enums that cover all enum values but
    249         # also contain a default: branch. Chrome is full of that.
    250         "-Wno-covered-switch-default",
    251 
    252         # Clang considers the `register` keyword as deprecated, but e.g.
    253         # code generated by flex (used in angle) contains that keyword.
    254         # http://crbug.com/255186
    255         "-Wno-deprecated-register",
    256 
    257         # Clang spots more unused functions.
    258         "-Wno-unused-function",
    259 
    260         # Warns when a const char[] is converted to bool.
    261         "-Wstring-conversion",
    262       ]
    263     #}  #is_clang
    264   }
    265 }
    266