From 87b6e7beff41fa24a78daddc6e7ea1d1cc578132 Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Tue, 26 Apr 2022 02:22:35 +0200 Subject: [PATCH] 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 Reviewed-by: Mirko Bonadei Cr-Commit-Position: refs/heads/main@{#36687} --- webrtc.gni | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/webrtc.gni b/webrtc.gni index a5da76c6f9..d52497d151 100644 --- a/webrtc.gni +++ b/webrtc.gni @@ -727,10 +727,7 @@ template("rtc_static_library") { # This template automatically switches the target type between source_set # and static_library. # -# This should be the default target type for all the WebRTC targets with -# 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). +# This should be the default target type for all the WebRTC targets. # # How does it work: # 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 # source_set in order to be sure that tests are present in the test binary. 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" } else { target_type = "static_library"