[CMake] [CMAKE] Getting compilation date through CMake

Matthew Woehlke matthew.woehlke at kitware.com
Thu Dec 5 16:34:49 EST 2013


On 2013-12-05 15:46, Fraser Hutchison wrote:
> If you can specify CMake version 2.8.11 as a minimum, you could use
> the string(TIMESTAMP ...) command instead:
>
> string(TIMESTAMP _output "%d/%m/%Y")
>
> Bear in mind that these only execute when CMake runs (i.e. at configure time)
> rather than at build time, so strictly-speaking you're not actually grabbing the
> compile date.

Of course you could put that in a CMake script and execute it with e.g. 
'${CMAKE_COMMAND} -p ${CMAKE_CURRENT_SOURCE_DIR}/get_date.cmake' in a 
custom command :-). Then it would truly be the compile date. (Needless 
to say, the script would need to write the date into some generated 
source file, e.g. with configure_file.)

-- 
Matthew



More information about the CMake mailing list