An rtc_library with no source file should be an rtc_source_set

Bug: webrtc:9838
Change-Id: I9b8db581e3e180aff11ffc38b1c9155b2bd3671c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/260060
Commit-Queue: Florent Castelli <orphis@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36687}
This commit is contained in:
Florent Castelli 2022-04-26 02:22:35 +02:00 committed by WebRTC LUCI CQ
parent e890e36c99
commit 87b6e7beff

View File

@ -727,10 +727,7 @@ template("rtc_static_library") {
# This template automatically switches the target type between source_set # This template automatically switches the target type between source_set
# and static_library. # and static_library.
# #
# This should be the default target type for all the WebRTC targets with # This should be the default target type for all the WebRTC targets.
# one exception. Do not use this template for header only targets, in that case
# rtc_source_set must be used in order to avoid build errors (e.g. libtool
# complains if the output .a file is empty).
# #
# How does it work: # How does it work:
# Since all files in a source_set are linked into a final binary, while files # Since all files in a source_set are linked into a final binary, while files
@ -742,7 +739,23 @@ template("rtc_static_library") {
# For the same reason, testonly targets will always be expanded to # For the same reason, testonly targets will always be expanded to
# source_set in order to be sure that tests are present in the test binary. # source_set in order to be sure that tests are present in the test binary.
template("rtc_library") { template("rtc_library") {
if (is_component_build || (defined(invoker.testonly) && invoker.testonly)) { header_only = true
if (defined(invoker.sources)) {
non_header_sources = filter_exclude(invoker.sources,
[
"*.h",
"*.hh",
"*.inc",
])
if (non_header_sources != []) {
header_only = false
}
}
# Header only libraries should use source_set as a static_library with no
# source files will cause issues with macOS libtool.
if (header_only || is_component_build ||
(defined(invoker.testonly) && invoker.testonly)) {
target_type = "source_set" target_type = "source_set"
} else { } else {
target_type = "static_library" target_type = "static_library"