summaryrefslogtreecommitdiffstats
path: root/Source/cmLocalGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmLocalGenerator.cxx')
-rw-r--r--Source/cmLocalGenerator.cxx47
1 files changed, 19 insertions, 28 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index c101ff3..4db9216 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -88,7 +88,6 @@ static auto ruleReplaceVars = { "CMAKE_${LANG}_COMPILER",
cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile)
: cmOutputConverter(makefile->GetStateSnapshot())
- , StateSnapshot(makefile->GetStateSnapshot())
, DirectoryBacktrace(makefile->GetBacktrace())
{
this->GlobalGenerator = gg;
@@ -3532,6 +3531,21 @@ bool cmLocalGenerator::IsNinjaMulti() const
return this->GetState()->UseNinjaMulti();
}
+namespace {
+std::string relativeIfUnder(std::string const& top, std::string const& cur,
+ std::string const& path)
+{
+ // Use a path relative to 'cur' if it can be expressed without
+ // a `../` sequence that leaves 'top'.
+ if (cmSystemTools::IsSubDirectory(path, cur) ||
+ (cmSystemTools::IsSubDirectory(cur, top) &&
+ cmSystemTools::IsSubDirectory(path, top))) {
+ return cmSystemTools::ForceToRelativePath(cur, path);
+ }
+ return path;
+}
+}
+
std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
const cmSourceFile& source, std::string const& dir_max,
bool* hasSourceExtension, char const* customOutputExtension)
@@ -3541,13 +3555,15 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
std::string const& fullPath = source.GetFullPath();
// Try referencing the source relative to the source tree.
- std::string relFromSource = this->MaybeRelativeToCurSrcDir(fullPath);
+ std::string relFromSource = relativeIfUnder(
+ this->GetSourceDirectory(), 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->MaybeRelativeToCurBinDir(fullPath);
+ std::string relFromBinary = relativeIfUnder(
+ this->GetBinaryDirectory(), this->GetCurrentBinaryDirectory(), fullPath);
assert(!relFromBinary.empty());
bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary);
bool subBinary = relBinary && relFromBinary[0] != '.';
@@ -3662,31 +3678,6 @@ std::string const& cmLocalGenerator::GetCurrentSourceDirectory() const
return this->StateSnapshot.GetDirectory().GetCurrentSource();
}
-std::string cmLocalGenerator::MaybeRelativeTo(
- std::string const& local_path, std::string const& remote_path) const
-{
- return this->StateSnapshot.GetDirectory().ConvertToRelPathIfContained(
- local_path, remote_path);
-}
-
-std::string cmLocalGenerator::MaybeRelativeToTopBinDir(
- std::string const& path) const
-{
- return this->MaybeRelativeTo(this->GetBinaryDirectory(), path);
-}
-
-std::string cmLocalGenerator::MaybeRelativeToCurBinDir(
- std::string const& path) const
-{
- return this->MaybeRelativeTo(this->GetCurrentBinaryDirectory(), path);
-}
-
-std::string cmLocalGenerator::MaybeRelativeToCurSrcDir(
- std::string const& path) const
-{
- return this->MaybeRelativeTo(this->GetCurrentSourceDirectory(), path);
-}
-
std::string cmLocalGenerator::GetTargetDirectory(
const cmGeneratorTarget* /*unused*/) const
{