summaryrefslogtreecommitdiff
path: root/llvm/utils/gn/build/BUILD.gn
blob: e5c8d2a6209561386cdb19e782f434d8cfae78b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import("//llvm/utils/gn/build/buildflags.gni")
import("//llvm/utils/gn/build/mac_sdk.gni")
import("//llvm/utils/gn/build/toolchain/compiler.gni")
import("//llvm/utils/gn/build/toolchain/target_flags.gni")

config("compiler_defaults") {
  defines = []

  if (!llvm_enable_assertions) {
    defines += [ "NDEBUG" ]
  }

  cflags = target_flags + target_cflags
  ldflags = target_flags + target_ldflags

  if (host_os == "mac" && clang_base_path != "") {
    cflags += [
      "-isysroot",
      mac_sdk_path,
    ]
  }

  if (host_os != "win") {
    if (is_debug) {
      cflags += [ "-g" ]
    } else {
      cflags += [ "-O3" ]
    }
    cflags += [ "-fdiagnostics-color" ]
    cflags_cc = [
      "-std=c++11",
      "-fno-exceptions",
      "-fvisibility-inlines-hidden",
    ]
  } else {
    if (is_debug) {
      cflags += [ "/Zi" ]
    } else {
      cflags += [
        "/O2",
        "/Zc:inline",
      ]
    }
    defines += [
      "_CRT_SECURE_NO_DEPRECATE",
      "_CRT_SECURE_NO_WARNINGS",
      "_CRT_NONSTDC_NO_DEPRECATE",
      "_CRT_NONSTDC_NO_WARNINGS",
      "_SCL_SECURE_NO_DEPRECATE",
      "_SCL_SECURE_NO_WARNINGS",

      "_HAS_EXCEPTIONS=0",
      "_UNICODE",
      "UNICODE",
    ]
    cflags += [ "/EHs-c-" ]

    # The MSVC default value (1 MB) is not enough for parsing recursive C++
    # templates in Clang.
    ldflags = [ "/STACK:10000000" ]
  }

  # Warning setup.
  if (host_os == "win" && !is_clang) {
    cflags += [
      # Suppress ''modifier' : used more than once' (__forceinline and inline).
      "-wd4141",

      # Suppress 'conversion from 'type1' to 'type2', possible loss of data'.
      "-wd4244",

      # Suppress 'conversion from 'size_t' to 'type', possible loss of data'.
      "-wd4267",

      # Suppress 'no matching operator delete found'.
      "-wd4291",

      # Suppress 'noexcept used with no exception handling mode specified'.
      "-wd4577",

      # Suppress 'destructor was implicitly defined as deleted'.
      "-wd4624",

      # Suppress 'unsafe mix of type <type> and type <type> in operation'.
      "-wd4805",
    ]
  } else {
    if (host_os == "win") {
      cflags += [ "/W4" ]
    } else {
      cflags += [
        "-Wall",
        "-Wextra",
      ]
    }
    cflags += [
      "-Wno-unused-parameter",
      "-Wstring-conversion",
    ]
    if (is_clang) {
      cflags += [ "-Wdelete-non-virtual-dtor" ]
    }
    if (is_clang && use_goma) {
      # goma converts all paths to lowercase on the server, breaking this
      # warning.
      cflags += [ "-Wno-nonportable-include-path" ]
    }
  }

  if (use_lld) {
    ldflags += [ "-fuse-ld=lld" ]
  }
}

config("no_rtti") {
  if (current_os == "win") {
    cflags_cc = [ "/GR-" ]
  } else {
    cflags_cc = [ "-fno-rtti" ]
  }
}

config("llvm_code") {
  include_dirs = [
    "//llvm/include",
    "$root_gen_dir/llvm/include",
  ]
}

config("lld_code") {
  include_dirs = [
    "//lld/include",
    "$root_gen_dir/lld/include",
  ]
}

config("clang_code") {
  include_dirs = [
    "//clang/include",
    "$root_gen_dir/clang/include",
  ]
}

config("crt_code") {
  include_dirs = [ "//compiler-rt/lib" ]
  cflags = [
    "-fPIC",
    "-funwind-tables",
    "-gline-tables-only",
  ]
}

config("warn_covered_switch_default") {
  if (is_clang) {
    cflags = [ "-Wcovered-switch-default" ]
  }
}