[Cmake-commits] [cmake-commits] king committed cmGlobalXCodeGenerator.cxx 1.229 1.230 cmGlobalXCodeGenerator.h 1.62 1.63

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Sep 22 16:18:33 EDT 2009


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv3600/Source

Modified Files:
	cmGlobalXCodeGenerator.cxx cmGlobalXCodeGenerator.h 
Log Message:
Fix Xcode project references to the source tree

Xcode project source file references need to always be relative to the
top of the source tree in order for SCM and debug symbols to work right.
We must even allow the relative paths to cross outside of the top source
or build directories.

For subdirectory project() command Xcode projects we use the source
directory containing the project() command as the top.  Relative paths
are generated accordingly for each subproject.

See issue #8481.


Index: cmGlobalXCodeGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalXCodeGenerator.cxx,v
retrieving revision 1.229
retrieving revision 1.230
diff -C 2 -d -r1.229 -r1.230
*** cmGlobalXCodeGenerator.cxx	21 Sep 2009 17:18:45 -0000	1.229
--- cmGlobalXCodeGenerator.cxx	22 Sep 2009 20:18:30 -0000	1.230
***************
*** 303,309 ****
    this->CurrentProject = root->GetMakefile()->GetProjectName();
    this->SetCurrentLocalGenerator(root);
!   std::string outDir = this->CurrentMakefile->GetHomeOutputDirectory();
!   outDir =cmSystemTools::CollapseFullPath(outDir.c_str());
!   cmSystemTools::SplitPath(outDir.c_str(),
                             this->ProjectOutputDirectoryComponents);
  
--- 303,309 ----
    this->CurrentProject = root->GetMakefile()->GetProjectName();
    this->SetCurrentLocalGenerator(root);
!   cmSystemTools::SplitPath(this->CurrentMakefile->GetCurrentDirectory(),
!                            this->ProjectSourceDirectoryComponents);
!   cmSystemTools::SplitPath(this->CurrentMakefile->GetCurrentOutputDirectory(),
                             this->ProjectOutputDirectoryComponents);
  
***************
*** 671,717 ****
                          this->CreateString(sourcecode.c_str()));
  
!   std::string path =
!     this->ConvertToRelativeForXCode(sf->GetFullPath().c_str());
!   std::string dir;
!   std::string file;
!   cmSystemTools::SplitProgramPath(sf->GetFullPath().c_str(),
!                                   dir, file);
! 
!   // Try to make the path relative to the project root.
!   bool Absolute = true;
!   if (this->XcodeVersion >= 30)
!     {
!     std::string relative = 
!       this->CurrentLocalGenerator->Convert(sf->GetFullPath().c_str(), 
!                                            cmLocalGenerator::HOME,
!                                            cmLocalGenerator::MAKEFILE, 
!                                            false);
!     relative = cmSystemTools::ConvertToOutputPath(relative.c_str());
!     if (!relative.empty() && relative[0] != '/') 
!       {
!       Absolute = false;
!       path = relative;
!       }
!     }
! 
!   fileRef->AddAttribute("name", this->CreateString(file.c_str()));
    fileRef->AddAttribute("path", this->CreateString(path.c_str()));
    if(this->XcodeVersion == 15)
      {
      fileRef->AddAttribute("refType", this->CreateString("4"));
      }
-   if(path.size() > 1 && path[0] == '.' && path[1] == '.')
-     {
-     fileRef->AddAttribute("sourceTree", this->CreateString("<group>"));
-     }
-   else if (Absolute)
-     {
-     fileRef->AddAttribute("sourceTree", this->CreateString("<absolute>"));
-     }
-   else
-     {
-     fileRef->AddAttribute("sourceTree", this->CreateString("SOURCE_ROOT"));
-     }
- 
    return fileRef;
  }
--- 671,686 ----
                          this->CreateString(sourcecode.c_str()));
  
!   // Store the file path relative to the top of the source tree.
!   std::string path = this->RelativeToSource(sf->GetFullPath().c_str());
!   std::string name = cmSystemTools::GetFilenameName(path.c_str());
!   const char* sourceTree = (cmSystemTools::FileIsFullPath(path.c_str())?
!                             "<absolute>" : "SOURCE_ROOT");
!   fileRef->AddAttribute("name", this->CreateString(name.c_str()));
    fileRef->AddAttribute("path", this->CreateString(path.c_str()));
+   fileRef->AddAttribute("sourceTree", this->CreateString(sourceTree));
    if(this->XcodeVersion == 15)
      {
      fileRef->AddAttribute("refType", this->CreateString("4"));
      }
    return fileRef;
  }
***************
*** 2611,2632 ****
        this->RootObject->AddAttribute("compatibilityVersion",
                                       this->CreateString("Xcode 3.0"));
-     this->RootObject->AddAttribute("projectDirPath", this->CreateString(""));
      }
    // Point Xcode at the top of the source tree.
    {
!   std::string proot = root->GetMakefile()->GetCurrentDirectory();
!   proot = this->ConvertToRelativeForXCode(proot.c_str());
!   if (this->XcodeVersion >= 30) 
!     {
!     this->RootObject->AddAttribute("projectRoot",
!                                    this->CreateString(""));
!     this->RootObject->AddAttribute("projectDirPath",
!                                    this->CreateString(proot.c_str()));
!     }
!   else
!     {
!     this->RootObject->AddAttribute("projectRoot",
!                                    this->CreateString(proot.c_str()));
!     }
    }
    cmXCodeObject* configlist = 
--- 2580,2591 ----
        this->RootObject->AddAttribute("compatibilityVersion",
                                       this->CreateString("Xcode 3.0"));
      }
    // Point Xcode at the top of the source tree.
    {
!   std::string pdir =
!     this->RelativeToBinary(root->GetMakefile()->GetCurrentDirectory());
!   this->RootObject->AddAttribute("projectDirPath",
!                                  this->CreateString(pdir.c_str()));
!   this->RootObject->AddAttribute("projectRoot", this->CreateString(""));
    }
    cmXCodeObject* configlist = 
***************
*** 3068,3071 ****
--- 3027,3046 ----
  
  //----------------------------------------------------------------------------
+ std::string cmGlobalXCodeGenerator::RelativeToSource(const char* p)
+ {
+   // We force conversion because Xcode breakpoints do not work unless
+   // they are in a file named relative to the source tree.
+   return this->CurrentLocalGenerator->
+     ConvertToRelativePath(this->ProjectSourceDirectoryComponents, p, true);
+ }
+ 
+ //----------------------------------------------------------------------------
+ std::string cmGlobalXCodeGenerator::RelativeToBinary(const char* p)
+ {
+   return this->CurrentLocalGenerator->
+     ConvertToRelativePath(this->ProjectOutputDirectoryComponents, p);
+ }
+ 
+ //----------------------------------------------------------------------------
  std::string cmGlobalXCodeGenerator::XCodeEscapePath(const char* p)
  {

Index: cmGlobalXCodeGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalXCodeGenerator.h,v
retrieving revision 1.62
retrieving revision 1.63
diff -C 2 -d -r1.62 -r1.63
*** cmGlobalXCodeGenerator.h	19 Sep 2009 16:00:09 -0000	1.62
--- cmGlobalXCodeGenerator.h	22 Sep 2009 20:18:31 -0000	1.63
***************
*** 94,97 ****
--- 94,99 ----
                      generators);
    std::string XCodeEscapePath(const char* p);
+   std::string RelativeToSource(const char* p);
+   std::string RelativeToBinary(const char* p);
    std::string ConvertToRelativeForXCode(const char* p);
    std::string ConvertToRelativeForMake(const char* p);
***************
*** 207,210 ****
--- 209,213 ----
    std::set<cmStdString> TargetDoneSet;
    std::vector<std::string> CurrentOutputDirectoryComponents;
+   std::vector<std::string> ProjectSourceDirectoryComponents;
    std::vector<std::string> ProjectOutputDirectoryComponents;
    std::map<cmStdString, cmXCodeObject* > GroupMap;



More information about the Cmake-commits mailing list