From f074d9f571d6dfab29c5fb097d7fa6a2236ff4af Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 7 Jan 2009 14:16:35 -0500 Subject: ENH: Add undocumented file(DIFFERENT) command This new command will be used by generated installation scripts to determine whether an already-installed export file has changed. --- Source/cmFileCommand.cxx | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ Source/cmFileCommand.h | 1 + 2 files changed, 66 insertions(+) diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index a101435..78fc088 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -112,6 +112,10 @@ bool cmFileCommand { return this->HandleInstallCommand(args); } + else if ( subCommand == "DIFFERENT" ) + { + return this->HandleDifferentCommand(args); + } else if ( subCommand == "RPATH_CHANGE" || subCommand == "CHRPATH" ) { return this->HandleRPathChangeCommand(args); @@ -831,6 +835,67 @@ bool cmFileCommand::HandleMakeDirectoryCommand( } //---------------------------------------------------------------------------- +bool +cmFileCommand::HandleDifferentCommand(std::vector const& args) +{ + /* + FILE(DIFFERENT FILES ) + */ + + // Evaluate arguments. + const char* file_lhs = 0; + const char* file_rhs = 0; + const char* var = 0; + enum Doing { DoingNone, DoingVar, DoingFileLHS, DoingFileRHS }; + Doing doing = DoingVar; + for(unsigned int i=1; i < args.size(); ++i) + { + if(args[i] == "FILES") + { + doing = DoingFileLHS; + } + else if(doing == DoingVar) + { + var = args[i].c_str(); + doing = DoingNone; + } + else if(doing == DoingFileLHS) + { + file_lhs = args[i].c_str(); + doing = DoingFileRHS; + } + else if(doing == DoingFileRHS) + { + file_rhs = args[i].c_str(); + doing = DoingNone; + } + else + { + cmOStringStream e; + e << "DIFFERENT given unknown argument " << args[i]; + this->SetError(e.str().c_str()); + return false; + } + } + if(!var) + { + this->SetError("DIFFERENT not given result variable name."); + return false; + } + if(!file_lhs || !file_rhs) + { + this->SetError("DIFFERENT not given FILES option with two file names."); + return false; + } + + // Compare the files. + const char* result = + cmSystemTools::FilesDiffer(file_lhs, file_rhs)? "1" : "0"; + this->Makefile->AddDefinition(var, result); + return true; +} + +//---------------------------------------------------------------------------- // File installation helper class. struct cmFileInstaller { diff --git a/Source/cmFileCommand.h b/Source/cmFileCommand.h index 35718a7..656ad96 100644 --- a/Source/cmFileCommand.h +++ b/Source/cmFileCommand.h @@ -172,6 +172,7 @@ protected: bool HandleRPathChangeCommand(std::vector const& args); bool HandleRPathCheckCommand(std::vector const& args); bool HandleRPathRemoveCommand(std::vector const& args); + bool HandleDifferentCommand(std::vector const& args); // file(INSTALL ...) related functions bool HandleInstallCommand(std::vector const& args); -- cgit v0.12