Commit 20169f0b authored by Daniel Pfeifer's avatar Daniel Pfeifer Committed by wahikihiki

cmExportLibraryDependenciesCommand: Port away from FinalPass

parent a74dad3b
......@@ -19,57 +19,31 @@
class cmExecutionStatus;
bool cmExportLibraryDependenciesCommand::InitialPass(
std::vector<std::string> const& args, cmExecutionStatus&)
{
if (args.empty()) {
this->SetError("called with incorrect number of arguments");
return false;
}
// store the arguments for the final pass
this->Filename = args[0];
this->Append = false;
if (args.size() > 1) {
if (args[1] == "APPEND") {
this->Append = true;
}
}
return true;
}
void cmExportLibraryDependenciesCommand::FinalPass()
{
// export_library_dependencies() shouldn't modify anything
// ensure this by calling a const method
this->ConstFinalPass();
}
void cmExportLibraryDependenciesCommand::ConstFinalPass() const
static void FinalAction(cmMakefile& makefile, std::string const& filename,
bool append)
{
// Use copy-if-different if not appending.
std::unique_ptr<cmsys::ofstream> foutPtr;
if (this->Append) {
if (append) {
const auto openmodeApp = std::ios::app;
foutPtr =
cm::make_unique<cmsys::ofstream>(this->Filename.c_str(), openmodeApp);
foutPtr = cm::make_unique<cmsys::ofstream>(filename.c_str(), openmodeApp);
} else {
std::unique_ptr<cmGeneratedFileStream> ap(
new cmGeneratedFileStream(this->Filename, true));
new cmGeneratedFileStream(filename, true));
ap->SetCopyIfDifferent(true);
foutPtr = std::move(ap);
}
std::ostream& fout = *foutPtr;
if (!fout) {
cmSystemTools::Error("Error Writing " + this->Filename);
cmSystemTools::Error("Error Writing " + filename);
cmSystemTools::ReportLastSystemError("");
return;
}
// Collect dependency information about all library targets built in
// the project.
cmake* cm = this->Makefile->GetCMakeInstance();
cmake* cm = makefile.GetCMakeInstance();
cmGlobalGenerator* global = cm->GetGlobalGenerator();
const std::vector<cmMakefile*>& locals = global->GetMakefiles();
std::map<std::string, std::string> libDepsOld;
......@@ -166,3 +140,20 @@ void cmExportLibraryDependenciesCommand::ConstFinalPass() const
}
fout << "endif()\n";
}
bool cmExportLibraryDependenciesCommand::InitialPass(
std::vector<std::string> const& args, cmExecutionStatus&)
{
if (args.empty()) {
this->SetError("called with incorrect number of arguments");
return false;
}
std::string const& filename = args[0];
bool const append = args.size() > 1 && args[1] == "APPEND";
this->Makefile->AddFinalAction([filename, append](cmMakefile& makefile) {
FinalAction(makefile, filename, append);
});
return true;
}
......@@ -23,14 +23,6 @@ public:
}
bool InitialPass(std::vector<std::string> const& args,
cmExecutionStatus& status) override;
void FinalPass() override;
bool HasFinalPass() const override { return true; }
private:
std::string Filename;
bool Append = false;
void ConstFinalPass() const;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment