From 1293c1561a58b2f8b0bd4ec05bb249fc36f487ac Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 17 Oct 2015 14:27:59 +0200 Subject: [PATCH] cmExportTryCompileFileGenerator: Port to cmGeneratorTarget. --- Source/cmCoreTryCompile.cxx | 7 +++-- Source/cmExportTryCompileFileGenerator.cxx | 30 +++++++++++++--------- Source/cmExportTryCompileFileGenerator.h | 8 +++--- Source/cmGlobalGenerator.cxx | 20 +++++++++++++++ Source/cmGlobalGenerator.h | 3 +++ 5 files changed, 48 insertions(+), 20 deletions(-) diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 5bb0f99b9..4a1f770ba 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -34,7 +34,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv) std::string outputVariable; std::string copyFile; std::string copyFileError; - std::vector targets; + std::vector targets; std::string libsToLink = " "; bool useOldLinkLibs = true; char targetNameBuf[64]; @@ -112,7 +112,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv) } if (tgt->IsImported()) { - targets.push_back(tgt); + targets.push_back(argv[i]); } } } @@ -375,9 +375,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector 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")); diff --git a/Source/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx index d0e65e190..0fafa86f1 100644 --- a/Source/cmExportTryCompileFileGenerator.cxx +++ b/Source/cmExportTryCompileFileGenerator.cxx @@ -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& 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 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 &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::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); } diff --git a/Source/cmExportTryCompileFileGenerator.h b/Source/cmExportTryCompileFileGenerator.h index 8838eca82..45077876a 100644 --- a/Source/cmExportTryCompileFileGenerator.h +++ b/Source/cmExportTryCompileFileGenerator.h @@ -20,11 +20,11 @@ class cmInstallTargetGenerator; class cmExportTryCompileFileGenerator: public cmExportFileGenerator { public: - cmExportTryCompileFileGenerator(cmGlobalGenerator* gg); + cmExportTryCompileFileGenerator(cmGlobalGenerator* gg, + std::vector const& targets, + cmMakefile* mf); /** Set the list of targets to export. */ - void SetExports(const std::vector &exports) - { this->Exports = exports; } void SetConfig(const std::string& config) { this->Config = config; } protected: @@ -52,7 +52,7 @@ private: std::set &emitted); - std::vector Exports; + std::vector Exports; std::string Config; }; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 9d54f6f70..f54f936ac 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1202,6 +1202,26 @@ void cmGlobalGenerator::CreateGenerationObjects(TargetTypes targetTypes) this->ComputeBuildFileGenerators(); } +void cmGlobalGenerator::CreateImportedGenerationObjects(cmMakefile* mf, + const std::vector& targets, + std::vector& exports) +{ + this->CreateGenerationObjects(ImportedOnly); + std::vector::iterator mfit = + std::find(this->Makefiles.begin(), this->Makefiles.end(), mf); + cmLocalGenerator* lg = + this->LocalGenerators[std::distance(this->Makefiles.begin(), mfit)]; + for (std::vector::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 { diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index ad8992f6f..4e6b11dae 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -91,6 +91,9 @@ public: ImportedOnly }; + void CreateImportedGenerationObjects(cmMakefile* mf, + std::vector const& targets, + std::vector& exports); void CreateGenerationObjects(TargetTypes targetTypes = AllTargets); /**