aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/gn/secondary/libunwind/src/BUILD.gn
blob: ea95b1d64fdde8dccd86cbdf3216456dfefebe93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import("//clang/runtimes.gni")
import("//compiler-rt/target.gni")

declare_args() {
  # Build libunwind as a shared library.
  libunwind_enable_shared = true

  # Build libunwind as a static library.
  libunwind_enable_static = true
}

unwind_headers = [
  "../include/libunwind.h",
  "../include/unwind.h",
]
if (current_os == "mac") {
  unwind_headers += [
    # Make `gn format` not collapse this, for sync_source_lists_from_cmake.py.
    "../include/mach-o/compact_unwind_encoding.h",
  ]
}

unwind_sources = [
  "../include/unwind_arm_ehabi.h",
  "../include/unwind_itanium.h",
  "AddressSpace.hpp",
  "CompactUnwinder.hpp",
  "DwarfInstructions.hpp",
  "DwarfParser.hpp",
  "RWMutex.hpp",
  "Registers.hpp",
  "Unwind-EHABI.cpp",
  "Unwind-EHABI.h",
  "Unwind-seh.cpp",
  "Unwind-sjlj.c",
  "Unwind-wasm.c",
  "UnwindCursor.hpp",
  "UnwindLevel1-gcc-ext.c",
  "UnwindLevel1.c",
  "UnwindRegistersRestore.S",
  "UnwindRegistersSave.S",
  "assembly.h",
  "cet_unwind.h",
  "config.h",
  "dwarf2.h",
  "libunwind.cpp",
  "libunwind_ext.h",
]
if (current_os == "aix") {
  unwind_sources += [ "Unwind_AIXExtras.cpp" ]
}

if (current_os == "android") {
  if (current_cpu == "arm64") {
    unwind_output_dir = "$crt_current_out_dir/aarch64"
  } else if (current_cpu == "arm") {
    unwind_output_dir = "$crt_current_out_dir/arm"
  } else if (current_cpu == "x64") {
    unwind_output_dir = "$crt_current_out_dir/x86_64"
  } else if (current_cpu == "x86") {
    unwind_output_dir = "$crt_current_out_dir/i386"
  }
} else {
  unwind_output_dir = runtimes_dir
}

config("unwind_config") {
  cflags = []
  cflags_c = [ "-std=c99" ]
  cflags_cc = [ "-fno-rtti" ]
  defines = [ "_LIBUNWIND_IS_NATIVE_ONLY" ]
  include_dirs = [ "//libunwind/include" ]
  if (current_os == "mac") {
    cflags += [ "-U__STRICT_ANSI__" ]
  }
  if (current_os == "android") {
    defines += [ "_LIBUNWIND_USE_DLADDR=0" ]
  }
}

if (libunwind_enable_shared && current_os != "android") {
  shared_library("unwind_shared") {
    output_dir = unwind_output_dir
    output_name = "unwind"
    if (current_os == "linux" || current_os == "mac") {
      cflags = [ "-fPIC" ]
      ldflags = [ "-nostdlib++" ]
      libs = [
        "dl",
        "pthread",
      ]
    }
    if (current_os == "mac") {
      cflags += [ "-fno-stack-protector" ]
      ldflags += [
        "-Wl,-compatibility_version,1",
        "-Wl,-install_name,/usr/lib/libunwind.1.dylib",
      ]
    }
    sources = unwind_sources
    public = unwind_headers
    deps = [ "//compiler-rt/lib/builtins" ]
    configs += [ ":unwind_config" ]
    configs -= [
      "//llvm/utils/gn/build:no_exceptions",
      "//llvm/utils/gn/build:no_rtti",
    ]
  }
}

if (libunwind_enable_static) {
  template("libunwind_static_library") {
    static_library(target_name) {
      output_dir = unwind_output_dir
      output_name = invoker.output_name
      complete_static_lib = true
      configs -= [ "//llvm/utils/gn/build:thin_archive" ]
      sources = unwind_sources
      public = unwind_headers
      if (!invoker.export) {
        cflags = [ "-fvisibility=hidden" ]
        cflags_cc = [ "-fvisibility-global-new-delete-hidden" ]
        defines = [ "_LIBUNWIND_HIDE_SYMBOLS" ]
      }
      deps = [ "//compiler-rt/lib/builtins" ]
      configs += [ ":unwind_config" ]
      configs -= [
        "//llvm/utils/gn/build:no_exceptions",
        "//llvm/utils/gn/build:no_rtti",
      ]
    }
  }

  libunwind_static_library("unwind_static_exported") {
    output_name = "unwind-exported"
    export = true
  }
  libunwind_static_library("unwind_static") {
    output_name = "unwind"
    export = false
  }
}

group("src") {
  deps = []
  if (libunwind_enable_shared && current_os != "android") {
    deps += [ ":unwind_shared" ]
  }
  if (libunwind_enable_static) {
    deps += [
      ":unwind_static",
      ":unwind_static_exported",
    ]
  }
}