From 4248132e59a8401a96d9c20ef155d80e439e7346 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 27 Apr 2012 10:42:23 -0400 Subject: [PATCH] VS10: Convert paths normally unless forced to relative Most CMake generators produce relative paths within the build tree and full paths to files outside the build tree. Make VS 10 and VS 11 project files consistent with this approach except for paths forced to be relative to work around a VS 10 bug. --- Source/cmVisualStudio10TargetGenerator.cxx | 39 +++++++++++----------- Source/cmVisualStudio10TargetGenerator.h | 1 + 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index c4d5415c0..7c38d4b6b 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -536,6 +536,18 @@ cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile* source, this->WriteString("\n", 2); } +std::string +cmVisualStudio10TargetGenerator::ConvertPath(std::string const& path, + bool forceRelative) +{ + return forceRelative + ? cmSystemTools::RelativePath( + this->Makefile->GetCurrentOutputDirectory(), path.c_str()) + : this->LocalGenerator->Convert(path.c_str(), + cmLocalGenerator::START_OUTPUT, + cmLocalGenerator::UNCHANGED); +} + void cmVisualStudio10TargetGenerator::ConvertToWindowsSlash(std::string& s) { // first convert all of the slashes @@ -716,10 +728,7 @@ WriteGroupSources(const char* name, this->Makefile->FindSourceGroup(source.c_str(), sourceGroups); const char* filter = sourceGroup.GetFullName(); this->WriteString("<", 2); - std::string path = s->RelativePath? - cmSystemTools::RelativePath( - this->Makefile->GetCurrentOutputDirectory(), - source.c_str()) : source; + std::string path = this->ConvertPath(source, s->RelativePath); this->ConvertToWindowsSlash(path); (*this->BuildFileStream) << name << " Include=\"" << path; @@ -743,25 +752,17 @@ void cmVisualStudio10TargetGenerator::WriteSource( const char* tool, cmSourceFile* sf, const char* end) { std::string sourceFile = sf->GetFullPath(); - bool relative = sf->GetCustomCommand()? true:false; - if(relative) - { - // custom command sources must use relative paths or they will - // not show up in the GUI. - sourceFile = cmSystemTools::RelativePath( - this->Makefile->GetCurrentOutputDirectory(), - sourceFile.c_str()); - } - else - { - // do not use a relative path here because it means that you - // can not use as long a path to the file. - } + // do not use a relative path here because it means that you + // can not use as long a path to the file. + // custom command sources must use relative paths or they will + // not show up in the GUI. + bool forceRelative = sf->GetCustomCommand()? true:false; + sourceFile = this->ConvertPath(sourceFile, forceRelative); this->ConvertToWindowsSlash(sourceFile); this->WriteString("<", 2); (*this->BuildFileStream ) << tool << " Include=\"" << sourceFile << "\"" << (end? end : " />\n"); - ToolSource toolSource = {sf, relative}; + ToolSource toolSource = {sf, forceRelative}; this->Tools[tool].push_back(toolSource); } diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index c00d328a6..2d5ec2a6b 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -50,6 +50,7 @@ private: }; struct ToolSources: public std::vector {}; + std::string ConvertPath(std::string const& path, bool forceRelative); void ConvertToWindowsSlash(std::string& s); void WriteString(const char* line, int indentLevel); void WriteProjectConfigurations();