[cmake-developers] patch for cmake that adds a new timestamp command

2012-09-27 Thread Nils Gladitz
I've tried creating a patch (attached; should apply to master) that adds 
a timestamp creation command.
It builds on strftime but only allows a limited number of conversion 
specifiers.
I tried to only allow those which are portable (C89), locale independent 
and of fixed range and length (with the exception of %Y).


Nils

--
Nils Gladitz, B.Sc.
DICOM, Konnektivität und Entwicklung

Scivis wissenschaftliche Bildverarbeitung GmbH
Bertha-von-Suttner-Str. 5
D-37085 Göttingen
GERMANY
Handelsregister Nr. / Trade Register No. B3100 Göttingen
Geschäftsführer / Managing Directors Dr. Gernot Ebel, Dr. Uwe Engeland

Tel: 0049 (0)551 634181-28
E-Mail: glad...@scivis.de
Web: www.scivis.de

From d532bb916aedb3383472727d999d16e8302e9fdd Mon Sep 17 00:00:00 2001
From: Nils Gladitz glad...@scivis.de
Date: Thu, 27 Sep 2012 13:10:52 +0200
Subject: [PATCH] new timestamp command

---
 Source/cmBootstrapCommands.cxx  |2 +
 Source/cmTimestampCommand.cxx   |  147 +++
 Source/cmTimestampCommand.h |  107 ++
 Tests/CMakeTests/CMakeLists.txt |1 +
 Tests/CMakeTests/TimestampTest.cmake.in |   60 +
 5 files changed, 317 insertions(+)
 create mode 100644 Source/cmTimestampCommand.cxx
 create mode 100644 Source/cmTimestampCommand.h
 create mode 100644 Tests/CMakeTests/TimestampTest.cmake.in

diff --git a/Source/cmBootstrapCommands.cxx b/Source/cmBootstrapCommands.cxx
index 9097a74..f651d37 100644
--- a/Source/cmBootstrapCommands.cxx
+++ b/Source/cmBootstrapCommands.cxx
@@ -89,6 +89,7 @@
 #include cmStringCommand.cxx
 #include cmSubdirCommand.cxx
 #include cmTargetLinkLibrariesCommand.cxx
+#include cmTimestampCommand.cxx
 #include cmTryCompileCommand.cxx
 #include cmTryRunCommand.cxx
 #include cmUnsetCommand.cxx
@@ -164,6 +165,7 @@ void GetBootstrapCommands(std::listcmCommand* commands)
   commands.push_back(new cmStringCommand);
   commands.push_back(new cmSubdirCommand);
   commands.push_back(new cmTargetLinkLibrariesCommand);
+  commands.push_back(new cmTimestampCommand);
   commands.push_back(new cmTryCompileCommand);
   commands.push_back(new cmTryRunCommand);
   commands.push_back(new cmUnsetCommand);
diff --git a/Source/cmTimestampCommand.cxx b/Source/cmTimestampCommand.cxx
new file mode 100644
index 000..0405026
--- /dev/null
+++ b/Source/cmTimestampCommand.cxx
@@ -0,0 +1,147 @@
+/*
+  CMake - Cross Platform Makefile Generator
+  Copyright 2012 Kitware, Inc., Insight Software Consortium
+
+  Distributed under the OSI-approved BSD License (the License);
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+*/
+#include cmTimestampCommand.h
+
+#include ctime
+#include cstring
+
+//
+namespace
+{
+  std::string AddTimestampComponent(char flag, std::tm timeStruct)
+  {
+std::string formatString = %;
+formatString += flag;
+
+switch(flag)
+{
+case 'd':
+case 'H':
+case 'I':
+case 'j':
+case 'm':
+case 'M':
+case 'S':
+case 'U':
+case 'w':
+case 'y':
+case 'Y':
+  break;
+default:
+  {
+return formatString;
+  }
+}
+
+char buffer[16];
+
+std::size_t size = std::strftime(buffer, sizeof(buffer),
+  formatString.c_str(), timeStruct);
+
+return std::string(buffer, size);
+  }
+}
+
+//
+bool cmTimestampCommand
+::InitialPass(std::vectorstd::string const args, cmExecutionStatus )
+{
+  if(args.size()  1)
+{
+this-SetError(must be called with at least one argument.);
+return false;
+}
+
+  const std::string outputVariable = args[0];
+
+  int index = 1;
+
+  std::string formatString;
+  if(args.size()  index  args[index] != UTC)
+  {
+formatString = args[index++];
+  }
+
+  bool utcFlag = false;
+  if(args.size()  index)
+  {
+if(args[index] == UTC)
+{
+  utcFlag = true;
+}
+else
+{
+  std::string e = does not recognize option  + args[index];
+  this-SetError(e.c_str());
+  return false;
+}
+  }
+
+  if(formatString.empty())
+  {
+  formatString = %Y-%m-%dT%H:%M:%S;
+  if(utcFlag) formatString += Z;
+  }
+
+  std::string timestamp = CreateTimestamp(formatString, utcFlag);
+  this-Makefile-AddDefinition(outputVariable.c_str(), timestamp.c_str());
+
+  return true;
+}
+
+//
+std::string cmTimestampCommand::CreateTimestamp(
+  const std::string formatString, bool utcFlag)
+{
+  std::string result;
+  const char* notFound 

Re: [cmake-developers] patch for cmake that adds a new timestamp command

2012-09-27 Thread Brad King
On 09/27/2012 08:37 AM, David Cole wrote:
 Should we add a new command for this? Or should it be a sub-command of
 string( like RANDOM is?

It should be a string(TIMESTAMP) subcommand.

-Brad
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers


Re: [cmake-developers] patch for cmake that adds a new timestamp command

2012-09-27 Thread Nils Gladitz

I wouldn't mind if this were a string subcommand.

Initially I wanted something like this to tag package filenames.

What gave me another push is this CMake test:
http://open.cdash.org/testDetails.php?test=160586053build=2583145

It seems to fail on my system because it relies on the US locale 
formatting of %DATE% and %TIME% (my test system has a german locale).


There are also these older mailing list posts asking for something similar:
http://www.cmake.org/pipermail/cmake/2009-March/027915.html
http://www.cmake.org/pipermail/cmake/2010-November/041030.html

It would be really cool to have fractions of seconds too but I'm not 
sure how to portably implement those.


Nils


On 09/27/2012 02:37 PM, David Cole wrote:

H. Good idea.

Should we add a new command for this? Or should it be a sub-command of
string( like RANDOM is?

And... while we're at it, I've always thought we should add the
ability to get the creation/modified/access times from a file via the
CMake file command. If we allow getting the current time, we should
leverage some of the same transformation-to-string code in the file
command to get the various times associated with a file.

What do other devs here think:
New command or string sub-command for this functionality?


Thanks,
David


On Thu, Sep 27, 2012 at 7:25 AM, Nils Gladitz glad...@sci-vis.de wrote:

I've tried creating a patch (attached; should apply to master) that adds a
timestamp creation command.
It builds on strftime but only allows a limited number of conversion
specifiers.
I tried to only allow those which are portable (C89), locale independent and
of fixed range and length (with the exception of %Y).

Nils

--
Nils Gladitz, B.Sc.
DICOM, Konnektivität und Entwicklung

Scivis wissenschaftliche Bildverarbeitung GmbH
Bertha-von-Suttner-Str. 5
D-37085 Göttingen
GERMANY
Handelsregister Nr. / Trade Register No. B3100 Göttingen
Geschäftsführer / Managing Directors Dr. Gernot Ebel, Dr. Uwe Engeland

Tel: 0049 (0)551 634181-28
E-Mail: glad...@scivis.de
Web: www.scivis.de


--

Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers



--
Nils Gladitz, B.Sc.
DICOM, Konnektivität und Entwicklung

Scivis wissenschaftliche Bildverarbeitung GmbH
Bertha-von-Suttner-Str. 5
D-37085 Göttingen
GERMANY
Handelsregister Nr. / Trade Register No. B3100 Göttingen
Geschäftsführer / Managing Directors Dr. Gernot Ebel, Dr. Uwe Engeland

Tel: 0049 (0)551 634181-28
E-Mail: glad...@scivis.de
Web: www.scivis.de

--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers


Re: [cmake-developers] patch for cmake that adds a new timestamp command

2012-09-27 Thread Brad King
On 09/27/2012 08:59 AM, Brad King wrote:
 On 09/27/2012 08:37 AM, David Cole wrote:
 Should we add a new command for this? Or should it be a sub-command of
 string( like RANDOM is?
 
 It should be a string(TIMESTAMP) subcommand.

We haven't added any top-level commands since 2008.  At this point
there are so many projects with macros and functions out there we
probably cannot safely add any new names unless they are long or start
with cmake_.  Subcommands are easy though.  I tend to think of the
top-level commands like file and string as namespaces.

-Brad
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers


Re: [cmake-developers] patch for cmake that adds a new timestamp command

2012-09-27 Thread Eric Noulard
2012/9/27 David Cole david.c...@kitware.com:
 H. Good idea.

 Should we add a new command for this? Or should it be a sub-command of
 string( like RANDOM is?

 And... while we're at it, I've always thought we should add the
 ability to get the creation/modified/access times from a file via the
 CMake file command. If we allow getting the current time, we should
 leverage some of the same transformation-to-string code in the file
 command to get the various times associated with a file.

 What do other devs here think:
 New command or string sub-command for this functionality?

string sub-command for me, and agreed with Brad as well
for the namespace thing.

agreed with file(...) extension as well.

that said isn't the TIMESTAMP misleading?
shouldn't it be called DATE instead?



-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers


Re: [cmake-developers] patch for cmake that adds a new timestamp command

2012-09-27 Thread Rolf Eike Beer
Eric Noulard wrote:
 2012/9/27 David Cole david.c...@kitware.com:
  H. Good idea.
  
  Should we add a new command for this? Or should it be a sub-command of
  string( like RANDOM is?
  
  And... while we're at it, I've always thought we should add the
  ability to get the creation/modified/access times from a file via the
  CMake file command. If we allow getting the current time, we should
  leverage some of the same transformation-to-string code in the file
  command to get the various times associated with a file.
  
  What do other devs here think:
  New command or string sub-command for this functionality?
 
 string sub-command for me, and agreed with Brad as well
 for the namespace thing.
 
 agreed with file(...) extension as well.
 
 that said isn't the TIMESTAMP misleading?
 shouldn't it be called DATE instead?

I would second that.

Eike

signature.asc
Description: This is a digitally signed message part.
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Re: [cmake-developers] patch for cmake that adds a new timestamp command

2012-09-27 Thread Rolf Eike Beer
Am Donnerstag, 27. September 2012, 17:10:20 schrieb Nils Gladitz:
 I've tried to reimplement this as a sting sub-command (patch attached).

Looks good, but the indentation looks wrong at some places.

signature.asc
Description: This is a digitally signed message part.
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers