Debian Codegraph @

llvm/utils/gn/secondary/libunwind/src/BUILD.gn

raw
1 import("//clang/runtimes.gni")
2 import("//compiler-rt/target.gni")
3
4 declare_args() {
5 # Build libunwind as a shared library.
6 libunwind_enable_shared = true
7
8 # Build libunwind as a static library.
9 libunwind_enable_static = true
10 }
11
12 unwind_headers = [
13 "../include/libunwind.h",
14 "../include/unwind.h",
15 ]
16 if (current_os == "mac") {
17 unwind_headers += [
18 # Make `gn format` not collapse this, for sync_source_lists_from_cmake.py.
19 "../include/mach-o/compact_unwind_encoding.h",
20 ]
21 }
22
23 unwind_sources = [
24 "../include/unwind_arm_ehabi.h",
25 "../include/unwind_itanium.h",
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 "Unwind-wasm.c",
37 "UnwindCursor.hpp",
38 "UnwindLevel1-gcc-ext.c",
39 "UnwindLevel1.c",
40 "UnwindRegistersRestore.S",
41 "UnwindRegistersSave.S",
42 "assembly.h",
43 "config.h",
44 "dwarf2.h",
45 "libunwind.cpp",
46 "libunwind_ext.h",
47 "shadow_stack_unwind.h",
48 ]
49 if (current_os == "aix") {
50 unwind_sources += [ "Unwind_AIXExtras.cpp" ]
51 }
52
53 if (current_os == "android") {
54 if (current_cpu == "arm64") {
55 unwind_output_dir = "$crt_current_out_dir/aarch64"
56 } else if (current_cpu == "arm") {
57 unwind_output_dir = "$crt_current_out_dir/arm"
58 } else if (current_cpu == "x64") {
59 unwind_output_dir = "$crt_current_out_dir/x86_64"
60 } else if (current_cpu == "x86") {
61 unwind_output_dir = "$crt_current_out_dir/i386"
62 }
63 } else {
64 unwind_output_dir = runtimes_dir
65 }
66
67 config("unwind_config") {
68 cflags = []
69 cflags_c = [ "-std=c99" ]
70 cflags_cc = [ "-fno-rtti" ]
71 defines = [ "_LIBUNWIND_IS_NATIVE_ONLY" ]
72 include_dirs = [ "//libunwind/include" ]
73 if (current_os == "mac") {
74 cflags += [ "-U__STRICT_ANSI__" ]
75 }
76 if (current_os == "android") {
77 defines += [ "_LIBUNWIND_USE_DLADDR=0" ]
78 }
79 }
80
81 if (libunwind_enable_shared && current_os != "android") {
82 shared_library("unwind_shared") {
83 output_dir = unwind_output_dir
84 output_name = "unwind"
85 if (current_os == "linux" || current_os == "mac") {
86 cflags = [ "-fPIC" ]
87 ldflags = [ "-nostdlib++" ]
88 libs = [
89 "dl",
90 "pthread",
91 ]
92 }
93 if (current_os == "mac") {
94 cflags += [ "-fno-stack-protector" ]
95 ldflags += [
96 "-Wl,-compatibility_version,1",
97 "-Wl,-install_name,/usr/lib/libunwind.1.dylib",
98 ]
99 }
100 sources = unwind_sources
101 public = unwind_headers
102 deps = [ "//compiler-rt/lib/builtins" ]
103 configs += [ ":unwind_config" ]
104 configs -= [
105 "//llvm/utils/gn/build:no_exceptions",
106 "//llvm/utils/gn/build:no_rtti",
107 ]
108 }
109 }
110
111 if (libunwind_enable_static) {
112 template("libunwind_static_library") {
113 static_library(target_name) {
114 output_dir = unwind_output_dir
115 output_name = invoker.output_name
116 complete_static_lib = true
117 configs -= [ "//llvm/utils/gn/build:thin_archive" ]
118 sources = unwind_sources
119 public = unwind_headers
120 if (!invoker.export) {
121 cflags = [ "-fvisibility=hidden" ]
122 cflags_cc = [ "-fvisibility-global-new-delete=force-hidden" ]
123 defines = [ "_LIBUNWIND_HIDE_SYMBOLS" ]
124 }
125 deps = [ "//compiler-rt/lib/builtins" ]
126 configs += [ ":unwind_config" ]
127 configs -= [
128 "//llvm/utils/gn/build:no_exceptions",
129 "//llvm/utils/gn/build:no_rtti",
130 ]
131 }
132 }
133
134 libunwind_static_library("unwind_static_exported") {
135 output_name = "unwind-exported"
136 export = true
137 }
138 libunwind_static_library("unwind_static") {
139 output_name = "unwind"
140 export = false
141 }
142 }
143
144 group("src") {
145 deps = []
146 if (libunwind_enable_shared && current_os != "android") {
147 deps += [ ":unwind_shared" ]
148 }
149 if (libunwind_enable_static) {
150 deps += [
151 ":unwind_static",
152 ":unwind_static_exported",
153 ]
154 }
155 }