build(cmake): silence benign macOS ranlib and ld warnings

POSIX/SITL builds on macOS produce two classes of benign warnings that
clutter output and obscure real issues:

  ranlib: warning: 'lib*.a(foo.o)' has no symbols
  ld: warning: ignoring duplicate libraries: ...

The ranlib warnings come from sources wrapped in #if defined(CONFIG_*)
guards (i2c.cpp, spi.cpp, board_common.c, pab_manifest.c,
px4_log_history.cpp) and dummy.cpp placeholders, which legitimately
compile to empty object files on POSIX. GNU ranlib ignores this;
Apple's warns. The warning is emitted by 'ar qc' (which implicitly
builds a symbol table), not by ranlib itself, so overriding only
ARCHIVE_FINISH is insufficient. Use 'ar qcS' to skip the implicit
symbol table, then let ranlib -no_warning_for_no_symbols build it
quietly via ARCHIVE_FINISH.

The duplicate-library warnings come from CMake intentionally
re-emitting static libraries on the link line to resolve circular
dependencies between px4_layer, px4_work_queue, px4_daemon and
lockstep_scheduler. GNU ld silently dedupes; Apple's ld-prime
(Xcode 15+) warns. Pass -no_warn_duplicate_libraries to the linker.

Both fixes are Darwin-only and have no effect on Linux CI or NuttX
builds.

Signed-off-by: Ramon Roche <mrpollo@gmail.com>
This commit is contained in:
Ramon Roche
2026-04-08 22:45:28 -06:00
parent 4c8c9a1e0f
commit c9f1d2ab0f
2 changed files with 28 additions and 0 deletions
+6
View File
@@ -225,6 +225,12 @@ function(px4_os_add_flags)
if(UNIX AND APPLE)
add_definitions(-D__PX4_DARWIN)
# Silence Apple ld warning about duplicate static libs. CMake intentionally
# re-emits them to resolve circular deps (px4_layer, px4_work_queue,
# px4_daemon, lockstep_scheduler). See also CMAKE_*_ARCHIVE_FINISH override
# at the top of the root CMakeLists.txt for the matching ranlib silence.
add_link_options(LINKER:-no_warn_duplicate_libraries)
elseif(CYGWIN)
add_definitions(
-D__PX4_CYGWIN