I've updated the patch (attached) to include a TIMESTAMP sub-command
for file as well (I hope indentation is also fixed).
I only implemented the last modification time since creation and last
access time are not implemented by all filesystems (or disabled for
performance).
Nils
From fdd3bd749b85ecff1d07e6f735417d8bad1e70c4 Mon Sep 17 00:00:00 2001
From: Nils Gladitz glad...@scivis.de
Date: Sat, 29 Sep 2012 11:31:18 +0200
Subject: [PATCH] timestamp sub-command for string and file
---
Source/CMakeLists.txt |2 +
Source/cmFileCommand.cxx | 57
Source/cmFileCommand.h | 10 ++
Source/cmStringCommand.cxx | 54
Source/cmStringCommand.h | 30 -
Source/cmTimestamp.cxx | 135
Source/cmTimestamp.h | 42 ++
Tests/CMakeTests/File-TIMESTAMP-BadArg1.cmake |1 +
Tests/CMakeTests/File-TIMESTAMP-NoFile.cmake |2 +
Tests/CMakeTests/File-TIMESTAMP-NotBogus.cmake | 24
Tests/CMakeTests/File-TIMESTAMP-Works.cmake|2 +
Tests/CMakeTests/FileTest.cmake.in | 12 ++
.../String-TIMESTAMP-AllSpecifiers.cmake | 11 ++
Tests/CMakeTests/String-TIMESTAMP-BadArg1.cmake|1 +
Tests/CMakeTests/String-TIMESTAMP-BadArg2.cmake|1 +
Tests/CMakeTests/String-TIMESTAMP-BadArg3.cmake|1 +
.../String-TIMESTAMP-CustomFormatLocal.cmake |2 +
.../String-TIMESTAMP-CustomFormatUTC.cmake |2 +
.../String-TIMESTAMP-DefaulFormatUTC.cmake |2 +
.../String-TIMESTAMP-DefaultFormatLocal.cmake |2 +
.../String-TIMESTAMP-DefaultFormatUTC.cmake|2 +
.../String-TIMESTAMP-IncompleteSpecifier.cmake |2 +
.../String-TIMESTAMP-UnknownSpecifier.cmake|2 +
Tests/CMakeTests/StringTest.cmake.in | 30 +
24 files changed, 428 insertions(+), 1 deletions(-)
create mode 100644 Source/cmTimestamp.cxx
create mode 100644 Source/cmTimestamp.h
create mode 100644 Tests/CMakeTests/File-TIMESTAMP-BadArg1.cmake
create mode 100644 Tests/CMakeTests/File-TIMESTAMP-NoFile.cmake
create mode 100644 Tests/CMakeTests/File-TIMESTAMP-NotBogus.cmake
create mode 100644 Tests/CMakeTests/File-TIMESTAMP-Works.cmake
create mode 100644 Tests/CMakeTests/String-TIMESTAMP-AllSpecifiers.cmake
create mode 100644 Tests/CMakeTests/String-TIMESTAMP-BadArg1.cmake
create mode 100644 Tests/CMakeTests/String-TIMESTAMP-BadArg2.cmake
create mode 100644 Tests/CMakeTests/String-TIMESTAMP-BadArg3.cmake
create mode 100644 Tests/CMakeTests/String-TIMESTAMP-CustomFormatLocal.cmake
create mode 100644 Tests/CMakeTests/String-TIMESTAMP-CustomFormatUTC.cmake
create mode 100644 Tests/CMakeTests/String-TIMESTAMP-DefaulFormatUTC.cmake
create mode 100644 Tests/CMakeTests/String-TIMESTAMP-DefaultFormatLocal.cmake
create mode 100644 Tests/CMakeTests/String-TIMESTAMP-DefaultFormatUTC.cmake
create mode 100644 Tests/CMakeTests/String-TIMESTAMP-IncompleteSpecifier.cmake
create mode 100644 Tests/CMakeTests/String-TIMESTAMP-UnknownSpecifier.cmake
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index 5a3e7d1..00a1a0a 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -259,6 +259,8 @@ set(SRCS
cmSystemTools.h
cmTarget.cxx
cmTarget.h
+ cmTimestamp.h
+ cmTimestamp.cxx
cmTest.cxx
cmTest.h
cmTestGenerator.cxx
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 8de24b3..3b074da 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
@@ -160,6 +162,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());
@@ -3246,3 +3252,54 @@ cmFileCommand::HandleUploadCommand(std::vectorstd::string const args)
return false;
#endif
}
+
+//
+bool cmFileCommand::HandleTimestampCommand(
+ std::vectorstd::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++];
+}
+
+