diff options
author | Stephen Kelly <steveire@gmail.com> | 2016-10-04 20:56:31 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2016-10-06 18:02:08 (GMT) |
commit | 1ed5f6b39b80ab337551f1fa9601b3257ddd4be7 (patch) | |
tree | 1af60419ab2297157ab5b06ae85de09b9fcb74c5 /Source/cmLocalUnixMakefileGenerator3.cxx | |
parent | 8377d9e00b7a00f1687b947aaf3c9e10b6779df4 (diff) | |
download | CMake-1ed5f6b39b80ab337551f1fa9601b3257ddd4be7.zip CMake-1ed5f6b39b80ab337551f1fa9601b3257ddd4be7.tar.gz CMake-1ed5f6b39b80ab337551f1fa9601b3257ddd4be7.tar.bz2 |
Makefiles: Introduce local RelativePath method
This makes it easier to remove directory-specific state from
cmOutputConverter where it doesn't belong. Of course, this just
relocates the problem to the makefiles generator for now, but that's
better than affecting the core.
Diffstat (limited to 'Source/cmLocalUnixMakefileGenerator3.cxx')
-rw-r--r-- | Source/cmLocalUnixMakefileGenerator3.cxx | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 8825b46..915119c 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -141,7 +141,7 @@ void cmLocalUnixMakefileGenerator3::ComputeHomeRelativeOutputPath() { // Compute the path to use when referencing the current output // directory from the top output directory. - this->HomeRelativeOutputPath = this->ConvertToRelativePath( + this->HomeRelativeOutputPath = this->MaybeConvertToRelativePath( this->GetBinaryDirectory(), this->GetCurrentBinaryDirectory()); if (this->HomeRelativeOutputPath == ".") { this->HomeRelativeOutputPath = ""; @@ -548,7 +548,8 @@ void cmLocalUnixMakefileGenerator3::WriteMakeRule( // Construct the left hand side of the rule. std::string tgt = cmSystemTools::ConvertToOutputPath( - this->ConvertToRelativePath(this->GetBinaryDirectory(), target).c_str()); + this->MaybeConvertToRelativePath(this->GetBinaryDirectory(), target) + .c_str()); const char* space = ""; if (tgt.size() == 1) { @@ -577,7 +578,7 @@ void cmLocalUnixMakefileGenerator3::WriteMakeRule( dep != depends.end(); ++dep) { replace = *dep; replace = cmSystemTools::ConvertToOutputPath( - this->ConvertToRelativePath(binDir, replace).c_str()); + this->MaybeConvertToRelativePath(binDir, replace).c_str()); os << cmMakeSafe(tgt) << space << ": " << cmMakeSafe(replace) << "\n"; } } @@ -969,7 +970,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand( // working directory will be the start-output directory. bool had_slash = cmd.find('/') != cmd.npos; if (workingDir.empty()) { - cmd = this->ConvertToRelativePath(currentBinDir, cmd); + cmd = this->MaybeConvertToRelativePath(currentBinDir, cmd); } bool has_slash = cmd.find('/') != cmd.npos; if (had_slash && !has_slash) { @@ -994,8 +995,8 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand( if (!outputs.empty()) { if (workingDir.empty()) { output = this->ConvertToOutputFormat( - this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), - outputs[0]), + this->MaybeConvertToRelativePath( + this->GetCurrentBinaryDirectory(), outputs[0]), cmOutputConverter::SHELL); } else { @@ -1082,14 +1083,15 @@ void cmLocalUnixMakefileGenerator3::AppendCleanCommand( fout << "file(REMOVE_RECURSE\n"; for (std::vector<std::string>::const_iterator f = files.begin(); f != files.end(); ++f) { - std::string fc = this->ConvertToRelativePath(currentBinDir, *f); + std::string fc = this->MaybeConvertToRelativePath(currentBinDir, *f); fout << " " << cmOutputConverter::EscapeForCMake(fc) << "\n"; } fout << ")\n"; } std::string remove = "$(CMAKE_COMMAND) -P "; remove += this->ConvertToOutputFormat( - this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), cleanfile), + this->MaybeConvertToRelativePath(this->GetCurrentBinaryDirectory(), + cleanfile), cmOutputConverter::SHELL); commands.push_back(remove); @@ -1858,7 +1860,8 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo( } for (std::vector<std::string>::iterator i = includes.begin(); i != includes.end(); ++i) { - cmakefileStream << " \"" << this->ConvertToRelativePath(binaryDir, *i) + cmakefileStream << " \"" + << this->MaybeConvertToRelativePath(binaryDir, *i) << "\"\n"; } cmakefileStream << " )\n"; @@ -1923,7 +1926,7 @@ std::string cmLocalUnixMakefileGenerator3::GetRecursiveMakeCall( if (!tgt.empty()) { // The make target is always relative to the top of the build tree. std::string tgt2 = - this->ConvertToRelativePath(this->GetBinaryDirectory(), tgt); + this->MaybeConvertToRelativePath(this->GetBinaryDirectory(), tgt); // The target may have been written with windows paths. cmSystemTools::ConvertToOutputSlashes(tgt2); @@ -2095,3 +2098,13 @@ void cmLocalUnixMakefileGenerator3::CreateCDCommand( std::bind1st(std::plus<std::string>(), prefix)); } } + +std::string cmLocalUnixMakefileGenerator3::MaybeConvertToRelativePath( + std::string const& base, std::string const& path) +{ + if (!cmOutputConverter::ContainedInDirectory( + base, path, this->GetStateSnapshot().GetDirectory())) { + return path; + } + return cmOutputConverter::ForceToRelativePath(base, path); +} |