diff options
author | Brad King <brad.king@kitware.com> | 2024-01-09 15:52:34 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-01-09 15:52:42 (GMT) |
commit | 1c97c57455fd6672cef8a23b57aea502864090eb (patch) | |
tree | b4bbbaf72321130bf070d2e1ebaf73dfbb11d45b | |
parent | 60175f073cb2cd7cb8cf33192bdecdf68e192f3d (diff) | |
parent | de3dc16b64188a18b3607939f336525ce955589e (diff) | |
download | CMake-1c97c57455fd6672cef8a23b57aea502864090eb.zip CMake-1c97c57455fd6672cef8a23b57aea502864090eb.tar.gz CMake-1c97c57455fd6672cef8a23b57aea502864090eb.tar.bz2 |
Merge topic 'ninja-always-make-object-dirs'
de3dc16b64 cmNinjaTargetGenerator: use `.` for the needed phony order-only dependency
1aa28f3b92 cmNinjaTargetGenerator: ensure that the object output directory exists
4a9613ff9b cmNinjaTargetGenerator: add a method to compute the object directory
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9105
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 8 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.h | 3 | ||||
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 51 | ||||
-rw-r--r-- | Source/cmNinjaTargetGenerator.h | 1 |
4 files changed, 43 insertions, 20 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 55eb9b5..74a6bea 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -828,6 +828,9 @@ void cmGlobalNinjaGenerator::CheckNinjaFeatures() this->NinjaExpectedEncoding = codecvt_Encoding::ANSI; } #endif + this->NinjaSupportsCWDDepend = + !cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, this->NinjaVersion, + RequiredNinjaVersionForCWDDepend()); } void cmGlobalNinjaGenerator::CheckNinjaCodePage() @@ -1996,6 +1999,11 @@ bool cmGlobalNinjaGenerator::SupportsMultilineDepfile() const return this->NinjaSupportsMultilineDepfile; } +bool cmGlobalNinjaGenerator::SupportsCWDDepend() const +{ + return this->NinjaSupportsCWDDepend; +} + bool cmGlobalNinjaGenerator::WriteTargetCleanAdditional(std::ostream& os) { const auto& lgr = this->LocalGenerators.at(0); diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 3443643..64eed4d 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -415,10 +415,12 @@ public: return "1.10.2"; } static std::string RequiredNinjaVersionForCodePage() { return "1.11"; } + static std::string RequiredNinjaVersionForCWDDepend() { return "1.7"; } bool SupportsDirectConsole() const override; bool SupportsImplicitOuts() const; bool SupportsManifestRestat() const; bool SupportsMultilineDepfile() const; + bool SupportsCWDDepend() const; std::string NinjaOutputPath(std::string const& path) const; bool HasOutputPathPrefix() const { return !this->OutputPathPrefix.empty(); } @@ -597,6 +599,7 @@ private: bool NinjaSupportsMultipleOutputs = false; bool NinjaSupportsMetadataOnRegeneration = false; bool NinjaSupportsCodePage = false; + bool NinjaSupportsCWDDepend = false; codecvt_Encoding NinjaExpectedEncoding = codecvt_Encoding::None; diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index bc75a95..a0651ee 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -411,28 +411,29 @@ std::string cmNinjaTargetGenerator::GetCompiledSourceNinjaPath( return this->ConvertToNinjaAbsPath(source->GetFullPath()); } -std::string cmNinjaTargetGenerator::GetObjectFilePath( - cmSourceFile const* source, const std::string& config) const +std::string cmNinjaTargetGenerator::GetObjectFileDir( + const std::string& config) const { std::string path = this->LocalGenerator->GetHomeRelativeOutputPath(); if (!path.empty()) { path += '/'; } - std::string const& objectName = this->GeneratorTarget->GetObjectName(source); - path += cmStrCat( - this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget), - this->GetGlobalGenerator()->ConfigDirectory(config), '/', objectName); + path += + cmStrCat(this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget), + this->GetGlobalGenerator()->ConfigDirectory(config)); return path; } -std::string cmNinjaTargetGenerator::GetBmiFilePath( +std::string cmNinjaTargetGenerator::GetObjectFilePath( cmSourceFile const* source, const std::string& config) const { - std::string path = this->LocalGenerator->GetHomeRelativeOutputPath(); - if (!path.empty()) { - path += '/'; - } + std::string const& objectName = this->GeneratorTarget->GetObjectName(source); + return cmStrCat(this->GetObjectFileDir(config), '/', objectName); +} +std::string cmNinjaTargetGenerator::GetBmiFilePath( + cmSourceFile const* source, const std::string& config) const +{ auto& importedConfigInfo = this->Configs.at(config).ImportedCxxModules; if (!importedConfigInfo.Initialized()) { std::string configUpper = cmSystemTools::UpperCase(config); @@ -444,10 +445,7 @@ std::string cmNinjaTargetGenerator::GetBmiFilePath( std::string bmiName = importedConfigInfo.BmiNameForSource(source->GetFullPath()); - path += cmStrCat( - this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget), - this->GetGlobalGenerator()->ConfigDirectory(config), '/', bmiName); - return path; + return cmStrCat(this->GetObjectFileDir(config), '/', bmiName); } std::string cmNinjaTargetGenerator::GetClangTidyReplacementsFilePath( @@ -1025,6 +1023,15 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements( } } + if (!this->GetGlobalGenerator()->SupportsCWDDepend()) { + // 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 + // as an order-only depends in the build files. Alternate `ninja` + // implementations may not allow this (such as `samu`). See #25526. + auto const objectDir = this->GetObjectFileDir(config); + this->EnsureDirectoryExists(objectDir); + } + { cmNinjaBuild build("phony"); build.Comment = @@ -1099,11 +1106,15 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements( // that "output ... of phony edge with no inputs doesn't exist" and // consider the phony output "dirty". if (orderOnlyDeps.empty()) { - // Any path that always exists will work here. It would be nice to - // use just "." but that is not supported by Ninja < 1.7. - std::string tgtDir = cmStrCat( - this->LocalGenerator->GetCurrentBinaryDirectory(), '/', - this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget)); + std::string tgtDir; + if (this->GetGlobalGenerator()->SupportsCWDDepend()) { + tgtDir = "."; + } else { + // Any path that always exists will work here. + tgtDir = cmStrCat( + this->LocalGenerator->GetCurrentBinaryDirectory(), '/', + this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget)); + } orderOnlyDeps.push_back(this->ConvertToNinjaPath(tgtDir)); } diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index f081117..2bfed80 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -128,6 +128,7 @@ protected: /// @return the source file path for the given @a source. std::string GetCompiledSourceNinjaPath(cmSourceFile const* source) const; + std::string GetObjectFileDir(const std::string& config) const; /// @return the object file path for the given @a source. std::string GetObjectFilePath(cmSourceFile const* source, const std::string& config) const; |