mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
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:
parent
4c8c9a1e0f
commit
c9f1d2ab0f
@ -229,6 +229,28 @@ endif()
|
||||
#
|
||||
project(px4 CXX C ASM)
|
||||
|
||||
# Silence Apple ranlib "has no symbols" warnings. Several PX4 sources are
|
||||
# wrapped in #if defined(CONFIG_*) guards (e.g. platforms/common/i2c.cpp,
|
||||
# spi.cpp, board_common.c, pab_manifest.c, px4_log_history.cpp) and some
|
||||
# libraries carry a dummy.cpp placeholder, all of which legitimately produce
|
||||
# empty object files on POSIX/SITL. GNU ranlib ignores this; Apple's warns.
|
||||
#
|
||||
# The warning is actually emitted by `ar qc` (which implicitly builds a symbol
|
||||
# table), not by the standalone ranlib call. So we use `ar qcS` to skip the
|
||||
# implicit symbol table, then let CMAKE_*_ARCHIVE_FINISH run ranlib with the
|
||||
# -no_warning_for_no_symbols flag to add it quietly.
|
||||
if(APPLE)
|
||||
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcS <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcS <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||
set(CMAKE_ASM_ARCHIVE_CREATE "<CMAKE_AR> qcS <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||
set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> qS <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||
set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> qS <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||
set(CMAKE_ASM_ARCHIVE_APPEND "<CMAKE_AR> qS <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||
set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
|
||||
set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
|
||||
set(CMAKE_ASM_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
|
||||
endif()
|
||||
|
||||
# CMake build type (Debug Release RelWithDebInfo MinSizeRel Coverage)
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
if(${PX4_PLATFORM} STREQUAL "nuttx")
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user