diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 0976a4d..3212428 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -601,6 +601,10 @@ cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf,
     }
   cmStdString key = GetGroupMapKey(cmtarget, sf);
   cmXCodeObject* group = this->GroupMap[key];
+  if (!group)
+    {
+    return NULL;
+    }
   cmXCodeObject* children = group->GetObject("children");
   if (!children->HasObject(fileRef))
     {
@@ -2429,7 +2433,8 @@ void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
       // end up with (empty anyhow) ALL_BUILD and XCODE_DEPEND_HELPER source
       // groups:
       //
-      if(cmtarget.GetType() == cmTarget::GLOBAL_TARGET)
+      if(cmtarget.GetType() == cmTarget::UTILITY ||
+         cmtarget.GetType() == cmTarget::GLOBAL_TARGET)
         {
         continue;
         }
@@ -2442,7 +2447,7 @@ void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
         cmSourceFile* sf = mf->GetOrCreateSource(plist.c_str(), true);
         cmtarget.AddSourceFile(sf);
         }
-
+        
       std::vector<cmSourceFile*>  classes = cmtarget.GetSourceFiles();
 
       for(std::vector<cmSourceFile*>::const_iterator s = classes.begin();
@@ -2453,22 +2458,64 @@ void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
         std::string const& source = sf->GetFullPath();
         cmSourceGroup& sourceGroup =
           mf->FindSourceGroup(source.c_str(), sourceGroups);
-        cmXCodeObject* pbxgroup =
-          this->CreateOrGetPBXGroup(cmtarget, &sourceGroup);
-        cmStdString key = GetGroupMapKey(cmtarget, sf);
-        this->GroupMap[key] = pbxgroup;
+        sourceGroup.AssignSource( sf );
+        }
+          
+      // Create all of the groups that should be created for this target.
+      // Loop through every source group.
+      for(unsigned int i = 0; i < sourceGroups.size(); ++i)
+        {
+        CreateSourceGroup(sourceGroups[i], cmtarget, false);
+        }
+      }
+    }
+}
+
+//----------------------------------------------------------------------------
+cmXCodeObject* cmGlobalXCodeGenerator
+::CreateSourceGroup( cmSourceGroup& sg, cmTarget& cmtarget, bool child_group )
+{
+  // Only do something with the group if there are files or child groups
+  if( !sg.GetSourceFiles().empty() || !sg.GetGroupChildren().empty() ) 
+    {
+    cmXCodeObject* pbxgroup = this->CreateOrGetPBXGroup(cmtarget, &sg, !child_group);
+    std::vector<const cmSourceFile*>& sources = sg.GetSourceFiles();
+
+    // Get all the source files and add them to the GroupMap
+    for(std::vector<const cmSourceFile*>::const_iterator s = sources.begin(); 
+        s != sources.end(); s++)
+      {
+      cmStdString key = GetGroupMapKey(cmtarget, (cmSourceFile*)*s);
+      this->GroupMap[key] = pbxgroup;
+      }
+    
+    // Do the child groups
+    std::vector<cmSourceGroup> children  = sg.GetGroupChildren();
+    cmXCodeObject* groupChildren = pbxgroup->GetObject("children");
+
+    for(unsigned int i=0;i<children.size();++i)
+      {
+      cmXCodeObject* group = this->CreateSourceGroup( children[i], cmtarget, true );
+      if (group)
+        {
+        groupChildren->AddObject(group);
         }
       }
+    
+    return pbxgroup;
     }
+  
+  return NULL;
 }
 
+
 //----------------------------------------------------------------------------
 cmXCodeObject* cmGlobalXCodeGenerator
-::CreateOrGetPBXGroup(cmTarget& cmtarget, cmSourceGroup* sg)
+::CreateOrGetPBXGroup(cmTarget& cmtarget, cmSourceGroup* sg, bool child_group)
 {
   cmStdString s = cmtarget.GetName();
   s += "/";
-  s += sg->GetName();
+  s += sg->GetFullName();
   std::map<cmStdString, cmXCodeObject* >::iterator i =
     this->GroupNameMap.find(s);
   if(i != this->GroupNameMap.end())
@@ -2506,7 +2553,6 @@ cmXCodeObject* cmGlobalXCodeGenerator
     return tgroup;
     }
 
-  cmXCodeObject* tgroupChildren = tgroup->GetObject("children");
   cmXCodeObject* group = this->CreateObject(cmXCodeObject::PBXGroup);
   cmXCodeObject* groupChildren =
     this->CreateObject(cmXCodeObject::OBJECT_LIST);
@@ -2517,7 +2563,11 @@ cmXCodeObject* cmGlobalXCodeGenerator
     group->AddAttribute("refType", this->CreateString("4"));
     }
   group->AddAttribute("sourceTree", this->CreateString("<group>"));
-  tgroupChildren->AddObject(group);
+    if( child_group ){
+        cmXCodeObject* tgroupChildren = tgroup->GetObject("children");
+        tgroupChildren->AddObject(group);
+    }
+  
   this->GroupNameMap[s] = group;
   return group;
 }
@@ -2617,8 +2667,6 @@ void cmGlobalXCodeGenerator
     this->CreateObject(cmXCodeObject::OBJECT_LIST);
   productGroup->AddAttribute("children", productGroupChildren);
   this->MainGroupChildren->AddObject(productGroup);
-
-
   this->RootObject = this->CreateObject(cmXCodeObject::PBXProject);
   this->RootObject->SetComment("Project object");
   group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h
index b4de805..04b7efd 100644
--- a/Source/cmGlobalXCodeGenerator.h
+++ b/Source/cmGlobalXCodeGenerator.h
@@ -87,10 +87,12 @@ public:
 
 private: 
   cmXCodeObject* CreateOrGetPBXGroup(cmTarget& cmtarget,
-                                     cmSourceGroup* sg);
+                                     cmSourceGroup* sg,
+                                     bool child_group);
   void CreateGroups(cmLocalGenerator* root,
                     std::vector<cmLocalGenerator*>&
                     generators);
+  cmXCodeObject* CreateSourceGroup( cmSourceGroup& sg, cmTarget& cmtarget, bool child_group );
   std::string XCodeEscapePath(const char* p);
   std::string RelativeToSource(const char* p);
   std::string RelativeToBinary(const char* p);
