Visual Studio project type selection and linker preference inconsistency
Under VS, the linker is implicitly defined by the type of project. Now I'm currently working on a library that consists almost exclusively out of Fortran code and only very minor amounts of C/C++ code, making it preferable to use the Fortran linker. To that end, we're using separate object libraries for each source files of each language and link them together in a separate target that has some dummy Fortran source files and the aforementioned object files as sources.
Under most generators, it's fine to use the
CMAKE_<LANG>_LINKER_PREFERENCE variable or
LINKER_LANGUAGE property to adjust the linker used. However, for Visual Studio, the logic in CMake is to create a
.vfproj if and only if the only language in the sources (and for object files their source language) is Fortran (see
cmGlobalVisualStudioGenerator::TargetIsFortranOnly ). Not only does this mean that the linker language selection that is possible in other generators won't work with VS, but during the generation of the link line, the determined linker language is being ignored as far as the
CMAKE_<LANG>_IMPLICIT_LINK_LIBRARIES variables are concerned in
Consequentially, if you configure the linker preferences in a way that Fortran is being chosen over C/C++ as linker language, the link line is generated incorrectly under Visual Studio causing such link processes to fail. I'm not sure what the best approach to address this issue is, whether it's ignoring the user set linker preferences so that under VS generators Fortran will be chosen if and only if there are only Fortran sources or whether the logic of the project generation should be adapted to differentiate between object and normal sources and consider the user provided linker choice if there's only object sources.