LINKER_LANGUAGE default for one-language executables linking mixed libraries
Consider this example:
add_library(SomeLibUsingCXX STATIC lib.cxx) add_executable(MyFortranProgram main.F) target_link_libraries(MyFortranProgram PRIVATE SomeLibUsingCXX) set_property(TARGET MyFortranProgram PROPERTY LINKER_LANGUAGE Fortran)
The last line is currently required to tell CMake that the Fortran compiler must be used to drive linking since the program entry point is in Fortran. This is mentioned in the LINKER_LANGUAGE target property documentation.
When the last line is not present, CMake recognizes that both Fortran and C++ object files are included in the link (the latter through the library) and prioritizes selection of the C++ compiler over the Fortran compiler to drive linking. For a shared library that normally doesn't matter, but for an executable that selection may not match the language of the object file that contains the program entry point (
In the case that the actual sources listed in an executable target are all only one language, it is a reasonably good guess that one of those sources has the program entry point and so their language should be the default used to drive linking.