diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 1f7aaafbd1..016705e1cf 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -1023,6 +1023,15 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements( } } + { + // 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 =