VS11: Simplify external object file handling (#13831)

Since commit 9a6ff950 (Fix for bug where VS2010 did not use .obj files as
part of the build, 2011-04-01) and commit b291d9e7 (VS10: Fix external
objects generated outside target, 2012-03-19) we try to detect whether an
external object file is also a custom command output in the same target.
This is because VS10 includes .obj custom command outputs on the link line
by default.

VS 11 supports a "<LinkObjects ...>false</LinkObjects>" setting in custom
command rules to tell VS not to link the outputs.  From the VS help:

 Specify whether the Inputs and output files with specific extensions (.obj,
 .lib, .res, .rsc) are passed to the linker.

Treat all external object files the same and add "<Object>" settings for them.
This commit is contained in:
Brad King 2013-01-07 11:31:52 -05:00
parent c7550d5ef1
commit b684b39581
1 changed files with 20 additions and 5 deletions

View File

@ -572,6 +572,12 @@ cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile* source,
sep = ";";
}
(*this->BuildFileStream ) << "</Outputs>\n";
if(this->LocalGenerator->GetVersion() > cmLocalVisualStudioGenerator::VS10)
{
// VS >= 11 let us turn off linking of custom command outputs.
this->WritePlatformConfigTag("LinkObjects", i->c_str(), 3);
(*this->BuildFileStream ) << "false</LinkObjects>\n";
}
}
this->WriteString("</CustomBuild>\n", 2);
}
@ -879,15 +885,24 @@ void cmVisualStudio10TargetGenerator::WriteAllSources()
}
}
if(this->LocalGenerator->GetVersion() > cmLocalVisualStudioGenerator::VS10)
{
// For VS >= 11 we use LinkObjects to avoid linking custom command
// outputs. Use Object for all external objects, generated or not.
this->WriteSources("Object", this->GeneratorTarget->ExternalObjects);
}
else
{
// If an object file is generated in this target, then vs10 will use
// it in the build, and we have to list it as None instead of Object.
for(std::vector<cmSourceFile*>::const_iterator
si = this->GeneratorTarget->ExternalObjects.begin();
si != this->GeneratorTarget->ExternalObjects.end(); ++si)
{
// If an object file is generated in this target, then vs10 will use
// it in the build, and we have to list it as None instead of Object.
std::vector<cmSourceFile*> const* d=this->Target->GetSourceDepends(*si);
this->WriteSource((d && !d->empty())? "None":"Object", *si);
}
}
this->WriteSources("None", this->GeneratorTarget->ExtraSources);