diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 4e9969d..33158c7 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -2432,7 +2432,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(); 
@@ -2443,10 +2443,14 @@ 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 );
         }
       }
     } 
@@ -2454,7 +2458,45 @@ void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
 
 //----------------------------------------------------------------------------
 cmXCodeObject* cmGlobalXCodeGenerator
-::CreateOrGetPBXGroup(cmTarget& cmtarget, cmSourceGroup* sg)
+::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, bool child_group)
 {
   cmStdString s = cmtarget.GetName();
   s += "/";
@@ -2496,7 +2538,6 @@ cmXCodeObject* cmGlobalXCodeGenerator
     return tgroup;
     }
 
-  cmXCodeObject* tgroupChildren = tgroup->GetObject("children");
   cmXCodeObject* group = this->CreateObject(cmXCodeObject::PBXGroup);
   cmXCodeObject* groupChildren = 
     this->CreateObject(cmXCodeObject::OBJECT_LIST);
@@ -2507,7 +2548,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;
 }
@@ -2608,7 +2653,6 @@ void cmGlobalXCodeGenerator
   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);
