tl;dr: I’d like to improve LINKER_LANGUAGE auto-detect for C++ library with Fortran main program.
Across compilers and OS, CMake is good at detecting the appropriate linker_language EXCEPT for C++ library with Fortran main program.
For those targets, I always have to set target property
set_property(TARGET fortran_main PROPERTY LINKER_LANGUAGE Fortran)
I assume that until recent years, using C++ libraries with Fortran main wasn’t so common. However a key use for my work is C++17 filesystem library in Fortran programs.
try_run() I can’t set the linker_language without CMake script access since only the source files are specified. Rather than mess with
try_run() internals, maybe it’s better to improve CMake’s linker language detection.
The reason I’d like to use
try_run() is to verify C++ exception handling is working at CMake configure time, which I’ve found needs to be done with a test program.
It looks like
CMAKE_<LANG>_LINKER_PREFERENCE is set only by internal CMake script with some arbitrary values: