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