diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index d7bec44920f027ffc83bbc16e307a477de556903..65e7b12810c5583955d5b9be0a8341e10653ae4f 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -1649,6 +1649,7 @@ void cmGlobalGenerator::ClearGeneratorMembers()
 
   this->ExportSets.clear();
   this->TargetDependencies.clear();
+  this->TargetSearchIndex.clear();
   this->ProjectMap.clear();
   this->RuleHashes.clear();
   this->DirectoryContentMap.clear();
@@ -2177,18 +2178,20 @@ bool cmGlobalGenerator::IsAlias(const std::string& name) const
   return this->AliasTargets.find(name) != this->AliasTargets.end();
 }
 
+void cmGlobalGenerator::IndexTarget(cmTarget* t)
+{
+  if (!t->IsImported() || t->IsImportedGloballyVisible())
+    {
+    this->TargetSearchIndex[t->GetName()] = t;
+    }
+}
+
 cmTarget* cmGlobalGenerator::FindTargetImpl(std::string const& name) const
 {
-  for (unsigned int i = 0; i < this->Makefiles.size(); ++i)
+  TargetMap::const_iterator i = this->TargetSearchIndex.find(name);
+  if (i != this->TargetSearchIndex.end())
     {
-    cmTargets& tgts = this->Makefiles[i]->GetTargets();
-    for (cmTargets::iterator it = tgts.begin(); it != tgts.end(); ++it)
-      {
-      if (it->second.GetName() == name)
-        {
-        return &it->second;
-        }
-      }
+    return i->second;
     }
   return 0;
 }
@@ -2212,25 +2215,6 @@ cmGlobalGenerator::FindGeneratorTargetImpl(std::string const& name) const
   return 0;
 }
 
-cmTarget*
-cmGlobalGenerator::FindImportedTargetImpl(std::string const& name) const
-{
-  for (unsigned int i = 0; i < this->Makefiles.size(); ++i)
-    {
-    const std::vector<cmTarget*>& tgts =
-        this->Makefiles[i]->GetOwnedImportedTargets();
-    for (std::vector<cmTarget*>::const_iterator it = tgts.begin();
-         it != tgts.end(); ++it)
-      {
-      if ((*it)->GetName() == name && (*it)->IsImportedGloballyVisible())
-        {
-        return *it;
-        }
-      }
-    }
-  return 0;
-}
-
 cmGeneratorTarget* cmGlobalGenerator::FindImportedGeneratorTargetImpl(
     std::string const& name) const
 {
@@ -2264,11 +2248,7 @@ cmGlobalGenerator::FindTarget(const std::string& name,
       return this->FindTargetImpl(ai->second);
       }
     }
-  if (cmTarget* tgt = this->FindTargetImpl(name))
-    {
-    return tgt;
-    }
-  return this->FindImportedTargetImpl(name);
+  return this->FindTargetImpl(name);
 }
 
 cmGeneratorTarget*
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index bc6e17d7ff4e09605ca28e58d5c82b38fa74bed1..82bb35c489922b929c5f18a94b1db792a5e40070 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -278,6 +278,8 @@ public:
   std::set<std::string> const& GetDirectoryContent(std::string const& dir,
                                                    bool needDisk = true);
 
+  void IndexTarget(cmTarget* t);
+
   static bool IsReservedTarget(std::string const& name);
 
   virtual const char* GetAllTargetName()         const { return "ALL_BUILD"; }
@@ -420,7 +422,6 @@ protected:
   std::map<std::string, std::string> AliasTargets;
 
   cmTarget* FindTargetImpl(std::string const& name) const;
-  cmTarget* FindImportedTargetImpl(std::string const& name) const;
 
   cmGeneratorTarget* FindGeneratorTargetImpl(std::string const& name) const;
   cmGeneratorTarget*
@@ -430,6 +431,21 @@ protected:
   virtual bool UseFolderProperty();
 
 private:
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+# ifdef CMake_HAVE_CXX11_UNORDERED_MAP
+  typedef std::unordered_map<std::string, cmTarget*> TargetMap;
+# else
+  typedef cmsys::hash_map<std::string, cmTarget*> TargetMap;
+# endif
+#else
+  typedef std::map<std::string,cmTarget *> TargetMap;
+#endif
+  // Map efficiently from target name to cmTarget instance.
+  // Do not use this structure for looping over all targets.
+  // It contains both normal and globally visible imported targets.
+  TargetMap TargetSearchIndex;
+
   cmMakefile* TryCompileOuterMakefile;
   // If you add a new map here, make sure it is copied
   // in EnableLanguagesFromGenerator
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index cba29eb0453fdf9f13fe20b0d2ff0785a1d745bb..950b247356563e08fd2d188595fcbbab752287cc 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -2128,6 +2128,7 @@ cmMakefile::AddNewTarget(cmState::TargetType type, const std::string& name)
   cmTarget& target = it->second;
   target.SetType(type, name);
   target.SetMakefile(this);
+  this->GetGlobalGenerator()->IndexTarget(&it->second);
   return &it->second;
 }
 
@@ -4218,6 +4219,7 @@ cmMakefile::AddImportedTarget(const std::string& name,
 
   // Add to the set of available imported targets.
   this->ImportedTargets[name] = target.get();
+  this->GetGlobalGenerator()->IndexTarget(target.get());
 
   // Transfer ownership to this cmMakefile object.
   this->ImportedTargetsOwned.push_back(target.get());