diff options
author | Nils Gladitz <gladitz@scivis.de> | 2012-10-05 19:55:07 (GMT) |
---|---|---|
committer | David Cole <david.cole@kitware.com> | 2012-12-05 15:39:10 (GMT) |
commit | 711e2b3b5c674d4f754b5b214d511be6ce7e8f4d (patch) | |
tree | eac34a0d730f835f60e4fb28cc0e039c30298d3d /Source/cmFileCommand.cxx | |
parent | 2bb2745fa8c260d12aca33d2e1fd26a92d3bfa6b (diff) | |
download | CMake-711e2b3b5c674d4f754b5b214d511be6ce7e8f4d.zip CMake-711e2b3b5c674d4f754b5b214d511be6ce7e8f4d.tar.gz CMake-711e2b3b5c674d4f754b5b214d511be6ce7e8f4d.tar.bz2 |
CMake: Add TIMESTAMP subcommand to string and file commands
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r-- | Source/cmFileCommand.cxx | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index b877f3c..42df3a1 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -17,6 +17,8 @@ #include "cmFileTimeComparison.h" #include "cmCryptoHash.h" +#include "cmTimestamp.h" + #if defined(CMAKE_BUILD_WITH_CMAKE) #include "cm_curl.h" #endif @@ -161,6 +163,10 @@ bool cmFileCommand { return this->HandleCMakePathCommand(args, true); } + else if ( subCommand == "TIMESTAMP" ) + { + return this->HandleTimestampCommand(args); + } std::string e = "does not recognize sub-command "+subCommand; this->SetError(e.c_str()); @@ -3241,3 +3247,54 @@ cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args) return false; #endif } + +//---------------------------------------------------------------------------- +bool cmFileCommand::HandleTimestampCommand( + std::vector<std::string> const& args) +{ + if(args.size() < 3) + { + this->SetError("sub-command TIMESTAMP requires at least two arguments."); + return false; + } + else if(args.size() > 5) + { + this->SetError("sub-command TIMESTAMP takes at most four arguments."); + return false; + } + + int argsIndex = 1; + + const std::string& filename = args[argsIndex++]; + + const std::string& outputVariable = args[argsIndex++]; + + std::string formatString; + if(args.size() > argsIndex && args[argsIndex] != "UTC") + { + formatString = args[argsIndex++]; + } + + bool utcFlag = false; + if(args.size() > argsIndex) + { + if(args[argsIndex] == "UTC") + { + utcFlag = true; + } + else + { + std::string e = " TIMESTAMP sub-command does not recognize option " + + args[argsIndex] + "."; + this->SetError(e.c_str()); + return false; + } + } + + cmTimestamp timestamp; + std::string result = timestamp.FileModificationTime( + filename.c_str(), formatString, utcFlag); + this->Makefile->AddDefinition(outputVariable.c_str(), result.c_str()); + + return true; +} |