diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 3c818ff5f23df92fdf960bf0189d2642e3181011..bc3c255a62ab25a9a60b4be375b8840c40980914 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -2054,10 +2054,10 @@ bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
 }
 
 bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
-                                   cmTarget const& target) const
+                                   cmGeneratorTarget* target) const
 {
-  if(target.GetType() == cmTarget::INTERFACE_LIBRARY
-      || target.GetPropertyAsBool("EXCLUDE_FROM_ALL"))
+  if(target->GetType() == cmTarget::INTERFACE_LIBRARY
+      || target->Target->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
     {
     // This target is excluded from its directory.
     return true;
@@ -2066,7 +2066,7 @@ bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
     {
     // This target is included in its directory.  Check whether the
     // directory is excluded.
-    return this->IsExcluded(root, target.GetMakefile()->GetLocalGenerator());
+    return this->IsExcluded(root, target->GetLocalGenerator());
     }
 }
 
@@ -2127,15 +2127,16 @@ void cmGlobalGenerator::FillLocalGeneratorToTargetMap()
       {
       cmTarget const& target = t->second;
 
+      cmGeneratorTarget* gt = this->GetGeneratorTarget(&target);
+
       // Consider the directory containing the target and all its
       // parents until something excludes the target.
-      for(cmLocalGenerator* clg = lg; clg && !this->IsExcluded(clg, target);
+      for(cmLocalGenerator* clg = lg; clg && !this->IsExcluded(clg, gt);
           clg = clg->GetParent())
         {
         // This local generator includes the target.
         std::set<cmGeneratorTarget const*>& targetSet =
           this->LocalGeneratorToTargetMap[clg];
-        cmGeneratorTarget* gt = this->GetGeneratorTarget(&target);
         targetSet.insert(gt);
 
         // Add dependencies of the included target.  An excluded
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index 3402fbcde9aca03ac3e2b7ef09a2db0c56ef0fa7..608b59c262acd528ff33c28d7caef3a549e9f299 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -391,7 +391,7 @@ protected:
   void FillProjectMap();
   void CheckLocalGenerators();
   bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen) const;
-  bool IsExcluded(cmLocalGenerator* root, cmTarget const& target) const;
+  bool IsExcluded(cmLocalGenerator* root, cmGeneratorTarget* target) const;
   void FillLocalGeneratorToTargetMap();
   void CreateDefaultGlobalTargets(cmTargets* targets);
   cmTarget CreateGlobalTarget(const std::string& name, const char* message,
diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h
index 2a749c1f7a9afae912c2eb106ebac6b7addd919a..47822b47fb7acf3d06ce26481bc2fc50a81dbb83 100644
--- a/Source/cmGlobalNinjaGenerator.h
+++ b/Source/cmGlobalNinjaGenerator.h
@@ -289,7 +289,7 @@ public:
   const std::vector<cmLocalGenerator*>& GetLocalGenerators() const {
     return LocalGenerators; }
 
-  bool IsExcluded(cmLocalGenerator* root, cmTarget& target) {
+  bool IsExcluded(cmLocalGenerator* root, cmGeneratorTarget* target) {
     return cmGlobalGenerator::IsExcluded(root, target); }
 
   int GetRuleCmdLength(const std::string& name) {
diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx
index 69747a4fda582e7b44c0ee3c30a2c13040c514b6..76d059ee2467205c4f535df0c27ec11e4dead5a5 100644
--- a/Source/cmGlobalUnixMakefileGenerator3.cxx
+++ b/Source/cmGlobalUnixMakefileGenerator3.cxx
@@ -821,7 +821,7 @@ cmGlobalUnixMakefileGenerator3
                         localName, depends, commands, true);
 
       // add the all/all dependency
-      if(!this->IsExcluded(this->LocalGenerators[0], *gtarget->Target))
+      if(!this->IsExcluded(this->LocalGenerators[0], gtarget))
         {
         depends.clear();
         depends.push_back(localName);
@@ -889,7 +889,7 @@ cmGlobalUnixMakefileGenerator3
                           "Pre-install relink rule for target.",
                           localName, depends, commands, true);
 
-        if(!this->IsExcluded(this->LocalGenerators[0], *gtarget->Target))
+        if(!this->IsExcluded(this->LocalGenerators[0], gtarget))
           {
           depends.clear();
           depends.push_back(localName);
diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx
index 2f9d79a97ade06c3b2f73309f5f0bdce37340b17..cf1be5cf4b522f7c7a1ec30d60124c2b7e7d0a08 100644
--- a/Source/cmGlobalVisualStudioGenerator.cxx
+++ b/Source/cmGlobalVisualStudioGenerator.cxx
@@ -111,17 +111,19 @@ bool cmGlobalVisualStudioGenerator::Compute()
       for(std::vector<cmLocalGenerator*>::iterator i = gen.begin();
           i != gen.end(); ++i)
         {
-        cmTargets& targets = (*i)->GetMakefile()->GetTargets();
-        for(cmTargets::iterator t = targets.begin();
+        cmGeneratorTargetsType targets =
+            (*i)->GetMakefile()->GetGeneratorTargets();
+        for(cmGeneratorTargetsType::iterator t = targets.begin();
             t != targets.end(); ++t)
           {
-          if (t->second.GetType() == cmTarget::GLOBAL_TARGET)
+          if (t->second->GetType() == cmTarget::GLOBAL_TARGET
+              || t->first->IsImported())
             {
             continue;
             }
           if(!this->IsExcluded(gen[0], t->second))
             {
-            allBuild->AddUtility(t->second.GetName());
+            allBuild->AddUtility(t->second->GetName());
             }
           }
         }
diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx
index 9889bd4c2a484ae94b2e28dd27ff932d0cde16c2..1822c97c65928eb59234652124fd871f73a5a164 100644
--- a/Source/cmLocalNinjaGenerator.cxx
+++ b/Source/cmLocalNinjaGenerator.cxx
@@ -90,7 +90,7 @@ void cmLocalNinjaGenerator::Generate()
       // Add the target to "all" if required.
       if (!this->GetGlobalNinjaGenerator()->IsExcluded(
             this->GetGlobalNinjaGenerator()->GetLocalGenerators()[0],
-            *t->second->Target))
+            t->second))
         this->GetGlobalNinjaGenerator()->AddDependencyToAll(t->second->Target);
       delete tg;
       }