ENH: Restored APPEND option to EXPORT() command in new implementation.

This commit is contained in:
Brad King
2008-01-28 13:21:42 -05:00
parent 611bff2c1b
commit 6388ebceb1
6 changed files with 41 additions and 5 deletions

View File

@@ -21,6 +21,14 @@
#include "cmSystemTools.h"
#include "cmTarget.h"
#include <cmsys/auto_ptr.hxx>
//----------------------------------------------------------------------------
cmExportFileGenerator::cmExportFileGenerator()
{
this->AppendMode = false;
}
//----------------------------------------------------------------------------
void cmExportFileGenerator::AddConfiguration(const char* config)
{
@@ -43,8 +51,23 @@ void cmExportFileGenerator::SetExportFile(const char* mainFile)
bool cmExportFileGenerator::GenerateImportFile()
{
// Open the output file to generate it.
cmGeneratedFileStream exportFileStream(this->MainImportFile.c_str(), true);
if(!exportFileStream)
cmsys::auto_ptr<std::ofstream> foutPtr;
if(this->AppendMode)
{
// Open for append.
cmsys::auto_ptr<std::ofstream>
ap(new std::ofstream(this->MainImportFile.c_str(), std::ios::app));
foutPtr = ap;
}
else
{
// Generate atomically and with copy-if-different.
cmsys::auto_ptr<cmGeneratedFileStream>
ap(new cmGeneratedFileStream(this->MainImportFile.c_str(), true));
ap->SetCopyIfDifferent(true);
foutPtr = ap;
}
if(!foutPtr.get() || !*foutPtr)
{
std::string se = cmSystemTools::GetLastSystemError();
cmOStringStream e;
@@ -53,7 +76,7 @@ bool cmExportFileGenerator::GenerateImportFile()
cmSystemTools::Error(e.str().c_str());
return false;
}
std::ostream& os = exportFileStream;
std::ostream& os = *foutPtr;
// Start with the import file header.
this->GenerateImportHeaderCode(os);