1import("//clang/runtimes.gni")
2
3declare_args() {
4  # Build libunwind as a shared library.
5  libunwind_enable_shared = true
6
7  # Build libunwind as a static library.
8  libunwind_enable_static = true
9
10  # Do not export any symbols from the static library.
11  libunwind_hermetic_static_library = true
12}
13
14unwind_headers = [
15  "../include/libunwind.h",
16  "../include/unwind.h",
17]
18if (target_os == "mac") {
19  unwind_headers += [
20    # Make `gn format` not collapse this, for sync_source_lists_from_cmake.py.
21    "../include/mach-o/compact_unwind_encoding.h",
22  ]
23}
24
25unwind_sources = [
26  "AddressSpace.hpp",
27  "CompactUnwinder.hpp",
28  "DwarfInstructions.hpp",
29  "DwarfParser.hpp",
30  "RWMutex.hpp",
31  "Registers.hpp",
32  "Unwind-EHABI.cpp",
33  "Unwind-EHABI.h",
34  "Unwind-seh.cpp",
35  "Unwind-sjlj.c",
36  "UnwindCursor.hpp",
37  "UnwindLevel1-gcc-ext.c",
38  "UnwindLevel1.c",
39  "UnwindRegistersRestore.S",
40  "UnwindRegistersSave.S",
41  "assembly.h",
42  "config.h",
43  "dwarf2.h",
44  "libunwind.cpp",
45  "libunwind_ext.h",
46]
47if (target_os == "mac") {
48  unwind_sources += [ "Unwind_AppleExtras.cpp" ]
49}
50
51config("unwind_config") {
52  cflags = []
53  cflags_c = [ "-std=c99" ]
54  cflags_cc = [ "-fno-rtti" ]
55  include_dirs = [ "//libunwind/include" ]
56  if (target_os == "mac") {
57    cflags += [ "-U__STRICT_ANSI__" ]
58  }
59}
60
61if (libunwind_enable_shared) {
62  shared_library("unwind_shared") {
63    output_dir = runtimes_dir
64    output_name = "unwind"
65    if (target_os == "linux" || target_os == "mac") {
66      cflags = [ "-fPIC" ]
67      ldflags = [ "-nostdlib++" ]
68      libs = [
69        "dl",
70        "pthread",
71      ]
72    }
73    if (target_os == "mac") {
74      ldflags += [
75        "-compatibility_version 1",
76        "-install_name /usr/lib/libunwind.1.dylib",
77      ]
78    }
79    sources = unwind_sources
80    public = unwind_headers
81    deps = [ "//compiler-rt/lib/builtins" ]
82    configs += [ ":unwind_config" ]
83    configs -= [
84      "//llvm/utils/gn/build:no_exceptions",
85      "//llvm/utils/gn/build:no_rtti",
86    ]
87  }
88}
89
90if (libunwind_enable_static) {
91  static_library("unwind_static") {
92    output_dir = runtimes_dir
93    output_name = "unwind"
94    complete_static_lib = true
95    configs -= [ "//llvm/utils/gn/build:thin_archive" ]
96    sources = unwind_sources
97    public = unwind_headers
98    if (libunwind_hermetic_static_library) {
99      cflags = [ "-fvisibility=hidden" ]
100      cflags_cc = [ "-fvisibility-global-new-delete-hidden" ]
101      defines = [ "_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS" ]
102    }
103    deps = [ "//compiler-rt/lib/builtins" ]
104    configs += [ ":unwind_config" ]
105    configs -= [
106      "//llvm/utils/gn/build:no_exceptions",
107      "//llvm/utils/gn/build:no_rtti",
108    ]
109  }
110}
111
112group("src") {
113  deps = []
114  if (libunwind_enable_shared) {
115    deps += [ ":unwind_shared" ]
116  }
117  if (libunwind_enable_static) {
118    deps += [ ":unwind_static" ]
119  }
120}
121