cmExportTryCompileFileGenerator: Port to cmGeneratorTarget.

This commit is contained in:
Stephen Kelly 2015-10-17 14:27:59 +02:00
parent 381e7afd36
commit 1293c1561a
5 changed files with 48 additions and 20 deletions

View File

@ -34,7 +34,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
std::string outputVariable;
std::string copyFile;
std::string copyFileError;
std::vector<cmTarget const*> targets;
std::vector<std::string> targets;
std::string libsToLink = " ";
bool useOldLinkLibs = true;
char targetNameBuf[64];
@ -112,7 +112,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
}
if (tgt->IsImported())
{
targets.push_back(tgt);
targets.push_back(argv[i]);
}
}
}
@ -375,9 +375,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
if (!targets.empty())
{
std::string fname = "/" + std::string(targetName) + "Targets.cmake";
cmExportTryCompileFileGenerator tcfg(gg);
cmExportTryCompileFileGenerator tcfg(gg, targets, this->Makefile);
tcfg.SetExportFile((this->BinaryDirectory + fname).c_str());
tcfg.SetExports(targets);
tcfg.SetConfig(this->Makefile->GetSafeDefinition(
"CMAKE_TRY_COMPILE_CONFIGURATION"));

View File

@ -14,13 +14,16 @@
#include "cmGeneratedFileStream.h"
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmGeneratorExpressionDAGChecker.h"
//----------------------------------------------------------------------------
cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator(
cmGlobalGenerator* gg)
cmGlobalGenerator* gg,
const std::vector<std::string>& targets,
cmMakefile* mf)
{
gg->CreateGenerationObjects(cmGlobalGenerator::ImportedOnly);
gg->CreateImportedGenerationObjects(mf, targets, this->Exports);
}
bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os)
@ -29,25 +32,25 @@ bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os)
std::set<cmTarget const*> emittedDeps;
while(!this->Exports.empty())
{
cmTarget const* te = this->Exports.back();
cmGeneratorTarget const* te = this->Exports.back();
this->Exports.pop_back();
if (emitted.insert(te).second)
if (emitted.insert(te->Target).second)
{
emittedDeps.insert(te);
this->GenerateImportTargetCode(os, te);
emittedDeps.insert(te->Target);
this->GenerateImportTargetCode(os, te->Target);
ImportPropertyMap properties;
#define FIND_TARGETS(PROPERTY) \
this->FindTargets("INTERFACE_" #PROPERTY, te, emittedDeps);
this->FindTargets("INTERFACE_" #PROPERTY, te->Target, emittedDeps);
CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(FIND_TARGETS)
#undef FIND_TARGETS
this->PopulateProperties(te, properties, emittedDeps);
this->PopulateProperties(te->Target, properties, emittedDeps);
this->GenerateInterfaceProperties(te, os, properties);
this->GenerateInterfaceProperties(te->Target, os, properties);
}
}
return true;
@ -91,7 +94,7 @@ std::string cmExportTryCompileFileGenerator::FindTargets(
{
if(emitted.insert((*li)->Target).second)
{
this->Exports.push_back((*li)->Target);
this->Exports.push_back((*li));
}
}
return result;
@ -104,6 +107,8 @@ cmExportTryCompileFileGenerator::PopulateProperties(cmTarget const* target,
std::set<cmTarget const*> &emitted)
{
cmPropertyMap props = target->GetProperties();
cmGeneratorTarget* gt =
target->GetMakefile()->GetGlobalGenerator()->GetGeneratorTarget(target);
for(cmPropertyMap::const_iterator i = props.begin(); i != props.end(); ++i)
{
properties[i->first] = i->second.GetValue();
@ -120,8 +125,9 @@ cmExportTryCompileFileGenerator::PopulateProperties(cmTarget const* target,
for(std::vector<std::string>::const_iterator li = depends.begin();
li != depends.end(); ++li)
{
cmTarget *tgt = target->GetMakefile()->FindTargetToUse(*li);
if(tgt && emitted.insert(tgt).second)
cmGeneratorTarget *tgt =
gt->GetLocalGenerator()->FindGeneratorTargetToUse(*li);
if(tgt && emitted.insert(tgt->Target).second)
{
this->Exports.push_back(tgt);
}

View File

@ -20,11 +20,11 @@ class cmInstallTargetGenerator;
class cmExportTryCompileFileGenerator: public cmExportFileGenerator
{
public:
cmExportTryCompileFileGenerator(cmGlobalGenerator* gg);
cmExportTryCompileFileGenerator(cmGlobalGenerator* gg,
std::vector<std::string> const& targets,
cmMakefile* mf);
/** Set the list of targets to export. */
void SetExports(const std::vector<cmTarget const*> &exports)
{ this->Exports = exports; }
void SetConfig(const std::string& config) { this->Config = config; }
protected:
@ -52,7 +52,7 @@ private:
std::set<cmTarget const*> &emitted);
std::vector<cmTarget const*> Exports;
std::vector<cmGeneratorTarget const*> Exports;
std::string Config;
};

View File

@ -1202,6 +1202,26 @@ void cmGlobalGenerator::CreateGenerationObjects(TargetTypes targetTypes)
this->ComputeBuildFileGenerators();
}
void cmGlobalGenerator::CreateImportedGenerationObjects(cmMakefile* mf,
const std::vector<std::string>& targets,
std::vector<const cmGeneratorTarget*>& exports)
{
this->CreateGenerationObjects(ImportedOnly);
std::vector<cmMakefile*>::iterator mfit =
std::find(this->Makefiles.begin(), this->Makefiles.end(), mf);
cmLocalGenerator* lg =
this->LocalGenerators[std::distance(this->Makefiles.begin(), mfit)];
for (std::vector<std::string>::const_iterator it = targets.begin();
it != targets.end(); ++it)
{
cmGeneratorTarget* gt = lg->FindGeneratorTargetToUse(*it);
if (gt)
{
exports.push_back(gt);
}
}
}
cmExportBuildFileGenerator*
cmGlobalGenerator::GetExportedTargetsFile(const std::string &filename) const
{

View File

@ -91,6 +91,9 @@ public:
ImportedOnly
};
void CreateImportedGenerationObjects(cmMakefile* mf,
std::vector<std::string> const& targets,
std::vector<cmGeneratorTarget const*>& exports);
void CreateGenerationObjects(TargetTypes targetTypes = AllTargets);
/**