Browse Source

cmMakefile: Define cmTargetMap type in cmMakefile instead of cmTarget

The `cmTargetMap` type is only used in the context of `cmMakefile`.
Therefore it is the most appropriate place to declare it.

This moves the `cmTarget.h/cmTargets` type definition to
`cmMakefile::cmTargetMap`.
Sebastian Holtermann 6 years ago
parent
commit
7b4b61a4d3

+ 1 - 2
Source/cmExportLibraryDependenciesCommand.cxx

@@ -76,8 +76,7 @@ void cmExportLibraryDependenciesCommand::ConstFinalPass() const
   std::map<std::string, std::string> libDepsNew;
   std::map<std::string, std::string> libTypes;
   for (cmMakefile* local : locals) {
-    const cmTargets& tgts = local->GetTargets();
-    for (auto const& tgt : tgts) {
+    for (auto const& tgt : local->GetTargets()) {
       // Get the current target.
       cmTarget const& target = tgt.second;
 

+ 2 - 2
Source/cmInstallTargetsCommand.cxx

@@ -23,7 +23,7 @@ bool cmInstallTargetsCommand::InitialPass(std::vector<std::string> const& args,
   // Enable the install target.
   this->Makefile->GetGlobalGenerator()->EnableInstallTarget();
 
-  cmTargets& tgts = this->Makefile->GetTargets();
+  cmMakefile::cmTargetMap& tgts = this->Makefile->GetTargets();
   std::vector<std::string>::const_iterator s = args.begin();
   ++s;
   std::string runtime_dir = "/bin";
@@ -38,7 +38,7 @@ bool cmInstallTargetsCommand::InitialPass(std::vector<std::string> const& args,
 
       runtime_dir = *s;
     } else {
-      cmTargets::iterator ti = tgts.find(*s);
+      cmMakefile::cmTargetMap::iterator ti = tgts.find(*s);
       if (ti != tgts.end()) {
         ti->second.SetInstallPath(args[0]);
         ti->second.SetRuntimeInstallPath(runtime_dir);

+ 4 - 4
Source/cmMakefile.cxx

@@ -818,7 +818,7 @@ void cmMakefile::AddCustomCommandToTarget(
   bool command_expand_lists, ObjectLibraryCommands objLibraryCommands)
 {
   // Find the target to which to add the custom command.
-  cmTargets::iterator ti = this->Targets.find(target);
+  cmTargetMap::iterator ti = this->Targets.find(target);
 
   if (ti == this->Targets.end()) {
     MessageType messageType = MessageType::AUTHOR_WARNING;
@@ -1099,7 +1099,7 @@ void cmMakefile::AddCustomCommandOldStyle(
     // then add the source to the target to make sure the rule is
     // included.
     if (sf && !sf->GetPropertyAsBool("__CMAKE_RULE")) {
-      cmTargets::iterator ti = this->Targets.find(target);
+      cmTargetMap::iterator ti = this->Targets.find(target);
       if (ti != this->Targets.end()) {
         ti->second.AddSource(sf->GetFullPath());
       } else {
@@ -2036,7 +2036,7 @@ cmTarget* cmMakefile::AddExecutable(const std::string& exeName,
 cmTarget* cmMakefile::AddNewTarget(cmStateEnums::TargetType type,
                                    const std::string& name)
 {
-  cmTargets::iterator it =
+  cmTargetMap::iterator it =
     this->Targets
       .emplace(name, cmTarget(name, type, cmTarget::VisibilityNormal, this))
       .first;
@@ -3888,7 +3888,7 @@ std::vector<std::string> cmMakefile::GetPropertyKeys() const
 
 cmTarget* cmMakefile::FindLocalNonAliasTarget(const std::string& name) const
 {
-  cmTargets::iterator i = this->Targets.find(name);
+  cmTargetMap::iterator i = this->Targets.find(name);
   if (i != this->Targets.end()) {
     return &i->second;
   }

+ 8 - 9
Source/cmMakefile.h

@@ -373,14 +373,13 @@ public:
     return this->ComplainFileRegularExpression.c_str();
   }
 
-  /**
-   * Get the list of targets
-   */
-  cmTargets& GetTargets() { return this->Targets; }
-  /**
-   * Get the list of targets, const version
-   */
-  const cmTargets& GetTargets() const { return this->Targets; }
+  // -- List of targets
+  typedef std::unordered_map<std::string, cmTarget> cmTargetMap;
+  /** Get the target map */
+  cmTargetMap& GetTargets() { return this->Targets; }
+  /** Get the target map - const version */
+  cmTargetMap const& GetTargets() const { return this->Targets; }
+
   const std::vector<cmTarget*>& GetOwnedImportedTargets() const
   {
     return this->ImportedTargetsOwned;
@@ -896,7 +895,7 @@ protected:
   mutable std::set<cmListFileContext> CMP0054ReportedIds;
 
   // libraries, classes, and executables
-  mutable cmTargets Targets;
+  mutable cmTargetMap Targets;
   std::map<std::string, std::string> AliasTargets;
 
   typedef std::vector<cmSourceFile*> SourceFileVec;

+ 1 - 2
Source/cmOutputRequiredFilesCommand.cxx

@@ -111,8 +111,7 @@ public:
     // Now extract any include paths from the targets
     std::set<std::string> uniqueIncludes;
     std::vector<std::string> orderedAndUniqueIncludes;
-    cmTargets& targets = this->Makefile->GetTargets();
-    for (auto const& target : targets) {
+    for (auto const& target : this->Makefile->GetTargets()) {
       const char* incDirProp =
         target.second.GetProperty("INCLUDE_DIRECTORIES");
       if (!incDirProp) {

+ 0 - 3
Source/cmTarget.h

@@ -9,7 +9,6 @@
 #include <memory> // IWYU pragma: keep
 #include <set>
 #include <string>
-#include <unordered_map>
 #include <utility>
 #include <vector>
 
@@ -260,6 +259,4 @@ private:
   std::unique_ptr<cmTargetInternals> impl;
 };
 
-typedef std::unordered_map<std::string, cmTarget> cmTargets;
-
 #endif