NAG Fortran: Use -xldarg @ to pass response files to the linker

The `nagfor` compiler driver does not invoke the linker directly.
Instead it runs the system C compiler driver, which then invokes the
linker.  Passing `@` to NAG Fortran expands the response file before
it reaches the linker, which might lead to too long linker lines.
`-Wl,@`, used since commit 10d6c3a635 (NAG: Pass response files
through front-end to the linker, 2018-08-01, v3.13.0-rc1~244^2), can
lead to wrong placement of the response file on the linker line and
doesn't work at all when the response file is the only object file
passed to the NAG Fortran frontend.

Instead use `-xldarg @` to pass a response file through to the linker
without any intermediate expansion.  However, the response file
generated by Ninja can contain flags meant for the compiler driver,
so we need to disable response files for these flags altogether.

Fixes: #23577
This commit is contained in:
Simon Maertens
2026-05-05 19:18:02 +01:00
parent 6dc46638f4
commit 65fbe16e16

View File

@@ -44,8 +44,13 @@ set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixed")
set(CMAKE_Fortran_FORMAT_FREE_FLAG "-free")
set(CMAKE_Fortran_COMPILE_OPTIONS_PIC "-PIC")
set(CMAKE_Fortran_COMPILE_OPTIONS_PIE "-PIC")
set(CMAKE_Fortran_RESPONSE_FILE_LINK_FLAG "-Wl,@")
set(CMAKE_Fortran_RESPONSE_FILE_ARCHIVE_FLAG "@")
if(CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2)
set(CMAKE_Fortran_RESPONSE_FILE_LINK_FLAG "-xldarg @")
set(CMAKE_Fortran_RESPONSE_FILE_ARCHIVE_FLAG "@")
set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
else()
set(CMAKE_Fortran_RESPONSE_FILE_LINK_FLAG "@")
endif()
set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-fpp")
set(CMAKE_Fortran_LINK_MODE DRIVER)