FortranCInterface/Detect: Broken with GCC 12.0 and LTO enabled
Fortran/C interface detection is broken when LTO is enabled with GCC (gfortran) 12.0.
Minimal reproducer:
CMakeLists.txt:
PROJECT(F-C-MWE LANGUAGES C Fortran)
include(FortranCInterface)
FortranCInterface_HEADER(FCMangle.h
MACRO_NAMESPACE "FC_"
SYMBOL_NAMESPACE "FC_"
SYMBOLS mysub mymod:my_sub)
FortranCInterface_VERIFY()
On shell:
export CFLAGS='-flto'
export FFLAGS='-flto'
export FCFLAGS='-flto'
cmake .
Result (some lines suppressed for legibility):
-- Detecting Fortran/C Interface - Failed to recognize symbols
CMake Warning (dev) at /usr/share/cmake/Modules/FortranCInterface.cmake:309 (message):
No FortranCInterface mangling known for mysub
CMake Warning (dev) at /usr/share/cmake/Modules/FortranCInterface.cmake:295 (message):
No FortranCInterface mangling known for mymod:my_sub
-- Verifying Fortran/C Compiler Compatibility
CMake Warning (dev) at /usr/share/cmake/Modules/FortranCInterface.cmake:309 (message):
No FortranCInterface mangling known for VerifyFortran
-- Verifying Fortran/C Compiler Compatibility - Failed
CMake Error at /usr/share/cmake/Modules/FortranCInterface.cmake:391 (message):
/usr/bin/ld: /tmp/cclMYidY.ltrans0.ltrans.o: in function `main':
/usr/share/cmake/Modules/FortranCInterface/Verify/main.c:14: undefined reference to `VerifyFortran'
collect2: error: ld returned 1 exit status