cmLocalGenerator: support shortening object filenames

This commit is contained in:
John Parent
2025-05-21 23:12:43 +02:00
committed by Ben Boeckel
parent 76f01de30e
commit 1feb801463
3 changed files with 38 additions and 1 deletions

View File

@@ -104,6 +104,9 @@ std::string cmLocalCommonGenerator::ComputeLongTargetDirectory(
std::string cmLocalCommonGenerator::GetTargetDirectory(
cmGeneratorTarget const* target) const
{
if (target->GetUseShortObjectNames()) {
return this->ComputeShortTargetDirectory(target);
}
return this->ComputeLongTargetDirectory(target);
}

View File

@@ -4242,6 +4242,14 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
}
}
// Short object path policy selected, use as little info as necessary to
// select an object name
bool keptSourceExtension = true;
if (this->UseShortObjectNames()) {
objectName = this->GetShortObjectFileName(source);
keptSourceExtension = false;
}
// Ensure that for the CMakeFiles/<target>.dir/generated_source_file
// we don't end up having:
// CMakeFiles/<target>.dir/CMakeFiles/<target>.dir/generated_source_file.obj
@@ -4261,7 +4269,6 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
// Replace the original source file extension with the object file
// extension.
bool keptSourceExtension = true;
if (!source.GetPropertyAsBool("KEEP_EXTENSION")) {
// Decide whether this language wants to replace the source
// extension with the object extension.
@@ -4281,6 +4288,10 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
}
}
// Strip source file extension when shortening object file paths
if (this->UseShortObjectNames()) {
objectName = cmSystemTools::GetFilenameWithoutExtension(objectName);
}
// Store the new extension.
if (customOutputExtension) {
objectName += customOutputExtension;
@@ -4311,6 +4322,26 @@ bool cmLocalGenerator::AlwaysUsesCMFPaths() const
return true;
}
std::string cmLocalGenerator::GetShortObjectFileName(
cmSourceFile const& source) const
{
std::string objectName = this->GetRelativeSourceFileName(source);
std::string objectFileName =
cmSystemTools::GetFilenameName(source.GetFullPath());
cmCryptoHash objNameHasher(cmCryptoHash::AlgoSHA3_512);
std::string terseObjectName =
objNameHasher.HashString(objectName).substr(0, 8);
return terseObjectName;
}
std::string cmLocalGenerator::ComputeShortTargetDirectory(
cmGeneratorTarget const* target) const
{
auto const& tgtName = target->GetName();
return this->GetGlobalGenerator()->ComputeTargetShortName(
this->GetCurrentBinaryDirectory(), tgtName);
}
std::string cmLocalGenerator::GetSourceFileLanguage(cmSourceFile const& source)
{
return source.GetLanguage();

View File

@@ -441,6 +441,9 @@ public:
bool UseShortObjectNames() const;
virtual std::string GetObjectOutputRoot() const;
virtual bool AlwaysUsesCMFPaths() const;
virtual std::string GetShortObjectFileName(cmSourceFile const& source) const;
virtual std::string ComputeShortTargetDirectory(
cmGeneratorTarget const* gt) const;
/**
* Generate a macOS application bundle Info.plist file.