[CMake] How to get the current date

ycollette.nospam at free.fr ycollette.nospam at free.fr
Fri Nov 26 08:36:55 EST 2010


Hello,

The version found in the archive doesn't works under windows XP 64 bits. So here is a little modified one (date seems to be a command from the cmd executable ...):

MACRO (TODAY RESULT)
    IF (WIN32)
        EXECUTE_PROCESS(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE ${RESULT})
        string(REGEX REPLACE "(..)/(..)/..(..).*" "\\1/\\2/\\3" ${RESULT} ${${RESULT}})
    ELSEIF(UNIX)
        EXECUTE_PROCESS(COMMAND "date" "+%d/%m/%Y" OUTPUT_VARIABLE ${RESULT})
        string(REGEX REPLACE "(..)/(..)/..(..).*" "\\1/\\2/\\3" ${RESULT} ${${RESULT}})
    ELSE (WIN32)
        MESSAGE(SEND_ERROR "date not implemented")
        SET(${RESULT} 000000)
    ENDIF (WIN32)
ENDMACRO (TODAY)

...

TODAY(RESULT)
message(STATUS "Compilation date = ${RESULT}")

YC

----- Mail Original -----
De: "ycollette nospam" <ycollette.nospam at free.fr>
À: "cmake" <cmake at cmake.org>
Envoyé: Vendredi 26 Novembre 2010 14h09:48 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne
Objet: Re: [CMake] How to get the current date

Thanks for the link:

http://www.cmake.org/pipermail/cmake/2009-February/027014.html

seems to answer my question.

YC

----- Mail Original -----
De: "Eric Noulard" <eric.noulard at gmail.com>
À: "ycollette nospam" <ycollette.nospam at free.fr>
Cc: "cmake" <cmake at cmake.org>
Envoyé: Vendredi 26 Novembre 2010 13h35:30 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne
Objet: Re: [CMake] How to get the current date

2010/11/26  <ycollette.nospam at free.fr>:
> Hello,
>
> Is it possible in a CMakeLists.txt file to get the current date (under linux and windows) ?
> I would like to store this date in a cmake variable so as to write it in a .h file.

CMake has no builtin for that but if you search the ML archive
http://www.cmake.org/Wiki/CMake_FAQ#Where_can_I_find_searchable_CMake_Mailing_Archives.3F
you'll find several discussions (and solution proposal) on this subject.
-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.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://www.cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list