[CMake] How best to capture the current Date/Time
Bill Hoffman
bill.hoffman at kitware.com
Fri Mar 20 10:12:55 EDT 2009
Michael Jackson wrote:
>
> On Mar 20, 2009, at 5:30 AM, Eric Noulard wrote:
>
>> 2009/3/20 Philip Lowman <philip at yhbt.com>:
>>> 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?
>>
>> I use 'date' on unix and nothing but a "nodate" string 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.
>>
>> may be the same idea, use TRY_RUN with your home made portable source
>> to get your string at CMake time.
>>
>> another solution would be to try to find some script language installed
>> (perl, python, ...) then EXECUTE_PROCESS with appropriate pieces of code
>> for getting the date you want.
>>
>> I think it would be worth a feature request for cmake -E date <format>
>> the "how to get date" is popping again and again.
>>
>> --
>> Erk
>
>
> That was the ticket. The try_run is working as best as I would expect it
> to. I plan to wrap that code in a CMake variable so that I can trigger
> the try_run when I need to increment the version string.
>
> After all of this I'll probably put in a feature request for this
> functionality to be a part of CMake. Actually, if we could just get the
> following variables set by CMake it would be great:
>
> CMAKE_CURRENT_YEAR
> CMAKE_CURRENT_MONTH
> CMAKE_CURRENT_DAY
> CMAKE_CURRENT_HOUR
> CMAKE_CURRENT_MINUTE
> CMAKE_CURRENT_SECOND
>
I don't think you could do this as a set of variables. It would be
better as some sort of command. file(GETDATE result) or something.
-Bill
More information about the CMake
mailing list