fix(cmake): don't pass -fno-fat-lto-objects on Apple GCC (#6114)
GCC on macOS has no linker plugin, so `-fno-fat-lto-objects` makes every
LTO probe fail and LTO is silently disabled. Plain `-flto=auto` works.
Fixes #6060
Assisted-by: ClaudeCode:claude-opus-5
Claude-Session: https://claude.ai/code/session_013JABmnjt9oAh29p1pytAB3
diff --git a/tools/pybind11Common.cmake b/tools/pybind11Common.cmake
index 1311d3f..f525270 100644
--- a/tools/pybind11Common.cmake
+++ b/tools/pybind11Common.cmake
@@ -353,7 +353,11 @@
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT APPLE)
# Clang Gold plugin does not support -Os; append -O3 to MinSizeRel builds to override it
set(linker_append ";$<$<CONFIG:MinSizeRel>:-O3>")
- elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT MINGW)
+ elseif(
+ CMAKE_CXX_COMPILER_ID MATCHES "GNU"
+ AND NOT MINGW
+ AND NOT APPLE)
+ # GCC on macOS has no linker plugin, which -fno-fat-lto-objects requires
set(cxx_append ";-fno-fat-lto-objects")
endif()