cmake/sitl: use CheckLinkerFlag instead of GCC version check for --no-warn-rwx-segments#11383
Conversation
…-warn-rwx-segments Replace the fragile CMAKE_COMPILER_IS_GNUCC + version threshold heuristic with a proper check_linker_flag() probe (available since CMake 3.18; SITL already requires 3.22+). The probe directly tests whether the linker accepts the flag rather than guessing based on compiler version.
Review Summary by QodoReplace GCC version check with CheckLinkerFlag probe
WalkthroughsDescription• Replace GCC version heuristic with proper linker capability probe • Use CMake's CheckLinkerFlag module for robust flag detection • Directly test linker support instead of guessing from compiler version Diagramflowchart LR
A["GCC version check<br/>CMAKE_COMPILER_IS_GNUCC"] -->|replaced| B["CheckLinkerFlag probe<br/>check_linker_flag()"]
B -->|tests linker support| C["LINKER_SUPPORTS_NO_RWX_WARNING"]
C -->|if true| D["Apply --no-warn-rwx-segments flag"]
File Changes1. cmake/sitl.cmake
|
Code Review by Qodo
1.
|
check_linker_flag() requires CMake 3.18. Use include(CheckLinkerFlag OPTIONAL) and if(COMMAND check_linker_flag) to probe for the module's availability rather than hardcoding a version number. On CMake < 3.18 the include silently does nothing, the guard skips the call, and LINKER_SUPPORTS_NO_RWX_WARNING is left unset — the flag is simply not added, which is safe because linkers old enough to ship with CMake < 3.18 do not produce the RWX warning anyway.
|
Test firmware build ready — commit Download firmware for PR #11383 223 targets built. Find your board's
|
Summary
Replace the fragile GCC version check for
--no-warn-rwx-segmentsincmake/sitl.cmakewith a properCheckLinkerFlagcapability probe.Changes
CMAKE_COMPILER_IS_GNUCC + VERSION_LESS 12.0heuristicinclude(CheckLinkerFlag)andcheck_linker_flag()probecheck_linker_flag()has been available since CMake 3.18; SITL already requires CMake 3.22+, so there is no minimum version concern.Testing
--no-warn-rwx-segmentsis not supported (ld < 2.39) and skipped the flag — build completed cleanly with no linker warnings or errors