xref: /netbsd-src/external/apache2/llvm/dist/llvm/utils/gn/build/BUILD.gn (revision cef8759bd76c1b621f8eab8faa6f208faabc2e15)
1import("//llvm/utils/gn/build/buildflags.gni")
2import("//llvm/utils/gn/build/mac_sdk.gni")
3import("//llvm/utils/gn/build/toolchain/compiler.gni")
4import("//llvm/utils/gn/build/toolchain/target_flags.gni")
5
6declare_args() {
7  # Whether to build everything with coverage information.
8  # After building with this, run tests and then run
9  #    llvm/utils/prepare-code-coverage-artifact.py  \
10  #        .../llvm-profdata .../llvm-cov out/gn/profiles/ report/ \
11  #        out/gn/bin/llvm-undname ...`
12  # to generate a HTML report for the binaries passed in the last line.
13  llvm_build_instrumented_coverage = false
14}
15
16assert(!llvm_build_instrumented_coverage || is_clang,
17       "llvm_build_instrumented_coverage requires clang as host compiler")
18
19config("compiler_defaults") {
20  defines = []
21
22  if (!llvm_enable_assertions) {
23    defines += [ "NDEBUG" ]
24  }
25
26  asmflags = target_flags
27  cflags = target_flags
28  ldflags = target_flags + target_ldflags
29
30  if (host_os == "mac" && clang_base_path != "") {
31    cflags += [
32      "-isysroot",
33      mac_sdk_path,
34    ]
35  }
36
37  if (host_os != "win") {
38    if (is_debug) {
39      cflags += [ "-g" ]
40    }
41    if (is_optimized) {
42      cflags += [ "-O3" ]
43    }
44    cflags += [ "-fdiagnostics-color" ]
45    if (use_lld) {
46      ldflags += [ "-Wl,--color-diagnostics" ]
47    }
48    cflags_cc = [
49      "-std=c++14",
50      "-fvisibility-inlines-hidden",
51    ]
52  } else {
53    if (is_debug) {
54      cflags += [
55        "/Zi",
56        "/FS",
57      ]
58      ldflags += [ "/DEBUG" ]
59    }
60    if (is_optimized) {
61      cflags += [
62        "/O2",
63        "/Zc:inline",
64      ]
65      ldflags += [
66        "/OPT:REF",
67        "/OPT:ICF",
68      ]
69    }
70    defines += [
71      "_CRT_SECURE_NO_DEPRECATE",
72      "_CRT_SECURE_NO_WARNINGS",
73      "_CRT_NONSTDC_NO_DEPRECATE",
74      "_CRT_NONSTDC_NO_WARNINGS",
75      "_SCL_SECURE_NO_DEPRECATE",
76      "_SCL_SECURE_NO_WARNINGS",
77
78      "_HAS_EXCEPTIONS=0",
79      "_UNICODE",
80      "UNICODE",
81    ]
82    cflags += [ "/EHs-c-" ]
83
84    # The MSVC default value (1 MB) is not enough for parsing recursive C++
85    # templates in Clang.
86    ldflags += [ "/STACK:10000000" ]
87  }
88
89  # Warning setup.
90  if (host_os == "win" && !is_clang) {
91    cflags += [
92      # Suppress ''modifier' : used more than once' (__forceinline and inline).
93      "-wd4141",
94
95      # Suppress 'conversion from 'type1' to 'type2', possible loss of data'.
96      "-wd4244",
97
98      # Suppress 'conversion from 'size_t' to 'type', possible loss of data'.
99      "-wd4267",
100
101      # Suppress 'no matching operator delete found'.
102      "-wd4291",
103
104      # Suppress 'noexcept used with no exception handling mode specified'.
105      "-wd4577",
106
107      # Suppress 'destructor was implicitly defined as deleted'.
108      "-wd4624",
109
110      # Suppress 'unsafe mix of type <type> and type <type> in operation'.
111      "-wd4805",
112    ]
113  } else {
114    if (host_os == "win") {
115      cflags += [ "/W4" ]
116    } else {
117      cflags += [
118        "-Wall",
119        "-Wextra",
120      ]
121    }
122    cflags += [ "-Wno-unused-parameter" ]
123    if (is_clang) {
124      cflags += [
125        "-Wdelete-non-virtual-dtor",
126        "-Wstring-conversion",
127      ]
128    } else {
129      cflags += [
130        # GCC's -Wcomment complains about // comments ending with '\' if the
131        # next line is also a // comment.
132        "-Wno-comment",
133
134        # Disable gcc's potentially uninitialized use analysis as it presents
135        # lots of false positives.
136        "-Wno-maybe-uninitialized",
137      ]
138      cflags_cc += [
139        # The LLVM libraries have no stable C++ API, so -Wnoexcept-type is not
140        # useful.
141        "-Wno-noexcept-type",
142      ]
143    }
144    if (is_clang && use_goma) {
145      # goma converts all paths to lowercase on the server, breaking this
146      # warning.
147      cflags += [ "-Wno-nonportable-include-path" ]
148    }
149  }
150
151  # On Windows, the linker is not invoked through the compiler driver.
152  if (use_lld && host_os != "win") {
153    ldflags += [ "-fuse-ld=lld" ]
154  }
155
156  if (llvm_build_instrumented_coverage) {
157    cflags += [
158      "-fcoverage-mapping",
159
160      # Using an absolute path here is lame, but it's used at test execution
161      # time to generate the profiles, and lit doesn't specify a fixed folder
162      # for test execution -- so this is the only way to get all profiles into
163      # a single folder like llvm/utils/prepare-code-coverage-artifact.py
164      # expects.
165      "-fprofile-instr-generate=" +
166          rebase_path("$root_build_dir/profiles/%4m.profraw"),
167    ]
168    ldflags += [ "-fprofile-instr-generate" ]
169  }
170}
171
172config("no_exceptions") {
173  if (host_os != "win") {
174    cflags_cc = [ "-fno-exceptions" ]
175  }
176}
177
178config("no_rtti") {
179  if (current_os == "win") {
180    cflags_cc = [ "/GR-" ]
181  } else {
182    cflags_cc = [ "-fno-rtti" ]
183  }
184}
185
186# To make an archive that can be distributed, you need to remove this config and
187# set complete_static_lib.
188config("thin_archive") {
189  if (current_os != "win" && current_os != "mac") {
190    arflags = [ "-T" ]
191  }
192}
193
194config("llvm_code") {
195  include_dirs = [
196    "//llvm/include",
197    "$root_gen_dir/llvm/include",
198  ]
199}
200
201config("lld_code") {
202  include_dirs = [
203    "//lld/include",
204    "$root_gen_dir/lld/include",
205  ]
206}
207
208config("clang_code") {
209  if (host_os != "win") {
210    cflags = [ "-fno-strict-aliasing" ]
211  }
212  include_dirs = [
213    "//clang/include",
214    "$root_gen_dir/clang/include",
215  ]
216}
217
218config("crt_code") {
219  include_dirs = [ "//compiler-rt/lib" ]
220  cflags = [
221    "-fPIC",
222    "-funwind-tables",
223    "-gline-tables-only",
224    "-fvisibility=hidden",
225  ]
226}
227
228config("warn_covered_switch_default") {
229  if (is_clang) {
230    cflags = [ "-Wcovered-switch-default" ]
231  }
232}
233