BUILD.gn 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. # Copyright 2015 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. import("//build/config/c++/c++.gni")
  5. import("//build/config/sanitizers/sanitizers.gni")
  6. import("//build/toolchain/toolchain.gni")
  7. # Used by libc++ and libc++abi.
  8. config("config") {
  9. cflags = [ "-fstrict-aliasing" ]
  10. if (is_win) {
  11. cflags += [
  12. # libc++ wants to redefine the macros WIN32_LEAN_AND_MEAN and _CRT_RAND_S
  13. # in its implementation.
  14. "-Wno-macro-redefined",
  15. ]
  16. cflags_cc = [
  17. # We want to use a uniform C++ version across all of chromium, but
  18. # upstream libc++ requires C++20 so we have to make an exception here.
  19. # No other target should override the default -std= flag.
  20. "-std:c++20",
  21. ]
  22. } else {
  23. cflags += [ "-fPIC" ]
  24. cflags_cc = [ "-std=c++20" ]
  25. }
  26. defines = [ "_LIBCPP_BUILDING_LIBRARY" ]
  27. }
  28. # Explicitly set version macros to Windows 7 to prevent libc++ from adding a
  29. # hard dependency on GetSystemTimePreciseAsFileTime, which was introduced in
  30. # Windows 8.
  31. config("winver") {
  32. defines = [
  33. "NTDDI_VERSION=NTDDI_WIN7",
  34. "_WIN32_WINNT=_WIN32_WINNT_WIN7",
  35. "WINVER=_WIN32_WINNT_WIN7",
  36. ]
  37. }
  38. if (libcxx_is_shared) {
  39. _libcxx_target_type = "shared_library"
  40. } else {
  41. _libcxx_target_type = "source_set"
  42. }
  43. target(_libcxx_target_type, "libc++") {
  44. # Most things that need to depend on libc++ should do so via the implicit
  45. # 'common_deps' dependency below. Some targets that package libc++.so may
  46. # need to explicitly depend on libc++.
  47. visibility = [
  48. "//build/config:common_deps",
  49. "//third_party/catapult/devil:devil",
  50. ]
  51. if (is_linux) {
  52. # This target packages libc++.so, so must have an explicit dependency on
  53. # libc++.
  54. visibility +=
  55. [ "//remoting/host/linux:remoting_me2me_host_copy_user_session" ]
  56. }
  57. if (libcxx_is_shared) {
  58. no_default_deps = true
  59. }
  60. if (is_linux && !is_clang) {
  61. libs = [ "atomic" ]
  62. }
  63. inputs = [ "__config_site" ]
  64. sources = [
  65. "trunk/src/algorithm.cpp",
  66. "trunk/src/any.cpp",
  67. "trunk/src/atomic.cpp",
  68. "trunk/src/barrier.cpp",
  69. "trunk/src/bind.cpp",
  70. "trunk/src/charconv.cpp",
  71. "trunk/src/chrono.cpp",
  72. "trunk/src/condition_variable.cpp",
  73. "trunk/src/condition_variable_destructor.cpp",
  74. "trunk/src/debug.cpp",
  75. "trunk/src/exception.cpp",
  76. "trunk/src/format.cpp",
  77. "trunk/src/functional.cpp",
  78. "trunk/src/future.cpp",
  79. "trunk/src/hash.cpp",
  80. "trunk/src/ios.cpp",
  81. "trunk/src/ios.instantiations.cpp",
  82. "trunk/src/iostream.cpp",
  83. "trunk/src/legacy_debug_handler.cpp",
  84. "trunk/src/legacy_pointer_safety.cpp",
  85. "trunk/src/locale.cpp",
  86. "trunk/src/memory.cpp",
  87. "trunk/src/mutex.cpp",
  88. "trunk/src/mutex_destructor.cpp",
  89. "trunk/src/new.cpp",
  90. "trunk/src/optional.cpp",
  91. "trunk/src/random.cpp",
  92. "trunk/src/random_shuffle.cpp",
  93. "trunk/src/regex.cpp",
  94. "trunk/src/ryu/d2fixed.cpp",
  95. "trunk/src/ryu/d2s.cpp",
  96. "trunk/src/ryu/f2s.cpp",
  97. "trunk/src/shared_mutex.cpp",
  98. "trunk/src/stdexcept.cpp",
  99. "trunk/src/string.cpp",
  100. "trunk/src/strstream.cpp",
  101. "trunk/src/system_error.cpp",
  102. "trunk/src/thread.cpp",
  103. "trunk/src/typeinfo.cpp",
  104. "trunk/src/utility.cpp",
  105. "trunk/src/valarray.cpp",
  106. "trunk/src/variant.cpp",
  107. "trunk/src/vector.cpp",
  108. "trunk/src/verbose_abort.cpp",
  109. ]
  110. include_dirs = [ "trunk/src" ]
  111. if (is_win) {
  112. sources += [
  113. "trunk/src/support/win32/locale_win32.cpp",
  114. "trunk/src/support/win32/support.cpp",
  115. "trunk/src/support/win32/thread_win32.cpp",
  116. ]
  117. configs -= [ "//build/config/win:winver" ]
  118. configs += [ ":winver" ]
  119. if (libcxx_natvis_include) {
  120. inputs += [
  121. # libc++.natvis listed as an input here instead of in
  122. # //build/config/c++:runtime_library to prevent unnecessary size
  123. # increase in generated build files.
  124. "//build/config/c++/libc++.natvis",
  125. ]
  126. }
  127. }
  128. configs -= [
  129. "//build/config/compiler:chromium_code",
  130. "//build/config/compiler:no_exceptions",
  131. "//build/config/compiler:no_rtti",
  132. "//build/config/coverage:default_coverage",
  133. ]
  134. if ((is_android || is_apple) && libcxx_is_shared) {
  135. # Use libc++_chrome to avoid conflicting with system libc++
  136. output_name = "libc++_chrome"
  137. if (is_android) {
  138. # See crbug.com/1076244#c11 for more detail.
  139. configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
  140. }
  141. }
  142. configs += [
  143. ":config",
  144. "//build/config/compiler:no_chromium_code",
  145. "//build/config/compiler:exceptions",
  146. "//build/config/compiler:rtti",
  147. ]
  148. if (libcxx_is_shared && !is_win) {
  149. configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
  150. configs += [ "//build/config/gcc:symbol_visibility_default" ]
  151. }
  152. defines = []
  153. if (!libcxx_is_shared) {
  154. if (is_apple && is_clang) {
  155. # We want operator new/delete to be private on Mac, but these functions
  156. # are implicitly created by the compiler for each translation unit, as
  157. # specified in the C++ spec 3.7.4p2, which makes them always have default
  158. # visibility. This option is needed to force hidden visibility since
  159. # -fvisibility=hidden doesn't have the desired effect.
  160. cflags = [ "-fvisibility-global-new-delete-hidden" ]
  161. } else {
  162. defines += [
  163. # This resets the visibility to default only for the various
  164. # flavors of operator new and operator delete. These symbols
  165. # are weak and get overriden by Chromium-provided ones, but if
  166. # these symbols had hidden visibility, this would make the
  167. # Chromium symbols hidden too because elf visibility rules
  168. # require that linkers use the least visible form when merging,
  169. # and if this is hidden, then when we merge it with tcmalloc's
  170. # operator new, hidden visibility would win. However, tcmalloc
  171. # needs a visible operator new to also override operator new
  172. # references from system libraries.
  173. # TODO(lld): Ask lld for a --force-public-visibility flag or
  174. # similar to that overrides the default elf merging rules, and
  175. # make tcmalloc's gn config pass that to all its dependencies,
  176. # then remove this override here.
  177. "_LIBCPP_OVERRIDABLE_FUNC_VIS=__attribute__((__visibility__(\"default\")))",
  178. ]
  179. }
  180. }
  181. if (!is_apple && (is_asan || is_tsan || is_msan)) {
  182. # In {a,t,m}san configurations, operator new and operator delete will be
  183. # provided by the sanitizer runtime library. Since libc++ defines these
  184. # symbols with weak linkage, and the *san runtime uses strong linkage, it
  185. # should technically be OK to omit this, but it's added to be explicit.
  186. defines += [ "_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS" ]
  187. }
  188. if (!is_win) {
  189. defines += [ "LIBCXX_BUILDING_LIBCXXABI" ]
  190. if (!export_libcxxabi_from_executables) {
  191. deps = [ "//buildtools/third_party/libc++abi" ]
  192. }
  193. }
  194. }