1 import("//llvm/utils/gn/build/buildflags.gni")
2 import("//llvm/utils/gn/build/mac_sdk.gni")
3 import("//llvm/utils/gn/build/toolchain/compiler.gni")
4 import("//llvm/utils/gn/build/toolchain/target_flags.gni")
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
16 assert(!llvm_build_instrumented_coverage || is_clang,
17 "llvm_build_instrumented_coverage requires clang as host compiler")
19 config("compiler_defaults") {
22 if (!llvm_enable_assertions) {
23 defines += [ "NDEBUG" ]
26 asmflags = target_flags
28 ldflags = target_flags + target_ldflags
30 if (host_os == "mac" && clang_base_path != "") {
37 if (host_os != "win") {
44 cflags += [ "-fdiagnostics-color" ]
46 ldflags += [ "-Wl,--color-diagnostics" ]
50 "-fvisibility-inlines-hidden",
58 ldflags += [ "/DEBUG" ]
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",
82 cflags += [ "/EHs-c-" ]
84 # The MSVC default value (1 MB) is not enough for parsing recursive C++
86 ldflags += [ "/STACK:10000000" ]
90 if (host_os == "win" && !is_clang) {
92 # Suppress ''modifier' : used more than once' (__forceinline and inline).
95 # Suppress 'conversion from 'type1' to 'type2', possible loss of data'.
98 # Suppress 'conversion from 'size_t' to 'type', possible loss of data'.
101 # Suppress 'no matching operator delete found'.
104 # Suppress 'noexcept used with no exception handling mode specified'.
107 # Suppress 'destructor was implicitly defined as deleted'.
110 # Suppress 'unsafe mix of type <type> and type <type> in operation'.
114 if (host_os == "win") {
122 cflags += [ "-Wno-unused-parameter" ]
125 "-Wdelete-non-virtual-dtor",
126 "-Wstring-conversion",
130 # GCC's -Wcomment complains about // comments ending with '\' if the
131 # next line is also a // comment.
134 # Disable gcc's potentially uninitialized use analysis as it presents
135 # lots of false positives.
136 "-Wno-maybe-uninitialized",
139 # The LLVM libraries have no stable C++ API, so -Wnoexcept-type is not
141 "-Wno-noexcept-type",
144 if (is_clang && use_goma) {
145 # goma converts all paths to lowercase on the server, breaking this
147 cflags += [ "-Wno-nonportable-include-path" ]
151 # On Windows, the linker is not invoked through the compiler driver.
152 if (use_lld && host_os != "win") {
153 ldflags += [ "-fuse-ld=lld" ]
156 if (llvm_build_instrumented_coverage) {
158 "-fcoverage-mapping",
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
165 "-fprofile-instr-generate=" +
166 rebase_path("$root_build_dir/profiles/%4m.profraw"),
168 ldflags += [ "-fprofile-instr-generate" ]
172 config("no_exceptions") {
173 if (host_os != "win") {
174 cflags_cc = [ "-fno-exceptions" ]
179 if (current_os == "win") {
180 cflags_cc = [ "/GR-" ]
182 cflags_cc = [ "-fno-rtti" ]
186 # To make an archive that can be distributed, you need to remove this config and
187 # set complete_static_lib.
188 config("thin_archive") {
189 if (current_os != "win" && current_os != "mac") {
194 config("llvm_code") {
197 "$root_gen_dir/llvm/include",
204 "$root_gen_dir/lld/include",
208 config("clang_code") {
209 if (host_os != "win") {
210 cflags = [ "-fno-strict-aliasing" ]
214 "$root_gen_dir/clang/include",
219 include_dirs = [ "//compiler-rt/lib" ]
223 "-gline-tables-only",
227 config("warn_covered_switch_default") {
229 cflags = [ "-Wcovered-switch-default" ]