mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-09 15:20:56 -06:00
VS: Do not reference output assemblies of targets with no output
Our logic that sets `ReferenceOutputAssembly` in `ProjectReference` has accumulated a series of conditions for different cases in which the referenced target has no output. Simplify the condition to check `GetManagedType` directly for cases with no output. This will explicitly turn off `ReferenceOutputAssembly` in `ProjectReference` for utility (i.e. `add_custom_target`) and special targets (i.e. `ZERO_CHECK`, etc.), and allowing reference of target dependencies that produce some output. Fixes: #19665
This commit is contained in:
committed by
Brad King
parent
9c31d83aa2
commit
acdb326610
@@ -4092,32 +4092,8 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0)
|
||||
e2.Element("Name", name);
|
||||
this->WriteDotNetReferenceCustomTags(e2, name);
|
||||
|
||||
// If the dependency target is not managed (compiled with /clr or
|
||||
// C# target) and not a WinRT component we cannot reference it and
|
||||
// have to set 'ReferenceOutputAssembly' to false.
|
||||
auto referenceNotManaged =
|
||||
dt->GetManagedType("") < cmGeneratorTarget::ManagedType::Mixed;
|
||||
// Workaround to check for manually set /clr flags.
|
||||
if (referenceNotManaged) {
|
||||
if (const auto* flags = dt->GetProperty("COMPILE_OPTIONS")) {
|
||||
std::string flagsStr = flags;
|
||||
if (flagsStr.find("clr") != std::string::npos) {
|
||||
// There is a warning already issued when building the flags.
|
||||
referenceNotManaged = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Workaround for static library C# targets
|
||||
if (referenceNotManaged && dt->GetType() == cmStateEnums::STATIC_LIBRARY) {
|
||||
referenceNotManaged = !dt->IsCSharpOnly();
|
||||
}
|
||||
|
||||
// Referencing WinRT components is okay.
|
||||
if (referenceNotManaged) {
|
||||
referenceNotManaged = !dt->GetPropertyAsBool("VS_WINRT_COMPONENT");
|
||||
}
|
||||
|
||||
if (referenceNotManaged) {
|
||||
// Don't reference targets that don't produce any output.
|
||||
if (dt->GetManagedType("") == cmGeneratorTarget::ManagedType::Undefined) {
|
||||
e2.Element("ReferenceOutputAssembly", "false");
|
||||
e2.Element("CopyToOutputDirectory", "Never");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user