xref: /netbsd-src/external/apache2/llvm/dist/llvm/utils/gn/secondary/libcxxabi/src/BUILD.gn (revision 82d56013d7b633d116a93943de88e08335357a7c)
1import("//clang/runtimes.gni")
2
3declare_args() {
4  # Use exceptions.
5  libcxxabi_enable_exceptions = true
6
7  # Build libc++abi with definitions for operator new/delete.
8  libcxxabi_enable_new_delete_definitions = true
9
10  # Build libcxxabi as a shared library.
11  libcxxabi_enable_shared = true
12
13  # Build libcxxabi as a static library.
14  libcxxabi_enable_static = true
15
16  # Do not export any symbols from the static library.
17  libcxxabi_hermetic_static_library = true
18}
19
20cxxabi_headers = [
21  # Make `gn format` not collapse this, for sync_source_lists_from_cmake.py.
22  "../include/cxxabi.h",
23]
24
25cxxabi_sources = [
26  # C++ABI files
27  "cxa_aux_runtime.cpp",
28  "cxa_default_handlers.cpp",
29  "cxa_demangle.cpp",
30  "cxa_exception_storage.cpp",
31  "cxa_guard.cpp",
32  "cxa_handlers.cpp",
33  "cxa_vector.cpp",
34  "cxa_virtual.cpp",
35
36  # C++ STL files
37  "stdlib_exception.cpp",
38  "stdlib_stdexcept.cpp",
39  "stdlib_typeinfo.cpp",
40
41  # Internal files
42  "abort_message.cpp",
43  "fallback_malloc.cpp",
44  "private_typeinfo.cpp",
45]
46if (libcxxabi_enable_new_delete_definitions) {
47  cxxabi_sources += [ "stdlib_new_delete.cpp" ]
48}
49if (libcxxabi_enable_exceptions) {
50  cxxabi_sources += [
51    "cxa_exception.cpp",
52    "cxa_personality.cpp",
53  ]
54} else {
55  cxxabi_sources += [ "cxa_noexception.cpp" ]
56}
57if (target_os == "linux" || target_os == "fuchsia") {
58  cxxabi_sources += [ "cxa_thread_atexit.cpp" ]
59}
60
61config("cxxabi_config") {
62  include_dirs = [
63    "//libcxxabi/include",
64
65    # stdlib_stdexcept.cpp depends on libc++ internals.
66    "//libcxx",
67  ]
68  cflags_cc = [ "-nostdinc++" ]
69  defines = [ "_LIBCXXABI_BUILDING_LIBRARY" ]
70  if (target_os == "win") {
71    defines += [ "_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS" ]
72  }
73}
74
75if (libcxxabi_enable_shared) {
76  shared_library("cxxabi_shared") {
77    output_dir = runtimes_dir
78    output_name = "c++abi"
79    if (target_os == "linux" || target_os == "mac") {
80      cflags = [ "-fPIC" ]
81      ldflags = [ "-nostdlib++" ]
82      libs = [
83        "dl",
84        "pthread",
85      ]
86    }
87    sources = cxxabi_sources
88    public = cxxabi_headers
89    deps = [
90      "//compiler-rt/lib/builtins",
91      "//libcxx/include",
92      "//libunwind/src:unwind_shared",
93    ]
94    configs += [ ":cxxabi_config" ]
95    configs -= [
96      "//llvm/utils/gn/build:no_exceptions",
97      "//llvm/utils/gn/build:no_rtti",
98    ]
99  }
100}
101
102if (libcxxabi_enable_static) {
103  static_library("cxxabi_static") {
104    output_dir = runtimes_dir
105    output_name = "c++abi"
106    complete_static_lib = true
107    configs -= [ "//llvm/utils/gn/build:thin_archive" ]
108    sources = cxxabi_sources
109    public = cxxabi_headers
110    if (libcxxabi_hermetic_static_library) {
111      cflags = [ "-fvisibility=hidden" ]
112      if (libcxxabi_enable_new_delete_definitions) {
113        cflags_cc = [ "-fvisibility-global-new-delete-hidden" ]
114      }
115      defines = [
116        "_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
117        "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
118      ]
119    }
120    deps = [
121      "//compiler-rt/lib/builtins",
122      "//libcxx/include",
123      "//libunwind/src:unwind_static",
124    ]
125    configs += [ ":cxxabi_config" ]
126    configs -= [
127      "//llvm/utils/gn/build:no_exceptions",
128      "//llvm/utils/gn/build:no_rtti",
129    ]
130  }
131}
132
133group("src") {
134  deps = []
135  if (libcxxabi_enable_shared) {
136    deps += [ ":cxxabi_shared" ]
137  }
138  if (libcxxabi_enable_static) {
139    deps += [ ":cxxabi_static" ]
140  }
141}
142