summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/build/config/c++/BUILD.gn
blob: e7ed69ec816f58d07a4e9861f265e9a8cbfb8fdd (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
import("//build/config/c++/c++.gni")
import("//build/config/chrome_build.gni")
import("//build/config/chromeos/ui_mode.gni")
import("//build/config/dcheck_always_on.gni")
import("//buildtools/deps_revisions.gni")

assert(use_custom_libcxx, "should only be used if use_custom_libcxx is set")

declare_args() {
  # lldb pretty printing only works when libc++ is built in the __1 (or __ndk1)
  # namespaces.  For pretty printing to work out-of-the-box on Mac (where lldb
  # is primarily used), this flag is set to false to build with the __1
  # namespace (to maintain ABI compatibility, this implies building without
  # _LIBCPP_ABI_UNSTABLE).  This is not necessary on non-component builds
  # because we leave the ABI version set to __1 in that case because libc++
  # symbols are not exported.
  # TODO(thomasanderson): Set this to true by default once rL352899 is available
  # in MacOS's lldb.
  libcxx_abi_unstable = !(is_apple && is_debug && is_component_build)
}

# TODO(xiaohuic): https://crbug/917533 Crashes on internal ChromeOS build.
# Do unconditionally once the underlying problem is fixed.
if (is_chromeos_ash && is_chrome_branded) {
  libcxx_abi_unstable = false
}

# This is included by reference in the //build/config/compiler:runtime_library
# config that is applied to all targets. It is here to separate out the logic
# that is specific to libc++. Please see that target for advice on what should
# go in :runtime_library vs. :compiler.
config("runtime_library") {
  cflags = []
  cflags_cc = []
  defines = []
  include_dirs = []
  ldflags = []
  libs = []

  if (libcxx_abi_unstable) {
    defines += [ "_LIBCPP_ABI_UNSTABLE" ]
  }

  if (libcxx_is_shared) {
    # When libcxx_is_shared is true, symbols from libc++.so are exported for
    # all DSOs to use.  If the system libc++ gets loaded (indirectly through
    # a system library), then it will conflict with our libc++.so.  Add a
    # custom ABI version if we're building with _LIBCPP_ABI_UNSTABLE to avoid
    # conflicts.
    #
    # Windows doesn't need to set _LIBCPP_ABI_VERSION since there's no system
    # C++ library we could conflict with.
    if (libcxx_abi_unstable && !is_win) {
      defines += [ "_LIBCPP_ABI_VERSION=Cr" ]
    }
  } else {
    # Don't leak any symbols on a static build.
    defines += [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ]
    if (!export_libcxxabi_from_executables && !is_win) {
      defines += [ "_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS" ]
    }
  }

  defines += [ "_LIBCPP_ENABLE_NODISCARD" ]

  include_dirs += [ "//buildtools/third_party/libc++" ]

  # Work around a symbol conflict between GRPC and the Fuchsia SDK.
  # TODO(crbug.com/1166970): Remove this when resolved.
  if (is_fuchsia) {
    defines += [ "_LIBCPP_NO_NATIVE_SEMAPHORES" ]
  }

  # The Windows component build fails to link with libc++'s debug mode. See
  # https://crbug.com/923166#c33, https://crbug.com/923166#c44, and
  # https://llvm.org/PR41018.
  if (!(is_win && is_component_build)) {
    # libc++ has two levels of debug mode. Setting _LIBCPP_DEBUG to zero
    # enables most assertions. Setting it to one additionally enables iterator
    # debugging. See https://libcxx.llvm.org/docs/DesignDocs/DebugMode.html
    if (enable_iterator_debugging) {
      defines += [ "_LIBCPP_DEBUG=1" ]
    } else if (is_debug || dcheck_always_on) {
      defines += [ "_LIBCPP_DEBUG=0" ]
    }
  }

  if (is_win) {
    # Intentionally not using libc++abi on Windows because libc++abi only
    # implements the Itanium C++ ABI, and not the Microsoft ABI which we use on
    # Windows (and we need to use in order to interoperate correctly with COM
    # among other things).
    assert(!export_libcxxabi_from_executables,
           "Don't use libcxxabi on Windows.")

    cflags_cc +=
        [ "-I" + rebase_path("$libcxx_prefix/include", root_build_dir) ]

    # Prevent libc++ from embedding linker flags to try to automatically link
    # against its runtime library. This is unnecessary with our build system,
    # and can also result in build failures if libc++'s name for a library
    # does not match ours.
    defines += [ "_LIBCPP_NO_AUTO_LINK" ]

    # Add a debug visualizer for Microsoft's debuggers so that they can display
    # libc++ types well.
    if (libcxx_natvis_include) {
      # chrome.natvis listed as an input in //buildtools/third_party/libc++ to
      # guarantee relinking on changes.
      ldflags += [ "/NATVIS:" + rebase_path("libc++.natvis", root_build_dir) ]
    }
  } else {
    cflags_cc += [
      "-nostdinc++",
      "-isystem" + rebase_path("$libcxx_prefix/include", root_build_dir),
      "-isystem" + rebase_path("$libcxxabi_prefix/include", root_build_dir),
    ]
    cflags_objcc = cflags_cc

    defines += [ "CR_LIBCXX_REVISION=$libcxx_revision" ]

    # Make sure we don't link against the system libstdc++ or libc++.
    if (is_clang) {
      ldflags += [ "-nostdlib++" ]
    } else {
      # Gcc has a built-in abs() definition with default visibility.
      # If it was not disabled, it would conflict with libc++'s abs()
      # with hidden visibility.
      cflags += [ "-fno-builtin-abs" ]

      ldflags += [ "-nodefaultlibs" ]

      # Unfortunately, there's no way to disable linking against just libc++
      # (gcc doesn't have -notstdlib++:
      # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83931); -nodefaultlibs
      # removes all of the default libraries, so add back the ones that we need.
      libs += [
        "c",
        "gcc_s",
        "m",
        "rt",
      ]
    }
  }
}