diff --git a/CMakeLists.txt b/CMakeLists.txt index 0da4780d11..351a209c45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 " qcS ") + set(CMAKE_CXX_ARCHIVE_CREATE " qcS ") + set(CMAKE_ASM_ARCHIVE_CREATE " qcS ") + set(CMAKE_C_ARCHIVE_APPEND " qS ") + set(CMAKE_CXX_ARCHIVE_APPEND " qS ") + set(CMAKE_ASM_ARCHIVE_APPEND " qS ") + set(CMAKE_C_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") + set(CMAKE_CXX_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") + set(CMAKE_ASM_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") +endif() + # CMake build type (Debug Release RelWithDebInfo MinSizeRel Coverage) if(NOT CMAKE_BUILD_TYPE) if(${PX4_PLATFORM} STREQUAL "nuttx") diff --git a/platforms/posix/cmake/px4_impl_os.cmake b/platforms/posix/cmake/px4_impl_os.cmake index 49c3813bda..aceb7dde3a 100644 --- a/platforms/posix/cmake/px4_impl_os.cmake +++ b/platforms/posix/cmake/px4_impl_os.cmake @@ -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