From 9b8a1f7c28deac892493b0a5548b08b2003238ea Mon Sep 17 00:00:00 2001 From: Tushar Maheshwari Date: Fri, 6 Sep 2019 15:46:02 +0530 Subject: cmExportSetMap: improve ownership of cmExportSet - use `std::piecewise_construct` to fix gcc-4.8 build. - can use `emplace(name, name)` gcc-6 onwards. --- Source/cmExportCommand.cxx | 10 +++++----- Source/cmExportInstallFileGenerator.cxx | 7 +++---- Source/cmExportSetMap.cxx | 22 ++++------------------ Source/cmExportSetMap.h | 18 ++++-------------- Source/cmInstallCommand.cxx | 12 ++++++------ 5 files changed, 22 insertions(+), 47 deletions(-) diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx index 4046f91..66dcb97 100644 --- a/Source/cmExportCommand.cxx +++ b/Source/cmExportCommand.cxx @@ -121,7 +121,7 @@ bool cmExportCommand::InitialPass(std::vector const& args, cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator(); - cmExportSet* ExportSet = nullptr; + cmExportSet* exportSet = nullptr; if (args[0] == "EXPORT") { cmExportSetMap& setMap = gg->GetExportSets(); auto const it = setMap.find(arguments.ExportSetName); @@ -131,7 +131,7 @@ bool cmExportCommand::InitialPass(std::vector const& args, this->SetError(e.str()); return false; } - ExportSet = it->second; + exportSet = &it->second; } else if (!arguments.Targets.empty() || cmContains(keywordsMissingValue, "TARGETS")) { for (std::string const& currentTarget : arguments.Targets) { @@ -180,8 +180,8 @@ bool cmExportCommand::InitialPass(std::vector const& args, ebfg->SetExportFile(fname.c_str()); ebfg->SetNamespace(arguments.Namespace); ebfg->SetAppendMode(arguments.Append); - if (ExportSet != nullptr) { - ebfg->SetExportSet(ExportSet); + if (exportSet != nullptr) { + ebfg->SetExportSet(exportSet); } else { ebfg->SetTargets(targets); } @@ -197,7 +197,7 @@ bool cmExportCommand::InitialPass(std::vector const& args, for (std::string const& ct : configurationTypes) { ebfg->AddConfiguration(ct); } - if (ExportSet != nullptr) { + if (exportSet != nullptr) { gg->AddBuildExportExportSet(ebfg); } else { gg->AddBuildExportSet(ebfg); diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index 4e3db09..c5aec64 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -474,9 +474,8 @@ cmExportInstallFileGenerator::FindNamespaces(cmGlobalGenerator* gg, const cmExportSetMap& exportSets = gg->GetExportSets(); for (auto const& expIt : exportSets) { - const cmExportSet* exportSet = expIt.second; - std::vector const* targets = - exportSet->GetTargetExports(); + const cmExportSet& exportSet = expIt.second; + std::vector const* targets = exportSet.GetTargetExports(); bool containsTarget = false; for (cmTargetExport* target : *targets) { @@ -488,7 +487,7 @@ cmExportInstallFileGenerator::FindNamespaces(cmGlobalGenerator* gg, if (containsTarget) { std::vector const* installs = - exportSet->GetInstallations(); + exportSet.GetInstallations(); for (cmInstallExportGenerator const* install : *installs) { exportFiles.push_back(install->GetDestinationFile()); ns = install->GetNamespace(); diff --git a/Source/cmExportSetMap.cxx b/Source/cmExportSetMap.cxx index 5c3f84f..68e76d5 100644 --- a/Source/cmExportSetMap.cxx +++ b/Source/cmExportSetMap.cxx @@ -2,30 +2,16 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmExportSetMap.h" -#include "cmAlgorithms.h" -#include "cmExportSet.h" - +#include #include -cmExportSet* cmExportSetMap::operator[](const std::string& name) +cmExportSet& cmExportSetMap::operator[](const std::string& name) { auto it = this->find(name); if (it == this->end()) // Export set not found { - it = this->insert(std::make_pair(name, new cmExportSet(name))).first; + auto tup_name = std::make_tuple(name); + it = this->emplace(std::piecewise_construct, tup_name, tup_name).first; } return it->second; } - -void cmExportSetMap::clear() -{ - cmDeleteAll(*this); - this->derived::clear(); -} - -cmExportSetMap::cmExportSetMap() = default; - -cmExportSetMap::~cmExportSetMap() -{ - this->clear(); -} diff --git a/Source/cmExportSetMap.h b/Source/cmExportSetMap.h index 0ef07ef..5764c0b 100644 --- a/Source/cmExportSetMap.h +++ b/Source/cmExportSetMap.h @@ -8,12 +8,12 @@ #include #include -class cmExportSet; +#include "cmExportSet.h" /// A name -> cmExportSet map with overloaded operator[]. -class cmExportSetMap : public std::map +class cmExportSetMap : public std::map { - using derived = std::map; + using derived = std::map; public: /** \brief Overloaded operator[]. @@ -21,17 +21,7 @@ public: * The operator is overloaded because cmExportSet has no default constructor: * we do not want unnamed export sets. */ - cmExportSet* operator[](const std::string& name); - - void clear(); - - cmExportSetMap(); - - /// Overloaded destructor deletes all member export sets. - ~cmExportSetMap(); - - cmExportSetMap(const cmExportSetMap&) = delete; - cmExportSetMap& operator=(const cmExportSetMap&) = delete; + cmExportSet& operator[](const std::string& name); }; #endif diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 9b931f7..11d2c4b 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -755,7 +755,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector const& args) te->ObjectsGenerator = objectGenerator; this->Makefile->GetGlobalGenerator() ->GetExportSets()[exports] - ->AddTargetExport(te); + .AddTargetExport(te); te->InterfaceIncludeDirectories = cmJoin(includesArgs.GetIncludeDirs(), ";"); @@ -1333,7 +1333,7 @@ bool cmInstallCommand::HandleExportAndroidMKMode( fname = "Android.mk"; } - cmExportSet* exportSet = + cmExportSet& exportSet = this->Makefile->GetGlobalGenerator()->GetExportSets()[exp]; cmInstallGenerator::MessageLevel message = @@ -1341,7 +1341,7 @@ bool cmInstallCommand::HandleExportAndroidMKMode( // Create the export install generator. cmInstallExportGenerator* exportGenerator = new cmInstallExportGenerator( - exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(), + &exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(), ica.GetConfigurations(), ica.GetComponent().c_str(), message, ica.GetExcludeFromAll(), fname.c_str(), name_space.c_str(), exportOld, true); @@ -1430,10 +1430,10 @@ bool cmInstallCommand::HandleExportMode(std::vector const& args) } } - cmExportSet* exportSet = + cmExportSet& exportSet = this->Makefile->GetGlobalGenerator()->GetExportSets()[exp]; if (exportOld) { - for (cmTargetExport* te : *exportSet->GetTargetExports()) { + for (cmTargetExport* te : *exportSet.GetTargetExports()) { cmTarget* tgt = this->Makefile->GetGlobalGenerator()->FindTarget(te->TargetName); const bool newCMP0022Behavior = @@ -1457,7 +1457,7 @@ bool cmInstallCommand::HandleExportMode(std::vector const& args) // Create the export install generator. cmInstallExportGenerator* exportGenerator = new cmInstallExportGenerator( - exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(), + &exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(), ica.GetConfigurations(), ica.GetComponent().c_str(), message, ica.GetExcludeFromAll(), fname.c_str(), name_space.c_str(), exportOld, false); -- cgit v0.12