diff --git a/module-template/CMakeLists.txt b/module-template/CMakeLists.txt index 2757a8d96d..3b00450722 100644 --- a/module-template/CMakeLists.txt +++ b/module-template/CMakeLists.txt @@ -130,8 +130,22 @@ if(NOT RECOMPCORE_MODULE_OPT_LEVEL MATCHES "^[0-3]$") endif() if(RECOMPCORE_MODULE_ENABLE_IPO AND CMAKE_C_COMPILER_ID MATCHES "Clang") include(CheckIPOSupported) + # moderngekko-port configures with CMAKE_NINJA_FORCE_RESPONSE_FILE=1, which the + # module needs: it links thousands of chunk objects and the command line does + # not fit in ARG_MAX. But check_ipo_supported's try-compile inherits the + # environment, and its static-library step then runs `ar qc libfoo.a @foo.rsp` + # -- Apple's /usr/bin/ar has no @file support, so the check fails with + # "ar: @CMakeFiles/foo.rsp: No such file or directory" and IPO is silently + # disabled. The manifest still records -flto=thin. Every module built this way + # had NO cross-translation-unit inlining. Scope the variable off for the check + # only, then restore it before the generator reads it. + set(_module_forced_rsp "$ENV{CMAKE_NINJA_FORCE_RESPONSE_FILE}") + unset(ENV{CMAKE_NINJA_FORCE_RESPONSE_FILE}) check_ipo_supported(RESULT RECOMPCORE_MODULE_IPO_SUPPORTED OUTPUT RECOMPCORE_MODULE_IPO_ERROR LANGUAGES C) + if(_module_forced_rsp) + set(ENV{CMAKE_NINJA_FORCE_RESPONSE_FILE} "${_module_forced_rsp}") + endif() if(RECOMPCORE_MODULE_IPO_SUPPORTED) set_property(TARGET ${MODULE_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) else()