summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-01-29 14:17:13 +0000
committerKitware Robot <kwrobot@kitware.com>2019-01-29 09:18:42 -0500
commit60c06620a690f0cbeeaa3fba762e19cd031669ca (patch)
treec72e5f4bd45dc2a769e0c7f7bcbbfbd108f0e0f7
parent90ac5e6384735deb0ac523684010b2f4701d4f4d (diff)
parentb6a957c9696706a338cdeef63540bf8a4c42d22d (diff)
downloadcmake-60c06620a690f0cbeeaa3fba762e19cd031669ca.tar.gz
Merge topic 'cmoutputconverter-simplify'
b6a957c969 cmOutputConverter: move ConvertToRelativePath to cmStateDirectory. Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !2831
-rw-r--r--Source/cmCommonTargetGenerator.cxx2
-rw-r--r--Source/cmDependsC.cxx6
-rw-r--r--Source/cmExtraEclipseCDT4Generator.cxx2
-rw-r--r--Source/cmGhsMultiTargetGenerator.cxx5
-rw-r--r--Source/cmGlobalGenerator.cxx6
-rw-r--r--Source/cmGlobalGhsMultiGenerator.cxx2
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx2
-rw-r--r--Source/cmGlobalUnixMakefileGenerator3.cxx21
-rw-r--r--Source/cmGlobalVisualStudio7Generator.cxx2
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx2
-rw-r--r--Source/cmListFileCache.cxx8
-rw-r--r--Source/cmLocalCommonGenerator.cxx2
-rw-r--r--Source/cmLocalGenerator.cxx19
-rw-r--r--Source/cmLocalGenerator.h10
-rw-r--r--Source/cmLocalNinjaGenerator.cxx9
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.cxx9
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.h3
-rw-r--r--Source/cmLocalVisualStudio7Generator.cxx10
-rw-r--r--Source/cmLocalVisualStudioGenerator.cxx7
-rw-r--r--Source/cmOutputConverter.cxx12
-rw-r--r--Source/cmOutputConverter.h10
-rw-r--r--Source/cmStateDirectory.cxx9
-rw-r--r--Source/cmStateDirectory.h3
-rw-r--r--Source/cmTarget.cxx6
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx8
25 files changed, 89 insertions, 86 deletions
diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx
index a1df27107f..0414817547 100644
--- a/Source/cmCommonTargetGenerator.cxx
+++ b/Source/cmCommonTargetGenerator.cxx
@@ -198,7 +198,7 @@ std::string cmCommonTargetGenerator::GetManifests()
manifests.reserve(manifest_srcs.size());
for (cmSourceFile const* manifest_src : manifest_srcs) {
manifests.push_back(this->LocalCommonGenerator->ConvertToOutputFormat(
- this->LocalCommonGenerator->ConvertToRelativePath(
+ this->LocalCommonGenerator->MaybeConvertToRelativePath(
this->LocalCommonGenerator->GetWorkingDirectory(),
manifest_src->GetFullPath()),
cmOutputConverter::SHELL));
diff --git a/Source/cmDependsC.cxx b/Source/cmDependsC.cxx
index ea24f09bcd..2043d7c0aa 100644
--- a/Source/cmDependsC.cxx
+++ b/Source/cmDependsC.cxx
@@ -100,7 +100,8 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
// Compute a path to the object file to write to the internal depend file.
// Any existing content of the internal depend file has already been
// loaded in ValidDeps with this path as a key.
- std::string obj_i = this->LocalGenerator->ConvertToRelativePath(binDir, obj);
+ std::string obj_i =
+ this->LocalGenerator->MaybeConvertToRelativePath(binDir, obj);
if (this->ValidDeps != nullptr) {
std::map<std::string, DependencyVector>::const_iterator tmpIt =
@@ -234,7 +235,8 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
for (std::string const& dep : dependencies) {
makeDepends << obj_m << ": "
<< cmSystemTools::ConvertToOutputPath(
- this->LocalGenerator->ConvertToRelativePath(binDir, dep))
+ this->LocalGenerator->MaybeConvertToRelativePath(binDir,
+ dep))
<< std::endl;
internalDepends << " " << dep << std::endl;
}
diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx
index 5833631052..30067b75b6 100644
--- a/Source/cmExtraEclipseCDT4Generator.cxx
+++ b/Source/cmExtraEclipseCDT4Generator.cxx
@@ -899,7 +899,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
const std::vector<cmGeneratorTarget*>& targets =
lgen->GetGeneratorTargets();
- std::string subdir = lgen->ConvertToRelativePath(
+ std::string subdir = lgen->MaybeConvertToRelativePath(
this->HomeOutputDirectory, lgen->GetCurrentBinaryDirectory());
if (subdir == ".") {
subdir.clear();
diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx
index c253937529..04a8b3c50d 100644
--- a/Source/cmGhsMultiTargetGenerator.cxx
+++ b/Source/cmGhsMultiTargetGenerator.cxx
@@ -150,7 +150,8 @@ void cmGhsMultiTargetGenerator::WriteTargetSpecifics(std::ostream& fout,
if (this->TagType != GhsMultiGpj::SUBPROJECT) {
// set target binary file destination
outpath = this->GeneratorTarget->GetDirectory(config);
- outpath = this->LocalGenerator->ConvertToRelativePath(rootpath, outpath);
+ outpath =
+ this->LocalGenerator->MaybeConvertToRelativePath(rootpath, outpath);
fout << " :binDirRelative=\"" << outpath << "\"" << std::endl;
fout << " -o \"" << this->TargetNameReal << "\"" << std::endl;
}
@@ -550,7 +551,7 @@ void cmGhsMultiTargetGenerator::WriteReferences(std::ostream& fout)
std::string tpath = t->LocalGenerator->GetCurrentBinaryDirectory();
std::string rootpath = this->LocalGenerator->GetCurrentBinaryDirectory();
std::string outpath =
- this->LocalGenerator->ConvertToRelativePath(rootpath, tpath) + "/" +
+ this->LocalGenerator->MaybeConvertToRelativePath(rootpath, tpath) + "/" +
tname + "REF" + cmGlobalGhsMultiGenerator::FILE_EXTENSION;
fout << outpath;
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 58d0971ee8..b8626abaaf 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -33,7 +33,6 @@
#include "cmMSVC60LinkLineComputer.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
-#include "cmOutputConverter.h"
#include "cmPolicies.h"
#include "cmSourceFile.h"
#include "cmState.h"
@@ -2794,8 +2793,9 @@ void cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs,
}
// Shorten the output name (in expected use case).
- cmOutputConverter converter(this->GetMakefiles()[0]->GetStateSnapshot());
- std::string fname = converter.ConvertToRelativePath(
+ cmStateDirectory cmDir =
+ this->GetMakefiles()[0]->GetStateSnapshot().GetDirectory();
+ std::string fname = cmDir.ConvertToRelPathIfNotContained(
this->GetMakefiles()[0]->GetState()->GetBinaryDirectory(), outputs[0]);
// Associate the hash with this output.
diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx
index bb8b77249c..5720502585 100644
--- a/Source/cmGlobalGhsMultiGenerator.cxx
+++ b/Source/cmGlobalGhsMultiGenerator.cxx
@@ -297,7 +297,7 @@ void cmGlobalGhsMultiGenerator::WriteSubProjects(
if (projName && projType) {
cmLocalGenerator* lg = target->GetLocalGenerator();
std::string dir = lg->GetCurrentBinaryDirectory();
- dir = root->ConvertToRelativePath(rootBinaryDir, dir.c_str());
+ dir = root->MaybeConvertToRelativePath(rootBinaryDir, dir.c_str());
if (dir == ".") {
dir.clear();
} else {
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 23dbd76b2a..8f095660e3 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -861,7 +861,7 @@ std::string const& cmGlobalNinjaGenerator::ConvertToNinjaPath(
cmLocalNinjaGenerator* ng =
static_cast<cmLocalNinjaGenerator*>(this->LocalGenerators[0]);
std::string const& bin_dir = ng->GetState()->GetBinaryDirectory();
- std::string convPath = ng->ConvertToRelativePath(bin_dir, path);
+ std::string convPath = ng->MaybeConvertToRelativePath(bin_dir, path);
convPath = this->NinjaOutputPath(convPath);
#ifdef _WIN32
std::replace(convPath.begin(), convPath.end(), '/', '\\');
diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx
index 792adc0071..3ca2b17528 100644
--- a/Source/cmGlobalUnixMakefileGenerator3.cxx
+++ b/Source/cmGlobalUnixMakefileGenerator3.cxx
@@ -325,7 +325,8 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
<< "set(CMAKE_MAKEFILE_DEPENDS\n"
<< " \"CMakeCache.txt\"\n";
for (std::string const& f : lfiles) {
- cmakefileStream << " \"" << lg->ConvertToRelativePath(currentBinDir, f)
+ cmakefileStream << " \""
+ << lg->MaybeConvertToRelativePath(currentBinDir, f)
<< "\"\n";
}
cmakefileStream << " )\n\n";
@@ -339,9 +340,11 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
cmakefileStream << "# The corresponding makefile is:\n"
<< "set(CMAKE_MAKEFILE_OUTPUTS\n"
<< " \""
- << lg->ConvertToRelativePath(currentBinDir, makefileName)
+ << lg->MaybeConvertToRelativePath(currentBinDir,
+ makefileName)
<< "\"\n"
- << " \"" << lg->ConvertToRelativePath(currentBinDir, check)
+ << " \""
+ << lg->MaybeConvertToRelativePath(currentBinDir, check)
<< "\"\n";
cmakefileStream << " )\n\n";
@@ -354,7 +357,8 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
const std::vector<std::string>& outfiles =
lg->GetMakefile()->GetOutputFiles();
for (std::string const& outfile : outfiles) {
- cmakefileStream << " \"" << lg->ConvertToRelativePath(binDir, outfile)
+ cmakefileStream << " \""
+ << lg->MaybeConvertToRelativePath(binDir, outfile)
<< "\"\n";
}
@@ -365,7 +369,8 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
tmpStr = lg->GetCurrentBinaryDirectory();
tmpStr += "/CMakeFiles";
tmpStr += "/CMakeDirectoryInformation.cmake";
- cmakefileStream << " \"" << lg->ConvertToRelativePath(binDir, tmpStr)
+ cmakefileStream << " \""
+ << lg->MaybeConvertToRelativePath(binDir, tmpStr)
<< "\"\n";
}
cmakefileStream << " )\n\n";
@@ -474,7 +479,7 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRules2(
// Begin the directory-level rules section.
std::string dir =
- cmSystemTools::ConvertToOutputPath(lg->ConvertToRelativePath(
+ cmSystemTools::ConvertToOutputPath(lg->MaybeConvertToRelativePath(
lg->GetBinaryDirectory(), lg->GetCurrentBinaryDirectory()));
lg->WriteDivider(ruleFileStream);
ruleFileStream << "# Directory level rules for directory " << dir << "\n\n";
@@ -526,9 +531,9 @@ void cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
if (fast) {
tname += "/fast";
}
- cmOutputConverter conv(mf->GetStateSnapshot());
tname =
- conv.ConvertToRelativePath(mf->GetState()->GetBinaryDirectory(), tname);
+ mf->GetStateSnapshot().GetDirectory().ConvertToRelPathIfNotContained(
+ mf->GetState()->GetBinaryDirectory(), tname);
cmSystemTools::ConvertToOutputSlashes(tname);
makeCommand.push_back(std::move(tname));
}
diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx
index cae46e1d8c..c267a7b03f 100644
--- a/Source/cmGlobalVisualStudio7Generator.cxx
+++ b/Source/cmGlobalVisualStudio7Generator.cxx
@@ -367,7 +367,7 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
if (vcprojName) {
cmLocalGenerator* lg = target->GetLocalGenerator();
std::string dir = lg->GetCurrentBinaryDirectory();
- dir = root->ConvertToRelativePath(rootBinaryDir, dir.c_str());
+ dir = root->MaybeConvertToRelativePath(rootBinaryDir, dir.c_str());
if (dir == ".") {
dir.clear(); // msbuild cannot handle ".\" prefix
}
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 0d70a0e78a..35a09a7da9 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -3581,7 +3581,7 @@ std::string cmGlobalXCodeGenerator::RelativeToSource(const char* p)
std::string cmGlobalXCodeGenerator::RelativeToBinary(const char* p)
{
- return this->CurrentLocalGenerator->ConvertToRelativePath(
+ return this->CurrentLocalGenerator->MaybeConvertToRelativePath(
cmSystemTools::JoinPath(this->ProjectOutputDirectoryComponents), p);
}
diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx
index cc2c09fb82..f85511964a 100644
--- a/Source/cmListFileCache.cxx
+++ b/Source/cmListFileCache.cxx
@@ -5,8 +5,8 @@
#include "cmListFileLexer.h"
#include "cmMessageType.h"
#include "cmMessenger.h"
-#include "cmOutputConverter.h"
#include "cmState.h"
+#include "cmStateDirectory.h"
#include "cmSystemTools.h"
#include <assert.h>
@@ -390,9 +390,8 @@ void cmListFileBacktrace::PrintTitle(std::ostream& out) const
}
cmListFileContext lfc = this->TopEntry->Context;
cmStateSnapshot bottom = this->GetBottom();
- cmOutputConverter converter(bottom);
if (!bottom.GetState()->GetIsInTryCompile()) {
- lfc.FilePath = converter.ConvertToRelativePath(
+ lfc.FilePath = bottom.GetDirectory().ConvertToRelPathIfNotContained(
bottom.GetState()->GetSourceDirectory(), lfc.FilePath);
}
out << (lfc.Line ? " at " : " in ") << lfc;
@@ -409,7 +408,6 @@ void cmListFileBacktrace::PrintCallStack(std::ostream& out) const
bool first = true;
cmStateSnapshot bottom = this->GetBottom();
- cmOutputConverter converter(bottom);
for (Entry const* cur = this->TopEntry->Parent.get(); !cur->IsBottom();
cur = cur->Parent.get()) {
if (cur->Context.Name.empty()) {
@@ -423,7 +421,7 @@ void cmListFileBacktrace::PrintCallStack(std::ostream& out) const
}
cmListFileContext lfc = cur->Context;
if (!bottom.GetState()->GetIsInTryCompile()) {
- lfc.FilePath = converter.ConvertToRelativePath(
+ lfc.FilePath = bottom.GetDirectory().ConvertToRelPathIfNotContained(
bottom.GetState()->GetSourceDirectory(), lfc.FilePath);
}
out << " " << lfc << "\n";
diff --git a/Source/cmLocalCommonGenerator.cxx b/Source/cmLocalCommonGenerator.cxx
index c6d2c5873c..eef1c7cc86 100644
--- a/Source/cmLocalCommonGenerator.cxx
+++ b/Source/cmLocalCommonGenerator.cxx
@@ -46,7 +46,7 @@ std::string cmLocalCommonGenerator::GetTargetFortranFlags(
target->GetFortranModuleDirectory(this->WorkingDirectory);
if (!mod_dir.empty()) {
mod_dir = this->ConvertToOutputFormat(
- this->ConvertToRelativePath(this->WorkingDirectory, mod_dir),
+ this->MaybeConvertToRelativePath(this->WorkingDirectory, mod_dir),
cmOutputConverter::SHELL);
} else {
mod_dir =
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 24bc7fac08..252aa4c213 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -316,7 +316,7 @@ void cmLocalGenerator::GenerateTestFiles()
for (cmStateSnapshot const& i : children) {
// TODO: Use add_subdirectory instead?
std::string outP = i.GetDirectory().GetCurrentBinary();
- outP = this->ConvertToRelativePath(parentBinDir, outP);
+ outP = this->MaybeConvertToRelativePath(parentBinDir, outP);
outP = cmOutputConverter::EscapeForCMake(outP);
fout << "subdirs(" << outP << ")" << std::endl;
}
@@ -2321,7 +2321,7 @@ std::string cmLocalGenerator::ConstructComment(
std::string currentBinaryDir = this->GetCurrentBinaryDirectory();
for (std::string const& o : ccg.GetOutputs()) {
comment += sep;
- comment += this->ConvertToRelativePath(currentBinaryDir, o);
+ comment += this->MaybeConvertToRelativePath(currentBinaryDir, o);
sep = ", ";
}
return comment;
@@ -2578,15 +2578,15 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
std::string const& fullPath = source.GetFullPath();
// Try referencing the source relative to the source tree.
- std::string relFromSource =
- this->ConvertToRelativePath(this->GetCurrentSourceDirectory(), fullPath);
+ std::string relFromSource = this->MaybeConvertToRelativePath(
+ this->GetCurrentSourceDirectory(), fullPath);
assert(!relFromSource.empty());
bool relSource = !cmSystemTools::FileIsFullPath(relFromSource);
bool subSource = relSource && relFromSource[0] != '.';
// Try referencing the source relative to the binary tree.
- std::string relFromBinary =
- this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), fullPath);
+ std::string relFromBinary = this->MaybeConvertToRelativePath(
+ this->GetCurrentBinaryDirectory(), fullPath);
assert(!relFromBinary.empty());
bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary);
bool subBinary = relBinary && relFromBinary[0] != '.';
@@ -2685,6 +2685,13 @@ std::string const& cmLocalGenerator::GetCurrentSourceDirectory() const
return this->StateSnapshot.GetDirectory().GetCurrentSource();
}
+std::string cmLocalGenerator::MaybeConvertToRelativePath(
+ std::string const& local_path, std::string const& remote_path) const
+{
+ return this->StateSnapshot.GetDirectory().ConvertToRelPathIfNotContained(
+ local_path, remote_path);
+}
+
std::string cmLocalGenerator::GetTargetDirectory(
const cmGeneratorTarget* /*unused*/) const
{
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index 7cc7e37cf6..f9839f6c19 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -326,6 +326,16 @@ public:
std::string const& GetCurrentSourceDirectory() const;
/**
+ * Convert the given remote path to a relative path with respect to
+ * the given local path. Both paths must use forward slashes and not
+ * already be escaped or quoted.
+ * The conversion is skipped if the paths are not both in the source
+ * or both in the binary tree.
+ */
+ std::string MaybeConvertToRelativePath(std::string const& local_path,
+ std::string const& remote_path) const;
+
+ /**
* Generate a macOS application bundle Info.plist file.
*/
void GenerateAppleInfoPList(cmGeneratorTarget* target,
diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx
index 4b9837ce9b..7417e80c28 100644
--- a/Source/cmLocalNinjaGenerator.cxx
+++ b/Source/cmLocalNinjaGenerator.cxx
@@ -54,7 +54,7 @@ void cmLocalNinjaGenerator::Generate()
{
// 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.clear();
@@ -139,7 +139,8 @@ std::string cmLocalNinjaGenerator::ConvertToIncludeReference(
format);
}
return this->ConvertToOutputFormat(
- this->ConvertToRelativePath(this->GetBinaryDirectory(), path), format);
+ this->MaybeConvertToRelativePath(this->GetBinaryDirectory(), path),
+ format);
}
// Private methods.
@@ -582,8 +583,8 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher(
if (!outputs.empty()) {
output = outputs[0];
if (ccg.GetWorkingDirectory().empty()) {
- output =
- this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), output);
+ output = this->MaybeConvertToRelativePath(
+ this->GetCurrentBinaryDirectory(), output);
}
output = this->ConvertToOutputFormat(output, cmOutputConverter::SHELL);
}
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx
index 173ac7a448..55ce50bbcc 100644
--- a/Source/cmLocalUnixMakefileGenerator3.cxx
+++ b/Source/cmLocalUnixMakefileGenerator3.cxx
@@ -2079,12 +2079,3 @@ void cmLocalUnixMakefileGenerator3::CreateCDCommand(
[&prefix](std::string const& s) { return prefix + s; });
}
}
-
-std::string cmLocalUnixMakefileGenerator3::MaybeConvertToRelativePath(
- std::string const& base, std::string const& path)
-{
- if (!this->GetStateSnapshot().GetDirectory().ContainsBoth(base, path)) {
- return path;
- }
- return cmSystemTools::ForceToRelativePath(base, path);
-}
diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h
index 1e1c59ea92..d83c9bb554 100644
--- a/Source/cmLocalUnixMakefileGenerator3.h
+++ b/Source/cmLocalUnixMakefileGenerator3.h
@@ -184,9 +184,6 @@ public:
// Eclipse generator.
void GetIndividualFileTargets(std::vector<std::string>& targets);
- std::string MaybeConvertToRelativePath(std::string const& base,
- std::string const& path);
-
protected:
void WriteLocalMakefile();
diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx
index 9ea8c2e28b..7019552c3a 100644
--- a/Source/cmLocalVisualStudio7Generator.cxx
+++ b/Source/cmLocalVisualStudio7Generator.cxx
@@ -803,8 +803,8 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
target->GetProperty("Fortran_MODULE_DIRECTORY");
std::string modDir;
if (target_mod_dir) {
- modDir = this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(),
- target_mod_dir);
+ modDir = this->MaybeConvertToRelativePath(
+ this->GetCurrentBinaryDirectory(), target_mod_dir);
} else {
modDir = ".";
}
@@ -1306,7 +1306,7 @@ void cmLocalVisualStudio7GeneratorInternals::OutputLibraries(
for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) {
if (l->IsPath) {
std::string rel =
- lg->ConvertToRelativePath(currentBinDir, l->Value.c_str());
+ lg->MaybeConvertToRelativePath(currentBinDir, l->Value.c_str());
fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
} else if (!l->Target ||
l->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
@@ -1332,7 +1332,7 @@ void cmLocalVisualStudio7GeneratorInternals::OutputObjects(
i != objs.end(); ++i) {
if (!(*i)->GetObjectLibrary().empty()) {
std::string const& objFile = (*i)->GetFullPath();
- std::string rel = lg->ConvertToRelativePath(currentBinDir, objFile);
+ std::string rel = lg->MaybeConvertToRelativePath(currentBinDir, objFile);
fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
sep = " ";
}
@@ -1358,7 +1358,7 @@ void cmLocalVisualStudio7Generator::OutputLibraryDirectories(
// Switch to a relative path specification if it is shorter.
if (cmSystemTools::FileIsFullPath(dir.c_str())) {
std::string rel =
- this->ConvertToRelativePath(currentBinDir, dir.c_str());
+ this->MaybeConvertToRelativePath(currentBinDir, dir.c_str());
if (rel.size() < dir.size()) {
dir = rel;
}
diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx
index 2237da75fb..660729c3ac 100644
--- a/Source/cmLocalVisualStudioGenerator.cxx
+++ b/Source/cmLocalVisualStudioGenerator.cxx
@@ -210,9 +210,10 @@ std::string cmLocalVisualStudioGenerator::ConstructScript(
}
if (workingDirectory.empty()) {
- script += this->ConvertToOutputFormat(
- this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), cmd),
- cmOutputConverter::SHELL);
+ script +=
+ this->ConvertToOutputFormat(this->MaybeConvertToRelativePath(
+ this->GetCurrentBinaryDirectory(), cmd),
+ cmOutputConverter::SHELL);
} else {
script += this->ConvertToOutputFormat(cmd.c_str(), SHELL);
}
diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx
index 011c7d896b..7d88b088e8 100644
--- a/Source/cmOutputConverter.cxx
+++ b/Source/cmOutputConverter.cxx
@@ -10,7 +10,6 @@
#include <vector>
#include "cmState.h"
-#include "cmStateDirectory.h"
#include "cmSystemTools.h"
cmOutputConverter::cmOutputConverter(cmStateSnapshot const& snapshot)
@@ -72,17 +71,6 @@ std::string cmOutputConverter::ConvertDirectorySeparatorsForShell(
return result;
}
-std::string cmOutputConverter::ConvertToRelativePath(
- std::string const& local_path, std::string const& remote_path) const
-{
- if (!this->StateSnapshot.GetDirectory().ContainsBoth(local_path,
- remote_path)) {
- return remote_path;
- }
-
- return cmSystemTools::ForceToRelativePath(local_path, remote_path);
-}
-
static bool cmOutputConverterIsShellOperator(const std::string& str)
{
static std::set<std::string> shellOperators;
diff --git a/Source/cmOutputConverter.h b/Source/cmOutputConverter.h
index 5a4f879813..6438c7bad4 100644
--- a/Source/cmOutputConverter.h
+++ b/Source/cmOutputConverter.h
@@ -91,16 +91,6 @@ public:
};
static FortranFormat GetFortranFormat(const char* value);
- /**
- * Convert the given remote path to a relative path with respect to
- * the given local path. Both paths must use forward slashes and not
- * already be escaped or quoted.
- * The conversion is skipped if the paths are not both in the source
- * or both in the binary tree.
- */
- std::string ConvertToRelativePath(std::string const& local_path,
- std::string const& remote_path) const;
-
private:
cmState* GetState() const;
diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx
index 40f694c0d9..6752743a1f 100644
--- a/Source/cmStateDirectory.cxx
+++ b/Source/cmStateDirectory.cxx
@@ -155,6 +155,15 @@ bool cmStateDirectory::ContainsBoth(std::string const& local_path,
return bothInBinary || bothInSource;
}
+std::string cmStateDirectory::ConvertToRelPathIfNotContained(
+ std::string const& local_path, std::string const& remote_path) const
+{
+ if (!this->ContainsBoth(local_path, remote_path)) {
+ return remote_path;
+ }
+ return cmSystemTools::ForceToRelativePath(local_path, remote_path);
+}
+
cmStateDirectory::cmStateDirectory(
cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator iter,
const cmStateSnapshot& snapshot)
diff --git a/Source/cmStateDirectory.h b/Source/cmStateDirectory.h
index c4b18adf16..69565940d6 100644
--- a/Source/cmStateDirectory.h
+++ b/Source/cmStateDirectory.h
@@ -35,6 +35,9 @@ public:
bool ContainsBoth(std::string const& local_path,
std::string const& remote_path) const;
+ std::string ConvertToRelPathIfNotContained(
+ std::string const& local_path, std::string const& remote_path) const;
+
cmStringRange GetIncludeDirectoriesEntries() const;
cmBacktraceRange GetIncludeDirectoriesEntryBacktraces() const;
void AppendIncludeDirectoriesEntry(std::string const& vec,
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index fe4893456e..93cdd46ce9 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -19,7 +19,6 @@
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmMessenger.h"
-#include "cmOutputConverter.h"
#include "cmProperty.h"
#include "cmSourceFile.h"
#include "cmSourceFileLocation.h"
@@ -747,11 +746,12 @@ void cmTarget::GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const
const char* sigString =
(sig == cmTarget::KeywordTLLSignature ? "keyword" : "plain");
s << "The uses of the " << sigString << " signature are here:\n";
- cmOutputConverter converter(this->GetMakefile()->GetStateSnapshot());
+ cmStateDirectory cmDir =
+ this->GetMakefile()->GetStateSnapshot().GetDirectory();
for (auto const& cmd : this->TLLCommands) {
if (cmd.first == sig) {
cmListFileContext lfc = cmd.second;
- lfc.FilePath = converter.ConvertToRelativePath(
+ lfc.FilePath = cmDir.ConvertToRelPathIfNotContained(
this->Makefile->GetState()->GetSourceDirectory(), lfc.FilePath);
s << " * " << lfc << std::endl;
}
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index ac4a4f526f..9d7dd07d8b 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -3584,8 +3584,8 @@ bool cmVisualStudio10TargetGenerator::ComputeLibOptions(
this->LocalGenerator->GetCurrentBinaryDirectory();
for (cmComputeLinkInformation::Item const& l : libs) {
if (l.IsPath && cmVS10IsTargetsFile(l.Value)) {
- std::string path =
- this->LocalGenerator->ConvertToRelativePath(currentBinDir, l.Value);
+ std::string path = this->LocalGenerator->MaybeConvertToRelativePath(
+ currentBinDir, l.Value);
ConvertToWindowsSlash(path);
this->AddTargetsFileAndConfigPair(path, config);
}
@@ -3668,8 +3668,8 @@ void cmVisualStudio10TargetGenerator::AddLibraries(
}
if (l.IsPath) {
- std::string path =
- this->LocalGenerator->ConvertToRelativePath(currentBinDir, l.Value);
+ std::string path = this->LocalGenerator->MaybeConvertToRelativePath(
+ currentBinDir, l.Value);
ConvertToWindowsSlash(path);
if (cmVS10IsTargetsFile(l.Value)) {
vsTargetVec.push_back(path);