You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1058 lines
33 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. # Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
  2. #
  3. # Use of this source code is governed by a BSD-style license
  4. # that can be found in the LICENSE file in the root of the source
  5. # tree. An additional intellectual property rights grant can be found
  6. # in the file PATENTS. All contributing project authors may
  7. # be found in the AUTHORS file in the root of the source tree.
  8. import("//build/config/arm.gni")
  9. import("//build/config/features.gni")
  10. import("//build/config/mips.gni")
  11. import("//build/config/sanitizers/sanitizers.gni")
  12. import("//build/config/sysroot.gni")
  13. import("//build/config/ui.gni")
  14. import("//build_overrides/build.gni")
  15. if (!build_with_chromium && is_component_build) {
  16. print("The Gn argument `is_component_build` is currently " +
  17. "ignored for WebRTC builds.")
  18. print("Component builds are supported by Chromium and the argument " +
  19. "`is_component_build` makes it possible to create shared libraries " +
  20. "instead of static libraries.")
  21. print("If an app depends on WebRTC it makes sense to just depend on the " +
  22. "WebRTC static library, so there is no difference between " +
  23. "`is_component_build=true` and `is_component_build=false`.")
  24. print(
  25. "More info about component builds at: " + "https://chromium.googlesource.com/chromium/src/+/master/docs/component_build.md")
  26. assert(!is_component_build, "Component builds are not supported in WebRTC.")
  27. }
  28. if (is_ios) {
  29. import("//build/config/ios/rules.gni")
  30. }
  31. if (is_mac) {
  32. import("//build/config/mac/rules.gni")
  33. }
  34. declare_args() {
  35. # Setting this to true will make RTC_EXPORT (see rtc_base/system/rtc_export.h)
  36. # expand to code that will manage symbols visibility.
  37. rtc_enable_symbol_export = false
  38. # Setting this to true will define WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT which
  39. # will tell the pre-processor to remove the default definition of symbols
  40. # needed to use field_trial. In that case a new implementation needs to be
  41. # provided.
  42. if (build_with_chromium) {
  43. # When WebRTC is built as part of Chromium it should exclude the default
  44. # implementation of field_trial unless it is building for NACL or
  45. # Chromecast.
  46. rtc_exclude_field_trial_default = !is_nacl && !is_chromecast
  47. } else {
  48. rtc_exclude_field_trial_default = false
  49. }
  50. # Setting this to true will define WEBRTC_EXCLUDE_METRICS_DEFAULT which
  51. # will tell the pre-processor to remove the default definition of symbols
  52. # needed to use metrics. In that case a new implementation needs to be
  53. # provided.
  54. rtc_exclude_metrics_default = build_with_chromium
  55. # Setting this to false will require the API user to pass in their own
  56. # SSLCertificateVerifier to verify the certificates presented from a
  57. # TLS-TURN server. In return disabling this saves around 100kb in the binary.
  58. rtc_builtin_ssl_root_certificates = true
  59. # Include the iLBC audio codec?
  60. rtc_include_ilbc = true
  61. # Disable this to avoid building the Opus audio codec.
  62. rtc_include_opus = true
  63. # Enable this if the Opus version upon which WebRTC is built supports direct
  64. # encoding of 120 ms packets.
  65. rtc_opus_support_120ms_ptime = true
  66. # Enable this to let the Opus audio codec change complexity on the fly.
  67. rtc_opus_variable_complexity = false
  68. # Used to specify an external Jsoncpp include path when not compiling the
  69. # library that comes with WebRTC (i.e. rtc_build_json == 0).
  70. rtc_jsoncpp_root = "//third_party/jsoncpp/source/include"
  71. # Used to specify an external OpenSSL include path when not compiling the
  72. # library that comes with WebRTC (i.e. rtc_build_ssl == 0).
  73. rtc_ssl_root = ""
  74. # Selects fixed-point code where possible.
  75. rtc_prefer_fixed_point = false
  76. # Enable when an external authentication mechanism is used for performing
  77. # packet authentication for RTP packets instead of libsrtp.
  78. rtc_enable_external_auth = build_with_chromium
  79. # Selects whether debug dumps for the audio processing module
  80. # should be generated.
  81. apm_debug_dump = false
  82. # Set this to true to enable BWE test logging.
  83. rtc_enable_bwe_test_logging = false
  84. # Set this to false to skip building examples.
  85. rtc_build_examples = true
  86. # Set this to false to skip building tools.
  87. rtc_build_tools = true
  88. # Set this to false to skip building code that requires X11.
  89. rtc_use_x11 = use_x11
  90. # Set this to use PipeWire on the Wayland display server.
  91. # By default it's only enabled on desktop Linux (excludes ChromeOS) and
  92. # only when using the sysroot as PipeWire is not available in older and
  93. # supported Ubuntu and Debian distributions.
  94. rtc_use_pipewire = is_desktop_linux && use_sysroot
  95. # Set this to link PipeWire directly instead of using the dlopen.
  96. rtc_link_pipewire = false
  97. # Enable to use the Mozilla internal settings.
  98. build_with_mozilla = false
  99. # Enable use of Android AAudio which requires Android SDK 26 or above and
  100. # NDK r16 or above.
  101. rtc_enable_android_aaudio = false
  102. # Set to "func", "block", "edge" for coverage generation.
  103. # At unit test runtime set UBSAN_OPTIONS="coverage=1".
  104. # It is recommend to set include_examples=0.
  105. # Use llvm's sancov -html-report for human readable reports.
  106. # See http://clang.llvm.org/docs/SanitizerCoverage.html .
  107. rtc_sanitize_coverage = ""
  108. if (current_cpu == "arm" || current_cpu == "arm64") {
  109. rtc_prefer_fixed_point = true
  110. }
  111. # Determines whether NEON code will be built.
  112. rtc_build_with_neon =
  113. (current_cpu == "arm" && arm_use_neon) || current_cpu == "arm64"
  114. # Enable this to build OpenH264 encoder/FFmpeg decoder. This is supported on
  115. # all platforms except Android and iOS. Because FFmpeg can be built
  116. # with/without H.264 support, |ffmpeg_branding| has to separately be set to a
  117. # value that includes H.264, for example "Chrome". If FFmpeg is built without
  118. # H.264, compilation succeeds but |H264DecoderImpl| fails to initialize.
  119. # CHECK THE OPENH264, FFMPEG AND H.264 LICENSES/PATENTS BEFORE BUILDING.
  120. # http://www.openh264.org, https://www.ffmpeg.org/
  121. #
  122. # Enabling H264 when building with MSVC is currently not supported, see
  123. # bugs.webrtc.org/9213#c13 for more info.
  124. rtc_use_h264 =
  125. proprietary_codecs && !is_android && !is_ios && !(is_win && !is_clang)
  126. # By default, use normal platform audio support or dummy audio, but don't
  127. # use file-based audio playout and record.
  128. rtc_use_dummy_audio_file_devices = false
  129. # When set to true, replace the audio output with a sinus tone at 440Hz.
  130. # The ADM will ask for audio data from WebRTC but instead of reading real
  131. # audio samples from NetEQ, a sinus tone will be generated and replace the
  132. # real audio samples.
  133. rtc_audio_device_plays_sinus_tone = false
  134. if (is_ios) {
  135. # Build broadcast extension in AppRTCMobile for iOS. This results in the
  136. # binary only running on iOS 11+, which is why it is disabled by default.
  137. rtc_apprtcmobile_broadcast_extension = false
  138. }
  139. # Determines whether Metal is available on iOS/macOS.
  140. rtc_use_metal_rendering = is_mac || (is_ios && current_cpu == "arm64")
  141. # When set to false, builtin audio encoder/decoder factories and all the
  142. # audio codecs they depend on will not be included in libwebrtc.{a|lib}
  143. # (they will still be included in libjingle_peerconnection_so.so and
  144. # WebRTC.framework)
  145. rtc_include_builtin_audio_codecs = true
  146. # When set to false, builtin video encoder/decoder factories and all the
  147. # video codecs they depends on will not be included in libwebrtc.{a|lib}
  148. # (they will still be included in libjingle_peerconnection_so.so and
  149. # WebRTC.framework)
  150. rtc_include_builtin_video_codecs = true
  151. # When set to true and in a standalone build, it will undefine UNICODE and
  152. # _UNICODE (which are always defined globally by the Chromium Windows
  153. # toolchain).
  154. # This is only needed for testing purposes, WebRTC wants to be sure it
  155. # doesn't assume /DUNICODE and /D_UNICODE but that it explicitly uses
  156. # wide character functions.
  157. rtc_win_undef_unicode = false
  158. }
  159. if (!build_with_mozilla) {
  160. import("//testing/test.gni")
  161. }
  162. # A second declare_args block, so that declarations within it can
  163. # depend on the possibly overridden variables in the first
  164. # declare_args block.
  165. declare_args() {
  166. # Enables the use of protocol buffers for debug recordings.
  167. rtc_enable_protobuf = !build_with_mozilla
  168. # Set this to disable building with support for SCTP data channels.
  169. rtc_enable_sctp = !build_with_mozilla
  170. # Disable these to not build components which can be externally provided.
  171. rtc_build_json = !build_with_mozilla
  172. rtc_build_libsrtp = !build_with_mozilla
  173. rtc_build_libvpx = !build_with_mozilla
  174. rtc_libvpx_build_vp9 = !build_with_mozilla
  175. rtc_build_opus = !build_with_mozilla
  176. rtc_build_ssl = !build_with_mozilla
  177. rtc_build_usrsctp = !build_with_mozilla
  178. # Enable libevent task queues on platforms that support it.
  179. if (is_win || is_mac || is_ios || is_nacl || is_fuchsia ||
  180. target_cpu == "wasm") {
  181. rtc_enable_libevent = false
  182. rtc_build_libevent = false
  183. } else {
  184. rtc_enable_libevent = true
  185. rtc_build_libevent = !build_with_mozilla
  186. }
  187. # Build sources requiring GTK. NOTICE: This is not present in Chrome OS
  188. # build environments, even if available for Chromium builds.
  189. rtc_use_gtk = !build_with_chromium && !build_with_mozilla
  190. # Excluded in Chromium since its prerequisites don't require Pulse Audio.
  191. rtc_include_pulse_audio = !build_with_chromium
  192. # Chromium uses its own IO handling, so the internal ADM is only built for
  193. # standalone WebRTC.
  194. rtc_include_internal_audio_device = !build_with_chromium
  195. # Include tests in standalone checkout.
  196. rtc_include_tests = !build_with_chromium && !build_with_mozilla
  197. # Set this to false to skip building code that also requires X11 extensions
  198. # such as Xdamage, Xfixes.
  199. rtc_use_x11_extensions = rtc_use_x11
  200. }
  201. # Make it possible to provide custom locations for some libraries (move these
  202. # up into declare_args should we need to actually use them for the GN build).
  203. rtc_libvpx_dir = "//third_party/libvpx"
  204. rtc_opus_dir = "//third_party/opus"
  205. # Desktop capturer is supported only on Windows, OSX and Linux.
  206. rtc_desktop_capture_supported =
  207. (is_win && current_os != "winuwp") || is_mac ||
  208. (is_linux && (rtc_use_x11_extensions || rtc_use_pipewire))
  209. ###############################################################################
  210. # Templates
  211. #
  212. # Points to // in webrtc stand-alone or to //third_party/webrtc/ in
  213. # chromium.
  214. # We need absolute paths for all configs in templates as they are shared in
  215. # different subdirectories.
  216. webrtc_root = get_path_info(".", "abspath")
  217. # Global configuration that should be applied to all WebRTC targets.
  218. # You normally shouldn't need to include this in your target as it's
  219. # automatically included when using the rtc_* templates.
  220. # It sets defines, include paths and compilation warnings accordingly,
  221. # both for WebRTC stand-alone builds and for the scenario when WebRTC
  222. # native code is built as part of Chromium.
  223. rtc_common_configs = [
  224. webrtc_root + ":common_config",
  225. "//build/config/compiler:no_size_t_to_int_warning",
  226. ]
  227. if (is_mac || is_ios) {
  228. rtc_common_configs += [ "//build/config/compiler:enable_arc" ]
  229. }
  230. # Global public configuration that should be applied to all WebRTC targets. You
  231. # normally shouldn't need to include this in your target as it's automatically
  232. # included when using the rtc_* templates. It set the defines, include paths and
  233. # compilation warnings that should be propagated to dependents of the targets
  234. # depending on the target having this config.
  235. rtc_common_inherited_config = webrtc_root + ":common_inherited_config"
  236. # Common configs to remove or add in all rtc targets.
  237. rtc_remove_configs = []
  238. if (!build_with_chromium && is_clang) {
  239. rtc_remove_configs += [ "//build/config/clang:find_bad_constructs" ]
  240. }
  241. rtc_add_configs = rtc_common_configs
  242. rtc_prod_configs = [ webrtc_root + ":rtc_prod_config" ]
  243. rtc_library_impl_config = [ webrtc_root + ":library_impl_config" ]
  244. set_defaults("rtc_test") {
  245. configs = rtc_add_configs
  246. suppressed_configs = []
  247. }
  248. set_defaults("rtc_library") {
  249. configs = rtc_add_configs
  250. suppressed_configs = []
  251. }
  252. set_defaults("rtc_source_set") {
  253. configs = rtc_add_configs
  254. suppressed_configs = []
  255. }
  256. set_defaults("rtc_static_library") {
  257. configs = rtc_add_configs
  258. suppressed_configs = []
  259. }
  260. set_defaults("rtc_executable") {
  261. configs = rtc_add_configs
  262. suppressed_configs = []
  263. }
  264. set_defaults("rtc_shared_library") {
  265. configs = rtc_add_configs
  266. suppressed_configs = []
  267. }
  268. webrtc_default_visibility = [ webrtc_root + "/*" ]
  269. if (build_with_chromium) {
  270. # Allow Chromium's WebRTC overrides targets to bypass the regular
  271. # visibility restrictions.
  272. webrtc_default_visibility += [ webrtc_root + "/../webrtc_overrides/*" ]
  273. }
  274. # ---- Poisons ----
  275. #
  276. # The general idea is that some targets declare that they contain some
  277. # kind of poison, which makes it impossible for other targets to
  278. # depend on them (even transitively) unless they declare themselves
  279. # immune to that particular type of poison.
  280. #
  281. # Targets that *contain* poison of type foo should contain the line
  282. #
  283. # poisonous = [ "foo" ]
  284. #
  285. # and targets that *are immune but arent't themselves poisonous*
  286. # should contain
  287. #
  288. # allow_poison = [ "foo" ]
  289. #
  290. # This useful in cases where we have some large target or set of
  291. # targets and want to ensure that most other targets do not
  292. # transitively depend on them. For example, almost no high-level
  293. # target should depend on the audio codecs, since we want WebRTC users
  294. # to be able to inject any subset of them and actually end up with a
  295. # binary that doesn't include the codecs they didn't inject.
  296. #
  297. # Test-only targets (`testonly` set to true) and non-public targets
  298. # (`visibility` not containing "*") are automatically immune to all
  299. # types of poison.
  300. #
  301. # Here's the complete list of all types of poison. It must be kept in
  302. # 1:1 correspondence with the set of //:poison_* targets.
  303. #
  304. all_poison_types = [
  305. # Encoders and decoders for specific audio codecs such as Opus and iSAC.
  306. "audio_codecs",
  307. # Software video codecs (VP8 and VP9 through libvpx).
  308. "software_video_codecs",
  309. # Default task queue implementation.
  310. "default_task_queue",
  311. ]
  312. absl_include_config = "//third_party/abseil-cpp:absl_include_config"
  313. absl_define_config = "//third_party/abseil-cpp:absl_define_config"
  314. # Abseil Flags are testonly, so this config will only be applied to WebRTC targets
  315. # that are testonly.
  316. absl_flags_config = webrtc_root + ":absl_flags_configs"
  317. template("rtc_test") {
  318. test(target_name) {
  319. forward_variables_from(invoker,
  320. "*",
  321. [
  322. "configs",
  323. "public_configs",
  324. "suppressed_configs",
  325. "visibility",
  326. ])
  327. # Always override to public because when target_os is Android the `test`
  328. # template can override it to [ "*" ] and we want to avoid conditional
  329. # visibility.
  330. visibility = [ "*" ]
  331. configs += invoker.configs
  332. configs -= rtc_remove_configs
  333. configs -= invoker.suppressed_configs
  334. public_configs = [
  335. rtc_common_inherited_config,
  336. absl_include_config,
  337. absl_define_config,
  338. absl_flags_config,
  339. ]
  340. if (defined(invoker.public_configs)) {
  341. public_configs += invoker.public_configs
  342. }
  343. if (!build_with_chromium && is_android) {
  344. android_manifest = webrtc_root + "test/android/AndroidManifest.xml"
  345. min_sdk_version = 16
  346. deps += [ webrtc_root + "test:native_test_java" ]
  347. }
  348. }
  349. }
  350. template("rtc_source_set") {
  351. source_set(target_name) {
  352. forward_variables_from(invoker,
  353. "*",
  354. [
  355. "configs",
  356. "public_configs",
  357. "suppressed_configs",
  358. "visibility",
  359. ])
  360. forward_variables_from(invoker, [ "visibility" ])
  361. if (!defined(visibility)) {
  362. visibility = webrtc_default_visibility
  363. }
  364. # What's your poison?
  365. if (defined(testonly) && testonly) {
  366. assert(!defined(poisonous))
  367. assert(!defined(allow_poison))
  368. } else {
  369. if (!defined(poisonous)) {
  370. poisonous = []
  371. }
  372. if (!defined(allow_poison)) {
  373. allow_poison = []
  374. }
  375. if (!defined(assert_no_deps)) {
  376. assert_no_deps = []
  377. }
  378. if (!defined(deps)) {
  379. deps = []
  380. }
  381. foreach(p, poisonous) {
  382. deps += [ webrtc_root + ":poison_" + p ]
  383. }
  384. foreach(poison_type, all_poison_types) {
  385. allow_dep = true
  386. foreach(v, visibility) {
  387. if (v == "*") {
  388. allow_dep = false
  389. }
  390. }
  391. foreach(p, allow_poison + poisonous) {
  392. if (p == poison_type) {
  393. allow_dep = true
  394. }
  395. }
  396. if (!allow_dep) {
  397. assert_no_deps += [ webrtc_root + ":poison_" + poison_type ]
  398. }
  399. }
  400. }
  401. if (!defined(testonly) || !testonly) {
  402. configs += rtc_prod_configs
  403. }
  404. configs += invoker.configs
  405. configs += rtc_library_impl_config
  406. configs -= rtc_remove_configs
  407. configs -= invoker.suppressed_configs
  408. public_configs = [
  409. rtc_common_inherited_config,
  410. absl_include_config,
  411. absl_define_config,
  412. ]
  413. if (defined(testonly) && testonly) {
  414. public_configs += [ absl_flags_config ]
  415. }
  416. if (defined(invoker.public_configs)) {
  417. public_configs += invoker.public_configs
  418. }
  419. }
  420. }
  421. template("rtc_static_library") {
  422. static_library(target_name) {
  423. forward_variables_from(invoker,
  424. "*",
  425. [
  426. "configs",
  427. "public_configs",
  428. "suppressed_configs",
  429. "visibility",
  430. ])
  431. forward_variables_from(invoker, [ "visibility" ])
  432. if (!defined(visibility)) {
  433. visibility = webrtc_default_visibility
  434. }
  435. # What's your poison?
  436. if (defined(testonly) && testonly) {
  437. assert(!defined(poisonous))
  438. assert(!defined(allow_poison))
  439. } else {
  440. if (!defined(poisonous)) {
  441. poisonous = []
  442. }
  443. if (!defined(allow_poison)) {
  444. allow_poison = []
  445. }
  446. if (!defined(assert_no_deps)) {
  447. assert_no_deps = []
  448. }
  449. if (!defined(deps)) {
  450. deps = []
  451. }
  452. foreach(p, poisonous) {
  453. deps += [ webrtc_root + ":poison_" + p ]
  454. }
  455. foreach(poison_type, all_poison_types) {
  456. allow_dep = true
  457. foreach(v, visibility) {
  458. if (v == "*") {
  459. allow_dep = false
  460. }
  461. }
  462. foreach(p, allow_poison + poisonous) {
  463. if (p == poison_type) {
  464. allow_dep = true
  465. }
  466. }
  467. if (!allow_dep) {
  468. assert_no_deps += [ webrtc_root + ":poison_" + poison_type ]
  469. }
  470. }
  471. }
  472. if (!defined(testonly) || !testonly) {
  473. configs += rtc_prod_configs
  474. }
  475. configs += invoker.configs
  476. configs += rtc_library_impl_config
  477. configs -= rtc_remove_configs
  478. configs -= invoker.suppressed_configs
  479. public_configs = [
  480. rtc_common_inherited_config,
  481. absl_include_config,
  482. absl_define_config,
  483. ]
  484. if (defined(testonly) && testonly) {
  485. public_configs += [ absl_flags_config ]
  486. }
  487. if (defined(invoker.public_configs)) {
  488. public_configs += invoker.public_configs
  489. }
  490. }
  491. }
  492. # This template automatically switches the target type between source_set
  493. # and static_library.
  494. #
  495. # This should be the default target type for all the WebRTC targets with
  496. # one exception. Do not use this template for header only targets, in that case
  497. # rtc_source_set must be used in order to avoid build errors (e.g. libtool
  498. # complains if the output .a file is empty).
  499. #
  500. # How does it work:
  501. # Since all files in a source_set are linked into a final binary, while files
  502. # in a static library are only linked in if at least one symbol in them is
  503. # referenced, in component builds source_sets are easy to deal with because
  504. # all their object files are passed to the linker to create a shared library.
  505. # In release builds instead, static_libraries are preferred since they allow
  506. # the linker to discard dead code.
  507. # For the same reason, testonly targets will always be expanded to
  508. # source_set in order to be sure that tests are present in the test binary.
  509. template("rtc_library") {
  510. if (is_component_build || (defined(invoker.testonly) && invoker.testonly)) {
  511. target_type = "source_set"
  512. } else {
  513. target_type = "static_library"
  514. }
  515. target(target_type, target_name) {
  516. forward_variables_from(invoker,
  517. "*",
  518. [
  519. "configs",
  520. "public_configs",
  521. "suppressed_configs",
  522. "visibility",
  523. ])
  524. forward_variables_from(invoker, [ "visibility" ])
  525. if (!defined(visibility)) {
  526. visibility = webrtc_default_visibility
  527. }
  528. # What's your poison?
  529. if (defined(testonly) && testonly) {
  530. assert(!defined(poisonous))
  531. assert(!defined(allow_poison))
  532. } else {
  533. if (!defined(poisonous)) {
  534. poisonous = []
  535. }
  536. if (!defined(allow_poison)) {
  537. allow_poison = []
  538. }
  539. if (!defined(assert_no_deps)) {
  540. assert_no_deps = []
  541. }
  542. if (!defined(deps)) {
  543. deps = []
  544. }
  545. foreach(p, poisonous) {
  546. deps += [ webrtc_root + ":poison_" + p ]
  547. }
  548. foreach(poison_type, all_poison_types) {
  549. allow_dep = true
  550. foreach(v, visibility) {
  551. if (v == "*") {
  552. allow_dep = false
  553. }
  554. }
  555. foreach(p, allow_poison + poisonous) {
  556. if (p == poison_type) {
  557. allow_dep = true
  558. }
  559. }
  560. if (!allow_dep) {
  561. assert_no_deps += [ webrtc_root + ":poison_" + poison_type ]
  562. }
  563. }
  564. }
  565. if (!defined(testonly) || !testonly) {
  566. configs += rtc_prod_configs
  567. }
  568. configs += invoker.configs
  569. configs += rtc_library_impl_config
  570. configs -= rtc_remove_configs
  571. configs -= invoker.suppressed_configs
  572. public_configs = [
  573. rtc_common_inherited_config,
  574. absl_include_config,
  575. absl_define_config,
  576. ]
  577. if (defined(testonly) && testonly) {
  578. public_configs += [ absl_flags_config ]
  579. }
  580. if (defined(invoker.public_configs)) {
  581. public_configs += invoker.public_configs
  582. }
  583. }
  584. }
  585. template("rtc_executable") {
  586. executable(target_name) {
  587. forward_variables_from(invoker,
  588. "*",
  589. [
  590. "deps",
  591. "configs",
  592. "public_configs",
  593. "suppressed_configs",
  594. "visibility",
  595. ])
  596. forward_variables_from(invoker, [ "visibility" ])
  597. if (!defined(visibility)) {
  598. visibility = webrtc_default_visibility
  599. }
  600. configs += invoker.configs
  601. configs -= rtc_remove_configs
  602. configs -= invoker.suppressed_configs
  603. deps = invoker.deps
  604. public_configs = [
  605. rtc_common_inherited_config,
  606. absl_include_config,
  607. absl_define_config,
  608. ]
  609. if (defined(testonly) && testonly) {
  610. public_configs += [ absl_flags_config ]
  611. }
  612. if (defined(invoker.public_configs)) {
  613. public_configs += invoker.public_configs
  614. }
  615. if (is_win) {
  616. deps += [
  617. # Give executables the default manifest on Windows (a no-op elsewhere).
  618. "//build/win:default_exe_manifest",
  619. ]
  620. }
  621. }
  622. }
  623. template("rtc_shared_library") {
  624. shared_library(target_name) {
  625. forward_variables_from(invoker,
  626. "*",
  627. [
  628. "configs",
  629. "public_configs",
  630. "suppressed_configs",
  631. "visibility",
  632. ])
  633. forward_variables_from(invoker, [ "visibility" ])
  634. if (!defined(visibility)) {
  635. visibility = webrtc_default_visibility
  636. }
  637. # What's your poison?
  638. if (defined(testonly) && testonly) {
  639. assert(!defined(poisonous))
  640. assert(!defined(allow_poison))
  641. } else {
  642. if (!defined(poisonous)) {
  643. poisonous = []
  644. }
  645. if (!defined(allow_poison)) {
  646. allow_poison = []
  647. }
  648. if (!defined(assert_no_deps)) {
  649. assert_no_deps = []
  650. }
  651. if (!defined(deps)) {
  652. deps = []
  653. }
  654. foreach(p, poisonous) {
  655. deps += [ webrtc_root + ":poison_" + p ]
  656. }
  657. foreach(poison_type, all_poison_types) {
  658. allow_dep = true
  659. foreach(v, visibility) {
  660. if (v == "*") {
  661. allow_dep = false
  662. }
  663. }
  664. foreach(p, allow_poison + poisonous) {
  665. if (p == poison_type) {
  666. allow_dep = true
  667. }
  668. }
  669. if (!allow_dep) {
  670. assert_no_deps += [ webrtc_root + ":poison_" + poison_type ]
  671. }
  672. }
  673. }
  674. configs += invoker.configs
  675. configs -= rtc_remove_configs
  676. configs -= invoker.suppressed_configs
  677. public_configs = [
  678. rtc_common_inherited_config,
  679. absl_include_config,
  680. absl_define_config,
  681. ]
  682. if (defined(testonly) && testonly) {
  683. public_configs += [ absl_flags_config ]
  684. }
  685. if (defined(invoker.public_configs)) {
  686. public_configs += invoker.public_configs
  687. }
  688. }
  689. }
  690. if (is_ios) {
  691. set_defaults("rtc_ios_xctest_test") {
  692. configs = rtc_add_configs
  693. suppressed_configs = []
  694. }
  695. template("rtc_ios_xctest_test") {
  696. ios_xctest_test(target_name) {
  697. forward_variables_from(invoker,
  698. "*",
  699. [
  700. "configs",
  701. "public_configs",
  702. "suppressed_configs",
  703. "visibility",
  704. ])
  705. forward_variables_from(invoker, [ "visibility" ])
  706. if (!defined(visibility)) {
  707. visibility = webrtc_default_visibility
  708. }
  709. configs += invoker.configs
  710. configs -= rtc_remove_configs
  711. configs -= invoker.suppressed_configs
  712. public_configs = [ rtc_common_inherited_config ]
  713. if (defined(invoker.public_configs)) {
  714. public_configs += invoker.public_configs
  715. }
  716. }
  717. }
  718. # TODO: Generate module.modulemap file to enable use in Swift
  719. # projects. See "mac_framework_bundle_with_umbrella_header".
  720. template("ios_framework_bundle_with_umbrella_header") {
  721. forward_variables_from(invoker, [ "output_name" ])
  722. umbrella_header_path =
  723. "$target_gen_dir/$output_name.framework/Headers/$output_name.h"
  724. ios_framework_bundle(target_name) {
  725. forward_variables_from(invoker, "*", [])
  726. deps += [ ":copy_umbrella_header_$target_name" ]
  727. }
  728. action("umbrella_header_$target_name") {
  729. forward_variables_from(invoker, [ "public_headers" ])
  730. script = "//tools_webrtc/ios/generate_umbrella_header.py"
  731. outputs = [
  732. umbrella_header_path,
  733. ]
  734. args = [
  735. "--out",
  736. rebase_path(umbrella_header_path, root_build_dir),
  737. "--sources",
  738. ] + public_headers
  739. }
  740. copy("copy_umbrella_header_$target_name") {
  741. sources = [
  742. umbrella_header_path,
  743. ]
  744. outputs = [
  745. "$root_out_dir/$output_name.framework/Headers/$output_name.h",
  746. ]
  747. deps = [
  748. ":umbrella_header_$target_name",
  749. ]
  750. }
  751. }
  752. set_defaults("ios_framework_bundle_with_umbrella_header") {
  753. configs = default_shared_library_configs
  754. }
  755. }
  756. if (is_mac) {
  757. template("mac_framework_bundle_with_umbrella_header") {
  758. forward_variables_from(invoker, [ "output_name" ])
  759. this_target_name = target_name
  760. umbrella_header_path = "$target_gen_dir/umbrella_header/$output_name.h"
  761. modulemap_path = "$target_gen_dir/Modules/module.modulemap"
  762. mac_framework_bundle(target_name) {
  763. forward_variables_from(invoker, "*", [ "configs" ])
  764. if (defined(invoker.configs)) {
  765. configs += invoker.configs
  766. }
  767. framework_version = "A"
  768. framework_contents = [
  769. "Headers",
  770. "Modules",
  771. "Resources",
  772. ]
  773. ldflags = [
  774. "-all_load",
  775. "-install_name",
  776. "@rpath/$output_name.framework/$output_name",
  777. ]
  778. deps += [
  779. ":copy_framework_headers_$this_target_name",
  780. ":copy_modulemap_$this_target_name",
  781. ":copy_umbrella_header_$this_target_name",
  782. ":modulemap_$this_target_name",
  783. ":umbrella_header_$this_target_name",
  784. ]
  785. }
  786. bundle_data("copy_framework_headers_$this_target_name") {
  787. forward_variables_from(invoker, [ "sources" ])
  788. outputs = [
  789. "{{bundle_contents_dir}}/Headers/{{source_file_part}}",
  790. ]
  791. }
  792. action("modulemap_$this_target_name") {
  793. script = "//tools_webrtc/ios/generate_modulemap.py"
  794. args = [
  795. "--out",
  796. rebase_path(modulemap_path, root_build_dir),
  797. "--name",
  798. output_name,
  799. ]
  800. outputs = [
  801. modulemap_path,
  802. ]
  803. }
  804. bundle_data("copy_modulemap_$this_target_name") {
  805. sources = [
  806. modulemap_path,
  807. ]
  808. outputs = [
  809. "{{bundle_contents_dir}}/Modules/module.modulemap",
  810. ]
  811. deps = [
  812. ":modulemap_$this_target_name",
  813. ]
  814. }
  815. action("umbrella_header_$this_target_name") {
  816. forward_variables_from(invoker, [ "sources" ])
  817. script = "//tools_webrtc/ios/generate_umbrella_header.py"
  818. outputs = [
  819. umbrella_header_path,
  820. ]
  821. args = [
  822. "--out",
  823. rebase_path(umbrella_header_path, root_build_dir),
  824. "--sources",
  825. ] + sources
  826. }
  827. bundle_data("copy_umbrella_header_$this_target_name") {
  828. sources = [
  829. umbrella_header_path,
  830. ]
  831. outputs = [
  832. "{{bundle_contents_dir}}/Headers/$output_name.h",
  833. ]
  834. deps = [
  835. ":umbrella_header_$this_target_name",
  836. ]
  837. }
  838. }
  839. }
  840. if (is_android) {
  841. template("rtc_android_library") {
  842. android_library(target_name) {
  843. forward_variables_from(invoker,
  844. "*",
  845. [
  846. "configs",
  847. "public_configs",
  848. "suppressed_configs",
  849. "visibility",
  850. ])
  851. errorprone_args = []
  852. # Treat warnings as errors.
  853. errorprone_args += [ "-Werror" ]
  854. # WebRTC supports API level 16 while Chromium only supports 19.
  855. # (the manifest defines minimum supported SDK version)
  856. if (defined(invoker.min_sdk_version)) {
  857. min_sdk_version = invoker.min_sdk_version
  858. } else {
  859. min_sdk_version = 16
  860. }
  861. # TODO(crbug.com/824679): Find out why this fails in Chromium
  862. if (!build_with_chromium) {
  863. errorprone_args += [
  864. "-Xep:ParameterNotNullable:ERROR",
  865. "-Xep:FieldMissingNullable:ERROR",
  866. "-Xep:ReturnMissingNullable:ERROR",
  867. ]
  868. }
  869. # Add any arguments defined by the invoker.
  870. if (defined(invoker.errorprone_args)) {
  871. errorprone_args += invoker.errorprone_args
  872. }
  873. if (!defined(deps)) {
  874. deps = []
  875. }
  876. no_build_hooks = true
  877. }
  878. }
  879. template("rtc_android_apk") {
  880. android_apk(target_name) {
  881. forward_variables_from(invoker,
  882. "*",
  883. [
  884. "configs",
  885. "public_configs",
  886. "suppressed_configs",
  887. "visibility",
  888. ])
  889. # Treat warnings as errors.
  890. errorprone_args = [ "-Werror" ]
  891. # TODO(crbug.com/824679): Find out why this fails in Chromium
  892. if (!build_with_chromium) {
  893. errorprone_args += [
  894. "-Xep:ParameterNotNullable:ERROR",
  895. "-Xep:FieldMissingNullable:ERROR",
  896. "-Xep:ReturnMissingNullable:ERROR",
  897. ]
  898. }
  899. if (!defined(deps)) {
  900. deps = []
  901. }
  902. no_build_hooks = true
  903. }
  904. }
  905. template("rtc_instrumentation_test_apk") {
  906. instrumentation_test_apk(target_name) {
  907. forward_variables_from(invoker,
  908. "*",
  909. [
  910. "configs",
  911. "public_configs",
  912. "suppressed_configs",
  913. "visibility",
  914. ])
  915. # Treat warnings as errors.
  916. errorprone_args = [ "-Werror" ]
  917. # TODO(crbug.com/824679): Find out why this fails in Chromium
  918. if (!build_with_chromium) {
  919. errorprone_args += [
  920. "-Xep:ParameterNotNullable:ERROR",
  921. "-Xep:FieldMissingNullable:ERROR",
  922. "-Xep:ReturnMissingNullable:ERROR",
  923. ]
  924. }
  925. if (!defined(deps)) {
  926. deps = []
  927. }
  928. no_build_hooks = true
  929. }
  930. }
  931. }