[CMake] How best to capture the current Date/Time

Philip Lowman philip at yhbt.com
Fri Mar 20 00:00:24 EDT 2009


On Thu, Mar 19, 2009 at 11:18 PM, Michael Jackson <
mike.jackson at bluequartz.net> wrote:

> I am trying to find a nice portable solution for generating version strings
> based on the date (seems reasonable). I even have my own c++ code that can
> generate the proper string for me. The problem that I can not seem to get my
> head around is that I need to compile and run the program at cmake time
> which probably isn't really going to happen, at least easily.
>  So. what is everyone else doing for this?
>
> My main goal is to automate the generation of cmake code like the
> following:
>
> set ( ${${Project_Name}_VERSION} "2009.03.10")
>
> so that I can later use it for OS X bundle building.
>
> On Unix systems I can easily spawn a "date" command to get what I need but
> what to do on windows?


Ugly, but apparently possible with batch file scripting!
http://www.tech-recipes.com/rx/956/windows-batch-file-bat-to-get-current-date-in-mmddyyyy-format/

Another option is you could write a small program which uses localtime() and
other posix functions to get you the format that you want and then use the
output from the program via a CHECK_C_SOURCE_COMPILES configure test.  You
could unset the cache variable this generates to cause the program to
recompile and run on every configure if you wanted.  Not sure how you could
get it run without recompiling but someone might know of a way.

You could also ask for a CMake command to get the date and/or time.

I've been wanting to add a date to one of our docbook manuals for quite some
time now so let me know what you come up with. Option #2 could be
implemented and shared in CMake/Modules.

-- 
Philip Lowman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090320/7819ef12/attachment-0001.htm>


More information about the CMake mailing list