1import("//clang/runtimes.gni") 2import("//compiler-rt/target.gni") 3 4declare_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 12unwind_headers = [ 13 "../include/libunwind.h", 14 "../include/unwind.h", 15] 16if (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 23unwind_sources = [ 24 "AddressSpace.hpp", 25 "CompactUnwinder.hpp", 26 "DwarfInstructions.hpp", 27 "DwarfParser.hpp", 28 "RWMutex.hpp", 29 "Registers.hpp", 30 "Unwind-EHABI.cpp", 31 "Unwind-EHABI.h", 32 "Unwind-seh.cpp", 33 "Unwind-sjlj.c", 34 "UnwindCursor.hpp", 35 "UnwindLevel1-gcc-ext.c", 36 "UnwindLevel1.c", 37 "UnwindRegistersRestore.S", 38 "UnwindRegistersSave.S", 39 "assembly.h", 40 "config.h", 41 "dwarf2.h", 42 "libunwind.cpp", 43 "libunwind_ext.h", 44] 45if (current_os == "mac") { 46 unwind_sources += [ "Unwind_AppleExtras.cpp" ] 47} 48 49if (current_os == "android") { 50 if (current_cpu == "arm64") { 51 unwind_output_dir = "$crt_current_out_dir/aarch64" 52 } else if (current_cpu == "arm") { 53 unwind_output_dir = "$crt_current_out_dir/arm" 54 } 55} else { 56 unwind_output_dir = runtimes_dir 57} 58 59config("unwind_config") { 60 cflags = [] 61 cflags_c = [ "-std=c99" ] 62 cflags_cc = [ "-fno-rtti" ] 63 defines = [ "_LIBUNWIND_IS_NATIVE_ONLY" ] 64 include_dirs = [ "//libunwind/include" ] 65 if (current_os == "mac") { 66 cflags += [ "-U__STRICT_ANSI__" ] 67 } 68 if (current_os == "android") { 69 defines += [ "_LIBUNWIND_USE_DLADDR=0" ] 70 } 71} 72 73if (libunwind_enable_shared) { 74 shared_library("unwind_shared") { 75 output_dir = unwind_output_dir 76 output_name = "unwind" 77 if (current_os == "linux" || current_os == "mac") { 78 cflags = [ "-fPIC" ] 79 ldflags = [ "-nostdlib++" ] 80 libs = [ 81 "dl", 82 "pthread", 83 ] 84 } 85 if (current_os == "mac") { 86 ldflags += [ 87 "-compatibility_version 1", 88 "-install_name /usr/lib/libunwind.1.dylib", 89 ] 90 } 91 sources = unwind_sources 92 public = unwind_headers 93 deps = [ "//compiler-rt/lib/builtins" ] 94 configs += [ ":unwind_config" ] 95 configs -= [ 96 "//llvm/utils/gn/build:no_exceptions", 97 "//llvm/utils/gn/build:no_rtti", 98 ] 99 } 100} 101 102if (libunwind_enable_static) { 103 template("libunwind_static_library") { 104 static_library(target_name) { 105 output_dir = unwind_output_dir 106 output_name = invoker.output_name 107 complete_static_lib = true 108 configs -= [ "//llvm/utils/gn/build:thin_archive" ] 109 sources = unwind_sources 110 public = unwind_headers 111 if (!invoker.export) { 112 cflags = [ "-fvisibility=hidden" ] 113 cflags_cc = [ "-fvisibility-global-new-delete-hidden" ] 114 defines = [ "_LIBUNWIND_HIDE_SYMBOLS" ] 115 } 116 deps = [ "//compiler-rt/lib/builtins" ] 117 configs += [ ":unwind_config" ] 118 configs -= [ 119 "//llvm/utils/gn/build:no_exceptions", 120 "//llvm/utils/gn/build:no_rtti", 121 ] 122 } 123 } 124 125 libunwind_static_library("unwind_static_exported") { 126 output_name = "unwind-exported" 127 export = true 128 } 129 libunwind_static_library("unwind_static") { 130 output_name = "unwind" 131 export = false 132 } 133} 134 135group("src") { 136 deps = [] 137 if (libunwind_enable_shared) { 138 deps += [ ":unwind_shared" ] 139 } 140 if (libunwind_enable_static) { 141 deps += [ 142 ":unwind_static", 143 ":unwind_static_exported", 144 ] 145 } 146} 147