cmake: Future-proof --find-package mode.

Create cmGeneratorTargets before generating generate-time information.
C++ interfaces for querying build information is increasingly only
available at generate time through the cmGeneratorTarget class.  Ensure
that the required cmGeneratorTarget instances are created.  Use the
cmGlobalGenerator access API to access the relevant cmGeneratorTarget
instead of creating a temporary one on the stack.
This commit is contained in:
Stephen Kelly 2014-01-11 14:17:03 +01:00
parent cb7af7af44
commit a7f393dc49
3 changed files with 31 additions and 26 deletions

View File

@ -1375,15 +1375,9 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo()
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmGlobalGenerator::CreateGeneratorTargets() void cmGlobalGenerator::CreateGeneratorTargets(cmMakefile *mf)
{
// Construct per-target generator information.
for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
{ {
cmGeneratorTargetsType generatorTargets; cmGeneratorTargetsType generatorTargets;
cmMakefile *mf = this->LocalGenerators[i]->GetMakefile();
cmTargets& targets = mf->GetTargets(); cmTargets& targets = mf->GetTargets();
for(cmTargets::iterator ti = targets.begin(); for(cmTargets::iterator ti = targets.begin();
ti != targets.end(); ++ti) ti != targets.end(); ++ti)
@ -1402,9 +1396,17 @@ void cmGlobalGenerator::CreateGeneratorTargets()
this->GeneratorTargets[*j] = gt; this->GeneratorTargets[*j] = gt;
generatorTargets[*j] = gt; generatorTargets[*j] = gt;
} }
mf->SetGeneratorTargets(generatorTargets); mf->SetGeneratorTargets(generatorTargets);
} }
//----------------------------------------------------------------------------
void cmGlobalGenerator::CreateGeneratorTargets()
{
// Construct per-target generator information.
for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
{
this->CreateGeneratorTargets(this->LocalGenerators[i]->GetMakefile());
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -432,6 +432,8 @@ private:
// Per-target generator information. // Per-target generator information.
cmGeneratorTargetsType GeneratorTargets; cmGeneratorTargetsType GeneratorTargets;
friend class cmake;
void CreateGeneratorTargets(cmMakefile* mf);
void CreateGeneratorTargets(); void CreateGeneratorTargets();
void ComputeGeneratorTargetObjects(); void ComputeGeneratorTargetObjects();
virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const; virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const;

View File

@ -593,9 +593,10 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
std::string linkPath; std::string linkPath;
std::string flags; std::string flags;
std::string linkFlags; std::string linkFlags;
cmGeneratorTarget gtgt(tgt); gg->CreateGeneratorTargets(mf);
cmGeneratorTarget *gtgt = gg->GetGeneratorTarget(tgt);
lg->GetTargetFlags(linkLibs, frameworkPath, linkPath, flags, linkFlags, lg->GetTargetFlags(linkLibs, frameworkPath, linkPath, flags, linkFlags,
&gtgt); gtgt);
linkLibs = frameworkPath + linkPath + linkLibs; linkLibs = frameworkPath + linkPath + linkLibs;
printf("%s\n", linkLibs.c_str() ); printf("%s\n", linkLibs.c_str() );