1import("//clang/runtimes.gni") 2import("//llvm/utils/gn/build/symlink_or_copy.gni") 3 4declare_args() { 5 # Whether to support libc++ opt-in debug mode via _LIBCPP_DEBUG. 6 libcxx_enable_debug_mode = true 7 8 # Build libc++ with definitions for operator new/delete. 9 libcxx_enable_new_delete_definitions = true 10 11 # Build libc++ as a shared library. 12 libcxx_enable_shared = true 13 14 # Build libc++ as a static library. 15 libcxx_enable_static = true 16 17 # Build filesystem as part of libc++fs.a. 18 libcxx_enable_filesystem = target_os != "win" 19 20 # Build libc++experimental.a. 21 libcxx_enable_experimental = true 22 23 # Use compiler-rt builtins. 24 libcxx_use_compiler_rt = true 25 26 # Use exceptions. 27 libcxx_enable_exceptions = true 28 29 # Use run time type information. 30 libcxx_enable_rtti = true 31 32 # Do not export any symbols from the static library. 33 libcxx_hermetic_static_library = true 34 35 # Use and install a linker script for the given ABI library. 36 libcxx_enable_abi_linker_script = true 37} 38 39config("cxx_config") { 40 include_dirs = [ 41 "//libcxxabi/include", 42 "//libcxx/include", 43 ] 44 cflags = [ 45 "-Wall", 46 "-Wextra", 47 "-W", 48 "-Wwrite-strings", 49 "-Wno-unused-parameter", 50 "-Wno-long-long", 51 "-Werror=return-type", 52 "-Wextra-semi", 53 "-Wno-user-defined-literals", 54 "-Wno-covered-switch-default", 55 ] 56 cflags_cc = [ 57 "-std=c++17", 58 "-nostdinc++", 59 ] 60 defines = [ "_LIBCPP_BUILDING_LIBRARY" ] 61 if (target_os == "win") { 62 cflags += [ "/Zl" ] 63 defines += [ 64 # Ignore the -MSC_VER mismatch, as we may build 65 # with a different compatibility version. 66 "_ALLOW_MSC_VER_MISMATCH", 67 68 # Don't check the msvcprt iterator debug levels 69 # as we will define the iterator types; libc++ 70 # uses a different macro to identify the debug 71 # level. 72 "_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH", 73 74 # We are building the c++ runtime, don't pull in 75 # msvcprt. 76 "_CRTBLD", 77 78 # Don't warn on the use of "deprecated" 79 # "insecure" functions which are standards 80 # specified. 81 "_CRT_SECURE_NO_WARNINGS", 82 83 # Use the ISO conforming behaviour for conversion 84 # in printf, scanf. 85 "_CRT_STDIO_ISO_WIDE_SPECIFIERS", 86 ] 87 } 88 if (!libcxx_enable_new_delete_definitions) { 89 defines += [ "_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS" ] 90 } 91 if (libcxx_enable_exceptions) { 92 if (current_os == "win") { 93 cflags_cc += [ "/EHsc" ] 94 } 95 } else { 96 if (current_os == "win") { 97 cflags_cc += [ 98 "/EHs-", 99 "/EHa-", 100 ] 101 } else { 102 cflags_cc += [ "-fno-exceptions" ] 103 } 104 } 105 if (!libcxx_enable_rtti) { 106 if (current_os == "win") { 107 cflags_cc += [ "/GR-" ] 108 } else { 109 cflags_cc += [ "-fno-rtti" ] 110 } 111 } 112} 113 114cxx_sources = [ 115 "algorithm.cpp", 116 "any.cpp", 117 "atomic.cpp", 118 "barrier.cpp", 119 "bind.cpp", 120 "charconv.cpp", 121 "chrono.cpp", 122 "condition_variable.cpp", 123 "condition_variable_destructor.cpp", 124 "exception.cpp", 125 "functional.cpp", 126 "future.cpp", 127 "hash.cpp", 128 "include/apple_availability.h", 129 "include/atomic_support.h", 130 "include/config_elast.h", 131 "include/refstring.h", 132 "ios.cpp", 133 "ios.instantiations.cpp", 134 "iostream.cpp", 135 "locale.cpp", 136 "memory.cpp", 137 "mutex.cpp", 138 "mutex_destructor.cpp", 139 "new.cpp", 140 "optional.cpp", 141 "random.cpp", 142 "random_shuffle.cpp", 143 "regex.cpp", 144 "shared_mutex.cpp", 145 "stdexcept.cpp", 146 "string.cpp", 147 "strstream.cpp", 148 "support/runtime/exception_fallback.ipp", 149 "support/runtime/exception_glibcxx.ipp", 150 "support/runtime/exception_libcxxabi.ipp", 151 "support/runtime/exception_libcxxrt.ipp", 152 "support/runtime/exception_msvc.ipp", 153 "support/runtime/exception_pointer_cxxabi.ipp", 154 "support/runtime/exception_pointer_glibcxx.ipp", 155 "support/runtime/exception_pointer_msvc.ipp", 156 "support/runtime/exception_pointer_unimplemented.ipp", 157 "support/runtime/new_handler_fallback.ipp", 158 "support/runtime/stdexcept_default.ipp", 159 "support/runtime/stdexcept_vcruntime.ipp", 160 "system_error.cpp", 161 "thread.cpp", 162 "typeinfo.cpp", 163 "utility.cpp", 164 "valarray.cpp", 165 "variant.cpp", 166 "vector.cpp", 167] 168if (target_os == "win") { 169 cxx_sources += [ 170 "support/win32/locale_win32.cpp", 171 "support/win32/support.cpp", 172 "support/win32/thread_win32.cpp", 173 ] 174} 175if (target_os == "solaris") { 176 cxx_sources += [ "support/solaris/xlocale.cpp" ] 177} 178if (libcxx_enable_debug_mode) { 179 cxx_sources += [ "debug.cpp" ] 180} 181if (libcxx_enable_filesystem) { 182 cxx_sources += [ 183 "filesystem/directory_iterator.cpp", 184 "filesystem/filesystem_common.h", 185 "filesystem/operations.cpp", 186 ] 187 if (libcxx_use_compiler_rt) { 188 cxx_sources += [ "filesystem/int128_builtins.cpp" ] 189 } 190} 191 192if (libcxx_enable_shared) { 193 shared_library("cxx_shared") { 194 output_dir = runtimes_dir 195 output_name = "c++" 196 if (libcxx_enable_abi_linker_script) { 197 output_extension = "so.0" 198 } 199 if (target_os == "linux" || target_os == "mac") { 200 cflags = [ "-fPIC" ] 201 ldflags = [ "-nostdlib++" ] 202 libs = [ 203 "dl", 204 "pthread", 205 ] 206 } 207 sources = cxx_sources 208 deps = [ 209 "//compiler-rt/lib/builtins", 210 "//libcxxabi/src:cxxabi_shared", 211 "//libunwind/src:unwind_shared", 212 ] 213 configs += [ ":cxx_config" ] 214 configs -= [ 215 "//llvm/utils/gn/build:no_exceptions", 216 "//llvm/utils/gn/build:no_rtti", 217 ] 218 } 219 220 symlink_or_copy("cxx_symlink") { 221 deps = [ ":cxx_shared" ] 222 source = "libc++.so.0" 223 output = "$runtimes_dir/libc++.so" 224 } 225 226 if (libcxx_enable_abi_linker_script) { 227 action("cxx_linker_script") { 228 script = "//llvm/utils/gn/secondary/libcxx/utils/gen_link_script.py" 229 outputs = [ "$runtimes_dir/libc++.so" ] 230 args = [ 231 "--input", 232 rebase_path("$runtimes_dir/libc++.so.0", root_build_dir), 233 "--output", 234 rebase_path("$runtimes_dir/libc++.so", root_build_dir), 235 "c++abi", 236 "unwind", 237 ] 238 deps = [ ":cxx_symlink" ] 239 } 240 } 241} 242 243if (libcxx_enable_static) { 244 static_library("cxx_static") { 245 output_dir = runtimes_dir 246 output_name = "c++" 247 complete_static_lib = true 248 configs -= [ "//llvm/utils/gn/build:thin_archive" ] 249 sources = cxx_sources 250 if (libcxx_hermetic_static_library) { 251 cflags = [ "-fvisibility=hidden" ] 252 if (libcxx_enable_new_delete_definitions) { 253 cflags_cc = [ "-fvisibility-global-new-delete-hidden" ] 254 } 255 defines = [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ] 256 } 257 deps = [ 258 "//compiler-rt/lib/builtins", 259 "//libcxxabi/src:cxxabi_static", 260 "//libunwind/src:unwind_static", 261 ] 262 configs += [ ":cxx_config" ] 263 configs -= [ 264 "//llvm/utils/gn/build:no_exceptions", 265 "//llvm/utils/gn/build:no_rtti", 266 ] 267 } 268} 269 270if (libcxx_enable_experimental) { 271 static_library("cxx_experimental") { 272 output_dir = runtimes_dir 273 output_name = "c++experimental" 274 sources = [ "experimental/memory_resource.cpp" ] 275 configs += [ ":cxx_config" ] 276 configs -= [ 277 "//llvm/utils/gn/build:no_exceptions", 278 "//llvm/utils/gn/build:no_rtti", 279 ] 280 } 281} 282 283group("src") { 284 deps = [] 285 if (libcxx_enable_shared) { 286 if (libcxx_enable_abi_linker_script) { 287 deps += [ ":cxx_linker_script" ] 288 } else { 289 deps += [ ":cxx_shared" ] 290 } 291 } 292 if (libcxx_enable_static) { 293 deps += [ ":cxx_static" ] 294 } 295 if (libcxx_enable_experimental) { 296 deps += [ ":cxx_experimental" ] 297 } 298} 299