mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-18 00:02:21 +08:00
VS: Fix Fortran target type selection when linking C++ targets
Since commit 2c9f35789d
(VS: Decide project type by linker lang as
fallback, 2017-03-30, v3.9.0-rc1~340^2) we consider the linker language
when detecting whether to generate a `.vfproj` or `.vcxproj` file.
However, this could cause C-only projects to become `.vfproj` files if
they link to Fortran projects. Instead we should consider only the
`LINKER_LANGUAGE` property on the target itself. This approach is
already used for CSharp. It allows project code to specify the project
file type for a target with no sources but does not allow linked targets
to affect it.
Fixes: #18687
This commit is contained in:
@@ -813,7 +813,6 @@ bool cmGlobalVisualStudioGenerator::TargetIsFortranOnly(
|
|||||||
cmGeneratorTarget const* gt)
|
cmGeneratorTarget const* gt)
|
||||||
{
|
{
|
||||||
// check to see if this is a fortran build
|
// check to see if this is a fortran build
|
||||||
std::set<std::string> languages;
|
|
||||||
{
|
{
|
||||||
// Issue diagnostic if the source files depend on the config.
|
// Issue diagnostic if the source files depend on the config.
|
||||||
std::vector<cmSourceFile*> sources;
|
std::vector<cmSourceFile*> sources;
|
||||||
@@ -821,27 +820,21 @@ bool cmGlobalVisualStudioGenerator::TargetIsFortranOnly(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's only one source language, Fortran has to be used
|
// If there's only one source language, Fortran has to be used
|
||||||
// in order for the sources to compile.
|
// in order for the sources to compile.
|
||||||
// Note: Via linker propagation, LINKER_LANGUAGE could become CXX in
|
std::set<std::string> languages;
|
||||||
// this situation and mismatch from the actual language of the linker.
|
|
||||||
gt->GetLanguages(languages, "");
|
gt->GetLanguages(languages, "");
|
||||||
if (languages.size() == 1) {
|
// Consider an explicit linker language property, but *not* the
|
||||||
if (*languages.begin() == "Fortran") {
|
// computed linker language that may depend on linked targets.
|
||||||
return true;
|
// This allows the project to control the language choice in
|
||||||
}
|
// a target with none of its own sources, e.g. when also using
|
||||||
|
// object libraries.
|
||||||
|
const char* linkLang = gt->GetProperty("LINKER_LANGUAGE");
|
||||||
|
if (linkLang && *linkLang) {
|
||||||
|
languages.insert(linkLang);
|
||||||
}
|
}
|
||||||
|
return languages.size() == 1 && *languages.begin() == "Fortran";
|
||||||
// In the case of mixed object files or sources mixed with objects,
|
|
||||||
// decide the language based on the value of LINKER_LANGUAGE.
|
|
||||||
// This will not make it possible to mix source files of different
|
|
||||||
// languages, but object libraries will be linked together in the
|
|
||||||
// same fashion as other generators do.
|
|
||||||
if (gt->GetLinkerLanguage("") == "Fortran") {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmGlobalVisualStudioGenerator::TargetCompare::operator()(
|
bool cmGlobalVisualStudioGenerator::TargetCompare::operator()(
|
||||||
|
@@ -99,6 +99,11 @@ function(test_fortran_c_interface_module)
|
|||||||
target_link_libraries(myc myfort)
|
target_link_libraries(myc myfort)
|
||||||
set_property(TARGET myc PROPERTY COMPILE_DEFINITIONS ${MYC_DEFS})
|
set_property(TARGET myc PROPERTY COMPILE_DEFINITIONS ${MYC_DEFS})
|
||||||
|
|
||||||
|
add_library(myfort_obj OBJECT mysub.f)
|
||||||
|
add_library(myc_use_obj myc.c $<TARGET_OBJECTS:myfort_obj>)
|
||||||
|
add_executable(mainc_use_obj mainc.c)
|
||||||
|
target_link_libraries(mainc_use_obj myc_use_obj)
|
||||||
|
|
||||||
add_library(mycxx mycxx.cxx)
|
add_library(mycxx mycxx.cxx)
|
||||||
target_link_libraries(mycxx myc)
|
target_link_libraries(mycxx myc)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user