[CMake] How to obtain "date of the day"

Andrew Maclean andrew.amaclean at gmail.com
Thu Aug 5 18:23:03 EDT 2010


Hi All,

I wrote a little c++ program that gets the date and time from the
system. It just returns a UTC time: "yyyy/mm/dd hhm:ss UTC". Works in
Linux, Windows, MAC-OS but does use iostream and ctime.

Then I have this in my CMake file:
#-----------------------------------------------------------------------------
# Determine a build date.
# Get the build date
try_run(TEST_DID_RUN TEST_DID_COMPILE "${CMAKE_BINARY_DIR}"
"${CMAKE_FILE_DIR}/date_time.cpp" OUTPUT_VARIABLE TEST_BUILD_DATE)
if(TEST_DID_COMPILE)
    string(REGEX MATCH "[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]
[0-9][0-9]:[0-9][0-9]:[0-9][0-9] [A-Z][A-Z][A-Z]"
CMAKE_FILE_TRANSFER_BUILD_DATE "${TEST_BUILD_DATE}")
else(TEST_DID_COMPILE)
    set(CMAKE_FILE_TRANSFER_BUILD_DATE "ERROR")
endif(TEST_DID_COMPILE)

Would this be of use?

Regards
   Andrew

On Fri, Aug 6, 2010 at 12:03 AM, David Cole <david.cole at kitware.com> wrote:
> On Thu, Aug 5, 2010 at 9:46 AM, Jean-Christophe Fillion-Robin
> <jchris.fillionr at kitware.com> wrote:
>>
>> hi Folks,
>>
>> Earlier in the day, somebody asked me how he could obtain "today date"
>> using cmake.
>> I replied there was no direct way to obtain the date and I told him to use
>> a macro I wrote.
>> See
>> http://viewvc.slicer.org/viewcvs.cgi/trunk/CMake/Slicer3TodayMacro.cmake?rev=11898&view=log
>>
>> Is there a better a way to retrieve "today date" ?
>
>
> Not yet. But it would be a relatively easy feature to add to CMake if
> somebody wants to sponsor it.
> I envision a new cmake command, or an extension to an existing command (like
> string with a NOW or NOW_UTC arg...) that returns a complete timestamp
> string (something like "2010-08-04 14:00:44.235675 UTC") and/or the
> components of such a string as a cmake list ("2010;8;4;14;0;44;235675;UTC").
> Any sponsors out there? :-)
>
> David
>
>>
>> Thks
>> Jc
>>
>> --
>> Phone: 1-518-836-2174
>> Ext: 304
>>
>> _______________________________________________
>> 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://www.cmake.org/mailman/listinfo/cmake
>
>
> _______________________________________________
> 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://www.cmake.org/mailman/listinfo/cmake
>



-- 
___________________________________________
Andrew J. P. Maclean
Centre for Autonomous Systems
The Rose Street Building J04
The University of Sydney  2006  NSW
AUSTRALIA
Ph: +61 2 9351 3283
Fax: +61 2 9351 7474
URL: http://www.acfr.usyd.edu.au/
___________________________________________


More information about the CMake mailing list