Merge GN templates for iOS and MacOS framework creation
The two GN templates are nearly identical, so merge them to reduce
maintenance.
Bug: webrtc:13949
Change-Id: I5f53ade5f9d09ce6f23a6cb29c9d39df4485a237
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/258380
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Commit-Queue: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com>
Cr-Commit-Position: refs/heads/main@{#36495}
diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn
index 763f3ee..0f23dd9 100644
--- a/sdk/BUILD.gn
+++ b/sdk/BUILD.gn
@@ -1244,7 +1244,7 @@
}
if (is_ios) {
- ios_framework_bundle_with_umbrella_header("framework_objc") {
+ apple_framework_bundle_with_umbrella_header("framework_objc") {
info_plist = "objc/Info.plist"
output_name = "WebRTC"
@@ -1381,7 +1381,7 @@
"CoreMedia.framework",
]
- configs += [
+ configs = [
"..:common_objc",
":used_from_extension",
]
@@ -1397,7 +1397,7 @@
}
if (is_mac) {
- mac_framework_bundle_with_umbrella_header("mac_framework_objc") {
+ apple_framework_bundle_with_umbrella_header("mac_framework_objc") {
info_plist = "objc/Info.plist"
output_name = "WebRTC"
diff --git a/webrtc.gni b/webrtc.gni
index 3a72106..a5da76c 100644
--- a/webrtc.gni
+++ b/webrtc.gni
@@ -960,14 +960,13 @@
}
}
-if (is_ios) {
- # TODO: Generate module.modulemap file to enable use in Swift
- # projects. See "mac_framework_bundle_with_umbrella_header".
- template("ios_framework_bundle_with_umbrella_header") {
+if (is_mac || is_ios) {
+ template("apple_framework_bundle_with_umbrella_header") {
forward_variables_from(invoker, [ "output_name" ])
this_target_name = target_name
umbrella_header_path =
"$target_gen_dir/$output_name.framework/WebRTC/$output_name.h"
+ modulemap_path = "$target_gen_dir/Modules/module.modulemap"
action_foreach("create_bracket_include_headers_$target_name") {
script = "//tools_webrtc/apple/copy_framework_header.py"
@@ -985,102 +984,63 @@
]
}
- ios_framework_bundle(target_name) {
- forward_variables_from(invoker, "*", [ "public_headers" ])
- public_headers = get_target_outputs(
- ":create_bracket_include_headers_$this_target_name")
- deps += [
- ":copy_umbrella_header_$target_name",
- ":create_bracket_include_headers_$target_name",
- ]
+ if (is_mac) {
+ mac_framework_bundle(target_name) {
+ forward_variables_from(invoker, "*", [ "configs" ])
+ if (defined(invoker.configs)) {
+ configs += invoker.configs
+ }
+
+ framework_version = "A"
+ framework_contents = [
+ "Headers",
+ "Modules",
+ "Resources",
+ ]
+
+ ldflags = [
+ "-all_load",
+ "-install_name",
+ "@rpath/$output_name.framework/$output_name",
+ ]
+
+ deps += [
+ ":copy_framework_headers_$this_target_name",
+ ":copy_modulemap_$this_target_name",
+ ":copy_umbrella_header_$this_target_name",
+ ":create_bracket_include_headers_$this_target_name",
+ ":modulemap_$this_target_name",
+ ":umbrella_header_$this_target_name",
+ ]
+ }
+ }
+ if (is_ios) {
+ ios_framework_bundle(target_name) {
+ forward_variables_from(invoker,
+ "*",
+ [
+ "configs",
+ "public_headers",
+ ])
+ if (defined(invoker.configs)) {
+ configs += invoker.configs
+ }
+ public_headers = get_target_outputs(
+ ":create_bracket_include_headers_$this_target_name")
+
+ deps += [
+ ":copy_umbrella_header_$this_target_name",
+ ":create_bracket_include_headers_$this_target_name",
+ ]
+ }
}
- action("umbrella_header_$target_name") {
- public_headers = get_target_outputs(
- ":create_bracket_include_headers_$this_target_name")
-
- script = "//tools_webrtc/ios/generate_umbrella_header.py"
-
- outputs = [ umbrella_header_path ]
- args = [
- "--out",
- rebase_path(umbrella_header_path, root_build_dir),
- "--sources",
- ] + public_headers
- deps = [ ":create_bracket_include_headers_$this_target_name" ]
- }
-
- if (target_environment == "catalyst") {
+ if (is_mac || target_environment == "catalyst") {
# Catalyst frameworks use the same layout as regular Mac frameworks.
headers_dir = "Versions/A/Headers"
} else {
headers_dir = "Headers"
}
- copy("copy_umbrella_header_$target_name") {
- sources = [ umbrella_header_path ]
- outputs =
- [ "$root_out_dir/$output_name.framework/$headers_dir/$output_name.h" ]
-
- deps = [ ":umbrella_header_$target_name" ]
- }
- }
-
- set_defaults("ios_framework_bundle_with_umbrella_header") {
- configs = default_shared_library_configs
- }
-}
-
-if (is_mac) {
- template("mac_framework_bundle_with_umbrella_header") {
- forward_variables_from(invoker, [ "output_name" ])
- this_target_name = target_name
- umbrella_header_path = "$target_gen_dir/umbrella_header/$output_name.h"
- modulemap_path = "$target_gen_dir/Modules/module.modulemap"
-
- mac_framework_bundle(target_name) {
- forward_variables_from(invoker, "*", [ "configs" ])
- if (defined(invoker.configs)) {
- configs += invoker.configs
- }
-
- framework_version = "A"
- framework_contents = [
- "Headers",
- "Modules",
- "Resources",
- ]
-
- ldflags = [
- "-all_load",
- "-install_name",
- "@rpath/$output_name.framework/$output_name",
- ]
-
- deps += [
- ":copy_framework_headers_$this_target_name",
- ":copy_modulemap_$this_target_name",
- ":copy_umbrella_header_$this_target_name",
- ":create_bracket_include_headers_$this_target_name",
- ":modulemap_$this_target_name",
- ":umbrella_header_$this_target_name",
- ]
- }
-
- action_foreach("create_bracket_include_headers_$this_target_name") {
- script = "//tools_webrtc/apple/copy_framework_header.py"
- sources = invoker.sources
- output_name = invoker.output_name
- outputs = [
- "$target_gen_dir/$output_name.framework/WebRTC/{{source_file_part}}",
- ]
- args = [
- "--input",
- "{{source}}",
- "--output",
- rebase_path(target_gen_dir, root_build_dir) +
- "/$output_name.framework/WebRTC/{{source_file_part}}",
- ]
- }
bundle_data("copy_framework_headers_$this_target_name") {
sources = get_target_outputs(
@@ -1122,11 +1082,12 @@
deps = [ ":create_bracket_include_headers_$this_target_name" ]
}
- bundle_data("copy_umbrella_header_$this_target_name") {
+ copy("copy_umbrella_header_$target_name") {
sources = [ umbrella_header_path ]
- outputs = [ "{{bundle_contents_dir}}/Headers/$output_name.h" ]
+ outputs =
+ [ "$root_out_dir/$output_name.framework/$headers_dir/$output_name.h" ]
- deps = [ ":umbrella_header_$this_target_name" ]
+ deps = [ ":umbrella_header_$target_name" ]
}
}
}