cmNinjaTargetGenerator: use . for the needed phony order-only dependency

It is only required for Ninja < 1.7 though.
This commit is contained in:
Ben Boeckel
2024-01-06 10:12:34 -05:00
parent 1aa28f3b92
commit de3dc16b64
3 changed files with 21 additions and 6 deletions

View File

@@ -828,6 +828,9 @@ void cmGlobalNinjaGenerator::CheckNinjaFeatures()
this->NinjaExpectedEncoding = codecvt_Encoding::ANSI; this->NinjaExpectedEncoding = codecvt_Encoding::ANSI;
} }
#endif #endif
this->NinjaSupportsCWDDepend =
!cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, this->NinjaVersion,
RequiredNinjaVersionForCWDDepend());
} }
void cmGlobalNinjaGenerator::CheckNinjaCodePage() void cmGlobalNinjaGenerator::CheckNinjaCodePage()
@@ -1996,6 +1999,11 @@ bool cmGlobalNinjaGenerator::SupportsMultilineDepfile() const
return this->NinjaSupportsMultilineDepfile; return this->NinjaSupportsMultilineDepfile;
} }
bool cmGlobalNinjaGenerator::SupportsCWDDepend() const
{
return this->NinjaSupportsCWDDepend;
}
bool cmGlobalNinjaGenerator::WriteTargetCleanAdditional(std::ostream& os) bool cmGlobalNinjaGenerator::WriteTargetCleanAdditional(std::ostream& os)
{ {
const auto& lgr = this->LocalGenerators.at(0); const auto& lgr = this->LocalGenerators.at(0);

View File

@@ -415,10 +415,12 @@ public:
return "1.10.2"; return "1.10.2";
} }
static std::string RequiredNinjaVersionForCodePage() { return "1.11"; } static std::string RequiredNinjaVersionForCodePage() { return "1.11"; }
static std::string RequiredNinjaVersionForCWDDepend() { return "1.7"; }
bool SupportsDirectConsole() const override; bool SupportsDirectConsole() const override;
bool SupportsImplicitOuts() const; bool SupportsImplicitOuts() const;
bool SupportsManifestRestat() const; bool SupportsManifestRestat() const;
bool SupportsMultilineDepfile() const; bool SupportsMultilineDepfile() const;
bool SupportsCWDDepend() const;
std::string NinjaOutputPath(std::string const& path) const; std::string NinjaOutputPath(std::string const& path) const;
bool HasOutputPathPrefix() const { return !this->OutputPathPrefix.empty(); } bool HasOutputPathPrefix() const { return !this->OutputPathPrefix.empty(); }
@@ -597,6 +599,7 @@ private:
bool NinjaSupportsMultipleOutputs = false; bool NinjaSupportsMultipleOutputs = false;
bool NinjaSupportsMetadataOnRegeneration = false; bool NinjaSupportsMetadataOnRegeneration = false;
bool NinjaSupportsCodePage = false; bool NinjaSupportsCodePage = false;
bool NinjaSupportsCWDDepend = false;
codecvt_Encoding NinjaExpectedEncoding = codecvt_Encoding::None; codecvt_Encoding NinjaExpectedEncoding = codecvt_Encoding::None;

View File

@@ -1023,7 +1023,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements(
} }
} }
{ if (!this->GetGlobalGenerator()->SupportsCWDDepend()) {
// Ensure that the object directory exists. If there are no objects in the // Ensure that the object directory exists. If there are no objects in the
// target (e.g., an empty `OBJECT` library), the directory is still listed // target (e.g., an empty `OBJECT` library), the directory is still listed
// as an order-only depends in the build files. Alternate `ninja` // as an order-only depends in the build files. Alternate `ninja`
@@ -1106,11 +1106,15 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements(
// that "output ... of phony edge with no inputs doesn't exist" and // that "output ... of phony edge with no inputs doesn't exist" and
// consider the phony output "dirty". // consider the phony output "dirty".
if (orderOnlyDeps.empty()) { if (orderOnlyDeps.empty()) {
// Any path that always exists will work here. It would be nice to std::string tgtDir;
// use just "." but that is not supported by Ninja < 1.7. if (this->GetGlobalGenerator()->SupportsCWDDepend()) {
std::string tgtDir = cmStrCat( tgtDir = ".";
this->LocalGenerator->GetCurrentBinaryDirectory(), '/', } else {
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget)); // Any path that always exists will work here.
tgtDir = cmStrCat(
this->LocalGenerator->GetCurrentBinaryDirectory(), '/',
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget));
}
orderOnlyDeps.push_back(this->ConvertToNinjaPath(tgtDir)); orderOnlyDeps.push_back(this->ConvertToNinjaPath(tgtDir));
} }