1 import("//clang/runtimes.gni")
2 import("//llvm/utils/gn/build/symlink_or_copy.gni")
5 # Build libc++ with definitions for operator new/delete.
6 libcxx_enable_new_delete_definitions = true
8 # Build libc++ as a shared library.
9 libcxx_enable_shared = true
11 # Build libc++ as a static library.
12 libcxx_enable_static = true
14 # Build filesystem as part of libc++fs.a.
15 libcxx_enable_filesystem = target_os != "win"
17 # Build libc++experimental.a.
18 libcxx_enable_experimental = true
20 # Use compiler-rt builtins.
21 libcxx_use_compiler_rt = true
24 libcxx_enable_exceptions = true
26 # Use run time type information.
27 libcxx_enable_rtti = true
29 # Do not export any symbols from the static library.
30 libcxx_hermetic_static_library = true
32 # Use and install a linker script for the given ABI library.
33 libcxx_enable_abi_linker_script = true
36 config("cxx_config") {
38 "//libcxxabi/include",
46 "-Wno-unused-parameter",
48 "-Werror=return-type",
50 "-Wno-user-defined-literals",
51 "-Wno-covered-switch-default",
53 cflags_cc = [ "-nostdinc++" ]
54 if (target_os == "win") {
55 cflags_cc += [ "/std:c++11" ]
57 cflags_cc += [ "-std=c++11" ]
59 defines = [ "_LIBCPP_BUILDING_LIBRARY" ]
60 if (target_os == "win") {
63 # Ignore the -MSC_VER mismatch, as we may build
64 # with a different compatibility version.
65 "_ALLOW_MSC_VER_MISMATCH",
67 # Don't check the msvcprt iterator debug levels
68 # as we will define the iterator types; libc++
69 # uses a different macro to identify the debug
71 "_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH",
73 # We are building the c++ runtime, don't pull in
77 # Don't warn on the use of "deprecated"
78 # "insecure" functions which are standards
80 "_CRT_SECURE_NO_WARNINGS",
82 # Use the ISO conforming behaviour for conversion
84 "_CRT_STDIO_ISO_WIDE_SPECIFIERS",
87 if (!libcxx_enable_new_delete_definitions) {
88 defines += [ "_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS" ]
90 if (libcxx_enable_exceptions) {
91 if (current_os == "win") {
92 cflags_cc += [ "/EHsc" ]
95 if (current_os == "win") {
101 cflags_cc += [ "-fno-exceptions" ]
103 defines += [ "_LIBCPP_NO_EXCEPTIONS" ]
105 if (!libcxx_enable_rtti) {
106 if (current_os == "win") {
107 cflags_cc += [ "/GR-" ]
109 cflags_cc += [ "-fno-rtti" ]
111 defines += [ "_LIBCPP_NO_RTTI" ]
121 "condition_variable.cpp",
122 "condition_variable_destructor.cpp",
128 "include/apple_availability.h",
129 "include/atomic_support.h",
130 "include/config_elast.h",
131 "include/refstring.h",
137 "mutex_destructor.cpp",
146 "support/runtime/exception_fallback.ipp",
147 "support/runtime/exception_glibcxx.ipp",
148 "support/runtime/exception_libcxxabi.ipp",
149 "support/runtime/exception_libcxxrt.ipp",
150 "support/runtime/exception_msvc.ipp",
151 "support/runtime/exception_pointer_cxxabi.ipp",
152 "support/runtime/exception_pointer_glibcxx.ipp",
153 "support/runtime/exception_pointer_msvc.ipp",
154 "support/runtime/exception_pointer_unimplemented.ipp",
155 "support/runtime/new_handler_fallback.ipp",
156 "support/runtime/stdexcept_default.ipp",
157 "support/runtime/stdexcept_vcruntime.ipp",
166 if (target_os == "win") {
168 "support/win32/locale_win32.cpp",
169 "support/win32/support.cpp",
170 "support/win32/thread_win32.cpp",
173 if (target_os == "solaris") {
175 # This comment prevents `gn format` from putting the file on the same line
176 # as `sources +=`, for sync_source_lists_from_cmake.py.
177 "support/solaris/xlocale.cpp",
180 if (libcxx_enable_filesystem) {
182 "filesystem/directory_iterator.cpp",
183 "filesystem/filesystem_common.h",
184 "filesystem/operations.cpp",
186 if (libcxx_use_compiler_rt) {
188 # This comment prevents `gn format` from putting the file on the same line
189 # as `sources +=`, for sync_source_lists_from_cmake.py.
190 "filesystem/int128_builtins.cpp",
195 if (libcxx_enable_shared) {
196 shared_library("cxx_shared") {
197 output_dir = runtimes_dir
199 if (libcxx_enable_abi_linker_script) {
200 output_extension = "so.0"
202 if (target_os == "linux" || target_os == "mac") {
204 ldflags = [ "-nostdlib++" ]
210 sources = cxx_sources
212 "//compiler-rt/lib/builtins",
213 "//libcxxabi/src:cxxabi_shared",
214 "//libunwind/src:unwind_shared",
216 configs += [ ":cxx_config" ]
218 "//llvm/utils/gn/build:no_exceptions",
219 "//llvm/utils/gn/build:no_rtti",
223 symlink_or_copy("cxx_symlink") {
227 source = "libc++.so.0"
228 output = "$runtimes_dir/libc++.so"
231 if (libcxx_enable_abi_linker_script) {
232 action("cxx_linker_script") {
233 script = "//llvm/utils/gn/secondary/libcxx/utils/gen_link_script.py"
235 "$runtimes_dir/libc++.so",
239 rebase_path("$runtimes_dir/libc++.so.0", root_build_dir),
241 rebase_path("$runtimes_dir/libc++.so", root_build_dir),
252 if (libcxx_enable_static) {
253 static_library("cxx_static") {
254 output_dir = runtimes_dir
256 complete_static_lib = true
257 configs -= [ "//llvm/utils/gn/build:thin_archive" ]
258 sources = cxx_sources
259 if (libcxx_hermetic_static_library) {
260 cflags = [ "-fvisibility=hidden" ]
261 if (libcxx_enable_new_delete_definitions) {
262 cflags_cc = [ "-fvisibility-global-new-delete-hidden" ]
264 defines = [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ]
267 "//compiler-rt/lib/builtins",
268 "//libcxxabi/src:cxxabi_static",
269 "//libunwind/src:unwind_static",
271 configs += [ ":cxx_config" ]
273 "//llvm/utils/gn/build:no_exceptions",
274 "//llvm/utils/gn/build:no_rtti",
279 if (libcxx_enable_experimental) {
280 static_library("cxx_experimental") {
281 output_dir = runtimes_dir
282 output_name = "c++experimental"
283 cflags_cc = [ "-std=c++14" ]
285 "experimental/memory_resource.cpp",
287 configs += [ ":cxx_config" ]
289 "//llvm/utils/gn/build:no_exceptions",
290 "//llvm/utils/gn/build:no_rtti",
297 if (libcxx_enable_shared) {
298 if (libcxx_enable_abi_linker_script) {
299 deps += [ ":cxx_linker_script" ]
301 deps += [ ":cxx_shared" ]
304 if (libcxx_enable_static) {
305 deps += [ ":cxx_static" ]
307 if (libcxx_enable_experimental) {
308 deps += [ ":cxx_experimental" ]