summaryrefslogtreecommitdiffstats
path: root/Source/cmLocalGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-05-14 16:33:34 (GMT)
committerBrad King <brad.king@kitware.com>2021-05-17 14:03:43 (GMT)
commitd6fe1bdb6d79516a68a88d5f5a11d2531dae7074 (patch)
treecfb40d9001c772a363be530bb07abd6a1920d197 /Source/cmLocalGenerator.cxx
parent4cb6a53bf524258c34440fc573ab6a9a4de0f0b2 (diff)
downloadCMake-d6fe1bdb6d79516a68a88d5f5a11d2531dae7074.zip
CMake-d6fe1bdb6d79516a68a88d5f5a11d2531dae7074.tar.gz
CMake-d6fe1bdb6d79516a68a88d5f5a11d2531dae7074.tar.bz2
cmLocalGenerator: Localize logic mapping source path to object file name
We select an object file name based on the path to its source file. Localize the logic for shortening this via relative paths. It does not need to use the generator-wide relative path conversion rules because we are not actually generating a relative path that needs to be consistent with anything else.
Diffstat (limited to 'Source/cmLocalGenerator.cxx')
-rw-r--r--Source/cmLocalGenerator.cxx21
1 files changed, 19 insertions, 2 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index c101ff3..79ad46f 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -3532,6 +3532,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 +3556,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] != '.';