diff --git a/Source/cmExportLibraryDependencies.cxx b/Source/cmExportLibraryDependencies.cxx index a83d7e1ea..16537a488 100644 --- a/Source/cmExportLibraryDependencies.cxx +++ b/Source/cmExportLibraryDependencies.cxx @@ -73,7 +73,8 @@ void cmExportLibraryDependenciesCommand::FinalPass() else { std::auto_ptr ap( - new cmGeneratedFileStream(fname.c_str(), true, true)); + new cmGeneratedFileStream(fname.c_str(), true)); + ap->SetCopyIfDifferent(true); foutNew = ap; foutPtr = foutNew.get(); } diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx index 1e470c874..254b6bf69 100644 --- a/Source/cmGeneratedFileStream.cxx +++ b/Source/cmGeneratedFileStream.cxx @@ -27,10 +27,8 @@ #endif //---------------------------------------------------------------------------- -cmGeneratedFileStream::cmGeneratedFileStream(const char* name, - bool copy_if_different, - bool quiet): - cmGeneratedFileStreamBase(name, copy_if_different), +cmGeneratedFileStream::cmGeneratedFileStream(const char* name, bool quiet): + cmGeneratedFileStreamBase(name), Stream(m_TempName.c_str()) { // Check if the file opened. @@ -53,11 +51,16 @@ cmGeneratedFileStream::~cmGeneratedFileStream() } //---------------------------------------------------------------------------- -cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(const char* name, - bool copy_if_different): +void cmGeneratedFileStream::SetCopyIfDifferent(bool copy_if_different) +{ + m_CopyIfDifferent = copy_if_different; +} + +//---------------------------------------------------------------------------- +cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(const char* name): m_Name(name), m_TempName(name), - m_CopyIfDifferent(copy_if_different), + m_CopyIfDifferent(false), m_Okay(false) { // Create the name of the temporary file. diff --git a/Source/cmGeneratedFileStream.h b/Source/cmGeneratedFileStream.h index f4473702b..7430ef932 100644 --- a/Source/cmGeneratedFileStream.h +++ b/Source/cmGeneratedFileStream.h @@ -26,7 +26,7 @@ class cmGeneratedFileStreamBase { protected: // The constructor prepares the temporary output file. - cmGeneratedFileStreamBase(const char* name, bool copy_if_different); + cmGeneratedFileStreamBase(const char* name); // The destructor renames the temporary output file to the real name. ~cmGeneratedFileStreamBase(); @@ -65,13 +65,11 @@ public: /** * The constructor takes the name of the file to be generated. It - * automatically generates a name for the temporary file. The - * second argument specifies whether the copy-if-different check - * should be done. If the file cannot be opened an error message is - * produced unless the third argument is set to true. + * automatically generates a name for the temporary file. If the + * file cannot be opened an error message is produced unless the + * second argument is set to true. */ - cmGeneratedFileStream(const char* name, bool copy_if_different, - bool quiet = false); + cmGeneratedFileStream(const char* name, bool quiet=false); /** * The destructor checks the stream status to be sure the temporary @@ -79,6 +77,11 @@ public: * replaced. */ ~cmGeneratedFileStream(); + + /** + * Set whether copy-if-different is done. + */ + void SetCopyIfDifferent(bool copy_if_different); }; #endif diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 0184833fe..e85a80c08 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -289,7 +289,8 @@ void cmGlobalVisualStudio7Generator::OutputSLNFile(cmLocalGenerator* root, fname += "/"; fname += root->GetMakefile()->GetProjectName(); fname += ".sln"; - cmGeneratedFileStream fout(fname.c_str(), true); + cmGeneratedFileStream fout(fname.c_str()); + fout.SetCopyIfDifferent(true); if(!fout) { return; diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 033ca6df0..92cb2029b 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -92,7 +92,8 @@ void cmLocalGenerator::GenerateInstallRules() toplevel_install = 1; } file += "/cmake_install.cmake"; - cmGeneratedFileStream fout(file.c_str(), true); + cmGeneratedFileStream fout(file.c_str()); + fout.SetCopyIfDifferent(true); fout << "# Install script for directory: " << m_Makefile->GetCurrentDirectory() << std::endl << std::endl; diff --git a/Source/cmLocalKdevelopGenerator.cxx b/Source/cmLocalKdevelopGenerator.cxx index 03c77b19a..c5821d036 100644 --- a/Source/cmLocalKdevelopGenerator.cxx +++ b/Source/cmLocalKdevelopGenerator.cxx @@ -120,7 +120,7 @@ void cmLocalKdevelopGenerator::MergeProjectFiles(const std::string& outputDir, } oldProjectFile.close(); - cmGeneratedFileStream fout(filename.c_str(), false); + cmGeneratedFileStream fout(filename.c_str()); if(!fout) { return; @@ -171,7 +171,7 @@ void cmLocalKdevelopGenerator::CreateNewProjectFile(const std::string& outputDir const std::string& cmakeFilePattern) { - cmGeneratedFileStream fout(filename.c_str(), false); + cmGeneratedFileStream fout(filename.c_str()); if(!fout) { return; @@ -364,7 +364,7 @@ bool cmLocalKdevelopGenerator::CreateFilelistFile(const std::string& outputDir, } //now write the new filename - cmGeneratedFileStream fout(filename.c_str(), false); + cmGeneratedFileStream fout(filename.c_str()); if(!fout) { return false; diff --git a/Source/cmLocalUnixMakefileGenerator.cxx b/Source/cmLocalUnixMakefileGenerator.cxx index 586bf292f..0a8a6ac3f 100644 --- a/Source/cmLocalUnixMakefileGenerator.cxx +++ b/Source/cmLocalUnixMakefileGenerator.cxx @@ -186,7 +186,7 @@ void cmLocalUnixMakefileGenerator::OutputMakefile(const char* file, // Create a stream that writes to a temporary file // then does a copy at the end. This is to allow users // to hit control-c during the make of the makefile - cmGeneratedFileStream fout(file, false); + cmGeneratedFileStream fout(file); if(!fout) { return; diff --git a/Source/cmLocalUnixMakefileGenerator2.cxx b/Source/cmLocalUnixMakefileGenerator2.cxx index d29f54572..6fd05752c 100644 --- a/Source/cmLocalUnixMakefileGenerator2.cxx +++ b/Source/cmLocalUnixMakefileGenerator2.cxx @@ -46,8 +46,6 @@ void cmLocalUnixMakefileGenerator2::SetEmptyCommand(const char* cmd) //---------------------------------------------------------------------------- void cmLocalUnixMakefileGenerator2::Generate(bool fromTheTop) { - // TODO: Account for control-c during Makefile generation. - // TODO: Think about unifying generation of "@" for silent commands. // Generate old style for now. @@ -88,15 +86,14 @@ void cmLocalUnixMakefileGenerator2::Generate(bool fromTheTop) //---------------------------------------------------------------------------- void cmLocalUnixMakefileGenerator2::GenerateMakefile() { - // Open the output file. + // Open the output file. This should not be copy-if-different + // because the check-build-system step compares the makefile time to + // see if the build system must be regenerated. std::string makefileName = m_Makefile->GetStartOutputDirectory(); makefileName += "/Makefile2"; - std::ofstream makefileStream(makefileName.c_str()); + cmGeneratedFileStream makefileStream(makefileName.c_str()); if(!makefileStream) { - cmSystemTools::Error("Error can not open for write: ", - makefileName.c_str()); - cmSystemTools::ReportLastSystemError(""); return; } @@ -134,12 +131,9 @@ void cmLocalUnixMakefileGenerator2::GenerateCMakefile() cmakefileName += ".cmake"; // Open the output file. - std::ofstream cmakefileStream(cmakefileName.c_str()); + cmGeneratedFileStream cmakefileStream(cmakefileName.c_str()); if(!cmakefileStream) { - cmSystemTools::Error("Error can not open for write: ", - cmakefileName.c_str()); - cmSystemTools::ReportLastSystemError(""); return; } @@ -237,7 +231,8 @@ cmLocalUnixMakefileGenerator2 // Open the rule file. This should be copy-if-different because the // rules may depend on this file itself. std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName); - cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str(), true); + cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str()); + ruleFileStream.SetCopyIfDifferent(true); if(!ruleFileStream) { return; @@ -351,7 +346,8 @@ cmLocalUnixMakefileGenerator2 std::string ruleFileName = obj; ruleFileName += ".make"; std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName); - cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str(), true); + cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str()); + ruleFileStream.SetCopyIfDifferent(true); if(!ruleFileStream) { return; @@ -526,7 +522,8 @@ cmLocalUnixMakefileGenerator2 // Open the rule file. This should be copy-if-different because the // rules may depend on this file itself. std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName); - cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str(), true); + cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str()); + ruleFileStream.SetCopyIfDifferent(true); if(!ruleFileStream) { return; @@ -2228,7 +2225,7 @@ cmLocalUnixMakefileGenerator2 std::string depMakeFile = objFile; depMarkFile += ".depends"; depMakeFile += ".depends.make"; - std::ofstream fout(depMakeFile.c_str()); + cmGeneratedFileStream fout(depMakeFile.c_str()); fout << "# Dependencies for " << objFile << std::endl; for(std::set::iterator i=dependencies.begin(); i != dependencies.end(); ++i) @@ -2406,7 +2403,7 @@ cmLocalUnixMakefileGenerator2 cmSystemTools::RemoveFile(depMarkFileFull); // Write an empty dependency file. - std::ofstream depFileStream(depMakeFileFull); + cmGeneratedFileStream depFileStream(depMakeFileFull); depFileStream << "# Empty dependencies file for " << file << ".\n" << "# This may be replaced when dependencies are built.\n"; diff --git a/Source/cmVTKMakeInstantiatorCommand.cxx b/Source/cmVTKMakeInstantiatorCommand.cxx index 6f2239bc2..5d96b8090 100644 --- a/Source/cmVTKMakeInstantiatorCommand.cxx +++ b/Source/cmVTKMakeInstantiatorCommand.cxx @@ -127,7 +127,8 @@ cmVTKMakeInstantiatorCommand std::string fullName = headerPath+"/"+fileName; // Generate the output file with copy-if-different. - cmGeneratedFileStream fout(fullName.c_str(), true); + cmGeneratedFileStream fout(fullName.c_str()); + fout.SetCopyIfDifferent(true); // Actually generate the code in the file. if(!oldVersion) @@ -147,7 +148,8 @@ cmVTKMakeInstantiatorCommand // Generate the output file with copy-if-different. { - cmGeneratedFileStream fout(fullName.c_str(), true); + cmGeneratedFileStream fout(fullName.c_str()); + fout.SetCopyIfDifferent(true); // Actually generate the code in the file. if(!oldVersion) @@ -188,7 +190,8 @@ cmVTKMakeInstantiatorCommand // Generate the output file with copy-if-different. { - cmGeneratedFileStream fout(fullName.c_str(), true); + cmGeneratedFileStream fout(fullName.c_str()); + fout.SetCopyIfDifferent(true); size_t thisBlockSize = (block < numFullBlocks)? groupSize:lastBlockSize;