From 61495cdaaeb5800da09513ad78ae2f4fc5e62a79 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 22 Sep 2009 16:18:31 -0400 Subject: 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. --- Source/cmGlobalXCodeGenerator.cxx | 87 ++++++++++++++------------------------- Source/cmGlobalXCodeGenerator.h | 3 ++ 2 files changed, 34 insertions(+), 56 deletions(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index bacc8c3..225d271 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -302,9 +302,9 @@ void cmGlobalXCodeGenerator::SetGenerationRoot(cmLocalGenerator* root) { 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(), + cmSystemTools::SplitPath(this->CurrentMakefile->GetCurrentDirectory(), + this->ProjectSourceDirectoryComponents); + cmSystemTools::SplitPath(this->CurrentMakefile->GetCurrentOutputDirectory(), this->ProjectOutputDirectoryComponents); this->CurrentXCodeHackMakefile = @@ -670,49 +670,18 @@ cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf, fileRef->AddAttribute("lastKnownFileType", 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())); + // 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())? + "" : "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")); } - if(path.size() > 1 && path[0] == '.' && path[1] == '.') - { - fileRef->AddAttribute("sourceTree", this->CreateString("")); - } - else if (Absolute) - { - fileRef->AddAttribute("sourceTree", this->CreateString("")); - } - else - { - fileRef->AddAttribute("sourceTree", this->CreateString("SOURCE_ROOT")); - } - return fileRef; } @@ -2610,24 +2579,14 @@ void cmGlobalXCodeGenerator else 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())); - } + 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 = this->CreateObject(cmXCodeObject::XCConfigurationList); @@ -3067,6 +3026,22 @@ std::string cmGlobalXCodeGenerator::ConvertToRelativeForXCode(const char* p) } //---------------------------------------------------------------------------- +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) { std::string ret = p; diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index 3dd105c..189d7fb 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -93,6 +93,8 @@ private: std::vector& 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); void CreateCustomCommands(cmXCodeObject* buildPhases, @@ -206,6 +208,7 @@ private: std::string CurrentProject; std::set TargetDoneSet; std::vector CurrentOutputDirectoryComponents; + std::vector ProjectSourceDirectoryComponents; std::vector ProjectOutputDirectoryComponents; std::map GroupMap; std::map GroupNameMap; -- cgit v0.12