export(): Set a Makefile on the cmExportBuildFileGenerator.

This is better than the cmCommand, because the lifetime of that is
not as useful, and it is only used to report an error anyway.

In the next commit, the cmExportBuildFileGenerator will outlive the
cmCommand.
This commit is contained in:
Stephen Kelly 2012-10-06 17:16:11 +02:00
parent e383555838
commit 5fe5c32480
3 changed files with 19 additions and 17 deletions

View File

@ -11,12 +11,11 @@
============================================================================*/ ============================================================================*/
#include "cmExportBuildFileGenerator.h" #include "cmExportBuildFileGenerator.h"
#include "cmExportCommand.h"
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmExportBuildFileGenerator::cmExportBuildFileGenerator() cmExportBuildFileGenerator::cmExportBuildFileGenerator()
{ {
this->ExportCommand = 0; this->Makefile = 0;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -39,12 +38,10 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
} }
else else
{ {
if(this->ExportCommand && this->ExportCommand->ErrorMessage.empty()) cmOStringStream e;
{ e << "given target \"" << te->GetName() << "\" more than once.";
cmOStringStream e; this->Makefile->GetCMakeInstance()
e << "given target \"" << te->GetName() << "\" more than once."; ->IssueMessage(cmake::FATAL_ERROR, e.str().c_str(), this->Backtrace);
this->ExportCommand->ErrorMessage = e.str();
}
return false; return false;
} }
if (te->GetType() == cmTarget::INTERFACE_LIBRARY) if (te->GetType() == cmTarget::INTERFACE_LIBRARY)
@ -220,18 +217,20 @@ cmExportBuildFileGenerator
::ComplainAboutMissingTarget(cmTarget* depender, ::ComplainAboutMissingTarget(cmTarget* depender,
cmTarget* dependee) cmTarget* dependee)
{ {
if(!this->ExportCommand || !this->ExportCommand->ErrorMessage.empty()) if(cmSystemTools::GetErrorOccuredFlag())
{ {
return; return;
} }
cmOStringStream e; cmOStringStream e;
e << "called with target \"" << depender->GetName() e << "export called with target \"" << depender->GetName()
<< "\" which requires target \"" << dependee->GetName() << "\" which requires target \"" << dependee->GetName()
<< "\" that is not in the export list.\n" << "\" that is not in the export list.\n"
<< "If the required target is not easy to reference in this call, " << "If the required target is not easy to reference in this call, "
<< "consider using the APPEND option with multiple separate calls."; << "consider using the APPEND option with multiple separate calls.";
this->ExportCommand->ErrorMessage = e.str();
this->Makefile->GetCMakeInstance()
->IssueMessage(cmake::FATAL_ERROR, e.str().c_str(), this->Backtrace);
} }
std::string std::string

View File

@ -13,8 +13,7 @@
#define cmExportBuildFileGenerator_h #define cmExportBuildFileGenerator_h
#include "cmExportFileGenerator.h" #include "cmExportFileGenerator.h"
#include "cmListFileCache.h"
class cmExportCommand;
/** \class cmExportBuildFileGenerator /** \class cmExportBuildFileGenerator
* \brief Generate a file exporting targets from a build tree. * \brief Generate a file exporting targets from a build tree.
@ -37,8 +36,11 @@ public:
/** Set whether to append generated code to the output file. */ /** Set whether to append generated code to the output file. */
void SetAppendMode(bool append) { this->AppendMode = append; } void SetAppendMode(bool append) { this->AppendMode = append; }
/** Set the command instance through which errors should be reported. */ void SetMakefile(cmMakefile *mf) {
void SetCommand(cmExportCommand* cmd) { this->ExportCommand = cmd; } this->Makefile = mf;
this->Makefile->GetBacktrace(this->Backtrace);
}
protected: protected:
// Implement virtual methods from the superclass. // Implement virtual methods from the superclass.
virtual bool GenerateMainFile(std::ostream& os); virtual bool GenerateMainFile(std::ostream& os);
@ -64,7 +66,8 @@ protected:
std::string InstallNameDir(cmTarget* target, const std::string& config); std::string InstallNameDir(cmTarget* target, const std::string& config);
std::vector<cmTarget*> const* Exports; std::vector<cmTarget*> const* Exports;
cmExportCommand* ExportCommand; cmMakefile* Makefile;
cmListFileBacktrace Backtrace;
}; };
#endif #endif

View File

@ -169,7 +169,7 @@ bool cmExportCommand
ebfg.SetNamespace(this->Namespace.GetCString()); ebfg.SetNamespace(this->Namespace.GetCString());
ebfg.SetAppendMode(this->Append.IsEnabled()); ebfg.SetAppendMode(this->Append.IsEnabled());
ebfg.SetExports(&targets); ebfg.SetExports(&targets);
ebfg.SetCommand(this); ebfg.SetMakefile(this->Makefile);
ebfg.SetExportOld(this->ExportOld.IsEnabled()); ebfg.SetExportOld(this->ExportOld.IsEnabled());
cmGlobalGenerator *gg = this->Makefile->GetLocalGenerator() cmGlobalGenerator *gg = this->Makefile->GetLocalGenerator()