Commit acdb3266 authored by Vedran Vujinovic's avatar Vedran Vujinovic Committed by Brad King

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
parent 9c31d83a
......@@ -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");
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment