1 import("//clang/lib/ARCMigrate/enable.gni")
2 import("//clang/lib/StaticAnalyzer/Frontend/enable.gni")
3 import("//llvm/lib/Target/targets.gni")
4 import("//llvm/triples.gni")
5 import("//llvm/utils/gn/build/libs/pthread/enable.gni")
6 import("//llvm/utils/gn/build/libs/zlib/enable.gni")
7 import("//llvm/utils/gn/build/write_cmake_config.gni")
8 import("clang_lit_site_cfg_files.gni")
10 template("write_lit_config") {
11 write_cmake_config(target_name) {
13 output = invoker.output
15 "LIT_SITE_CFG_IN_HEADER=## Autogenerated from $input, do not edit",
17 rebase_path(get_label_info("//clang", "target_out_dir")),
18 "CLANG_SOURCE_DIR=" + rebase_path("//clang"),
21 rebase_path(get_label_info("//llvm", "target_out_dir")),
22 "LLVM_LIBS_DIR=", # needed only for shared builds
23 "LLVM_SOURCE_DIR=" + rebase_path("//llvm"),
24 "LLVM_TOOLS_DIR=" + rebase_path("$root_out_dir/bin"),
25 "TARGET_TRIPLE=$llvm_target_triple",
27 if (host_os == "win") {
28 # See comment for Windows solink in llvm/utils/gn/build/toolchain/BUILD.gn
29 values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/bin") ]
31 values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/lib") ]
33 values += invoker.extra_values
37 write_lit_config("lit_site_cfg") {
38 # Fully-qualified instead of relative for LIT_SITE_CFG_IN_HEADER.
39 input = "//clang/test/lit.site.cfg.py.in"
40 output = clang_lit_site_cfg_file
43 "LLVM_WITH_Z3=", # Must be empty, not 0.
44 "CLANG_BUILD_EXAMPLES=0",
45 "CLANG_DEFAULT_CXX_STDLIB=", # Empty string means "default value" here.
46 "CLANG_TOOLS_DIR=" + rebase_path("$root_out_dir/bin"),
48 # This is only used if LLVM_USE_SANITIZER includes lsan and the host
49 # OS is macOS. Since the GN build currently never uses LLVM_USE_SANITIZER,
50 # this is never read. If it's ever needed,
51 # utils/gn/build/toolchain/BUILD.gn should get the compiler from a variable
52 # that's also read here -- but that should happen after multi-toolchain
53 # builds exist, to make sure it's a toolchain var.
54 "CMAKE_CXX_COMPILER=c++",
55 "ENABLE_BACKTRACES=1",
56 "ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER=0",
57 "LLVM_HOST_TRIPLE=$llvm_current_triple",
58 "LLVM_LIT_TOOLS_DIR=", # Intentionally empty, matches cmake build.
59 "LLVM_USE_SANITIZER=",
60 "PYTHON_EXECUTABLE=$python_path",
64 if (clang_enable_arcmt) {
65 extra_values += [ "CLANG_ENABLE_ARCMT=1" ]
67 extra_values += [ "CLANG_ENABLE_ARCMT=0" ]
70 if (clang_enable_static_analyzer) {
71 extra_values += [ "CLANG_ENABLE_STATIC_ANALYZER=1" ]
73 extra_values += [ "CLANG_ENABLE_STATIC_ANALYZER=0" ]
76 if (llvm_enable_zlib) {
77 extra_values += [ "HAVE_LIBZ=1" ]
79 extra_values += [ "HAVE_LIBZ=0" ] # Must be 0.
82 if (host_cpu == "x64") {
83 extra_values += [ "HOST_ARCH=x86_64" ]
84 } else if (host_cpu == "ppc64") {
85 extra_values += [ "HOST_ARCH=powerpc64le" ]
87 assert(false, "unimplemented host_cpu " + host_cpu)
90 if (host_os == "mac") {
91 extra_values += [ "LLVM_PLUGIN_EXT=.dylib" ]
92 } else if (host_os == "win") {
93 extra_values += [ "LLVM_PLUGIN_EXT=.dll" ]
95 extra_values += [ "LLVM_PLUGIN_EXT=.so" ]
98 if (host_os == "win") {
99 extra_values += [ "LLVM_ENABLE_PLUGINS=0" ]
101 # FIXME: Analysis/plugins need global -fPIC
102 extra_values += [ "LLVM_ENABLE_PLUGINS=0" ]
105 if (llvm_enable_threads) {
106 extra_values += [ "LLVM_ENABLE_THREADS=1" ]
108 extra_values += [ "LLVM_ENABLE_THREADS=0" ] # Must be 0.
112 write_lit_config("lit_unit_site_cfg") {
113 # Fully-qualified instead of relative for LIT_SITE_CFG_IN_HEADER.
114 input = "//clang/test/Unit/lit.site.cfg.py.in"
115 output = clang_lit_unit_site_cfg_file
116 extra_values = [ "LLVM_BUILD_MODE=." ]
119 # This target should contain all dependencies of check-clang.
120 # //:default depends on it, so that ninja's default target builds all
121 # prerequisites for check-clang but doesn't run check-clang itself.
125 ":lit_unit_site_cfg",
126 "//clang/lib/Headers",
127 "//clang/tools/c-index-test",
128 "//clang/tools/clang-diff",
129 "//clang/tools/clang-format",
130 "//clang/tools/clang-import-test",
131 "//clang/tools/clang-offload-bundler",
132 "//clang/tools/clang-refactor",
133 "//clang/tools/clang-rename",
134 "//clang/tools/clang-scan-deps",
135 "//clang/tools/diagtool",
136 "//clang/tools/driver:symlinks",
138 "//clang/utils/TableGen:clang-tblgen",
139 "//clang/utils/hmaptool",
141 "//llvm/tools/llvm-as",
142 "//llvm/tools/llvm-bcanalyzer",
143 "//llvm/tools/llvm-cat",
144 "//llvm/tools/llvm-config",
145 "//llvm/tools/llvm-dis",
146 "//llvm/tools/llvm-dwarfdump",
147 "//llvm/tools/llvm-ifs",
148 "//llvm/tools/llvm-lto",
149 "//llvm/tools/llvm-lto2",
150 "//llvm/tools/llvm-modextract",
151 "//llvm/tools/llvm-nm:symlinks",
152 "//llvm/tools/llvm-objdump:symlinks",
153 "//llvm/tools/llvm-profdata",
154 "//llvm/tools/llvm-readobj:symlinks",
155 "//llvm/tools/llvm-symbolizer:symlinks",
157 "//llvm/utils/FileCheck",
158 "//llvm/utils/count",
159 "//llvm/utils/llvm-lit",
162 if (clang_enable_arcmt) {
164 "//clang/tools/arcmt-test",
165 "//clang/tools/c-arcmt-test",
168 if (clang_enable_static_analyzer) {
170 "//clang/tools/clang-check",
171 "//clang/tools/clang-extdef-mapping",
175 # FIXME: clang_build_examples
179 action("check-clang") {
180 script = "$root_out_dir/bin/llvm-lit"
181 if (host_os == "win") {
187 "clang_site_config=" + rebase_path(clang_lit_site_cfg_file, root_out_dir),
189 "clang_unit_site_config=" +
190 rebase_path(clang_lit_unit_site_cfg_file, root_out_dir),
191 rebase_path(".", root_out_dir),
194 "$target_gen_dir/run-lit", # Non-existing, so that ninja runs it each time.
197 # Since check-clang is always dirty, //:default doesn't depend on it so that
198 # it's not part of the default ninja target. Hence, check-clang shouldn't
199 # have any deps except :test. so that the default target is sure to build