# - Get the current date from the system # This file defines the macro TODAY that can be used to # retrive the current date. # # This is the definition of the macro # macro TODAY(result) # # After retriving the current date, it set the variable ${result} # in the format YYYYMMDD. In addition the following variables # are also set: # ${result}_YEAR to YYYY # ${result}_MONTH to MM # ${result}_DAY to DD # # Example: # include(Today) # today(CURRENT_DATE) # message(STATUS "${CURRENT_DATE_YEAR}-${CURRENT_DATE_MONTH}-${CURRENT_DATE_DAY}") # will print YYYY-MM-DD. # macro(TODAY RESULT) if(WIN32) execute_process(COMMAND "cmd" "/C date /T" OUTPUT_VARIABLE ${RESULT}) elseif(UNIX) execute_process(COMMAND "date" "+%d/%m/%Y" OUTPUT_VARIABLE ${RESULT}) else() message(WARNING "Cannot get the current date, continue with date equal to '00000000'") set(${RESULT} 00000000) endif() string(REGEX REPLACE "([0-9][0-9])/([0-9][0-9])/([0-9][0-9][0-9][0-9]).*" "\\3\\2\\1" ${RESULT} ${${RESULT}}) string(REGEX REPLACE "([0-9][0-9][0-9][0-9])[0-9][0-9][0-9][0-9]" "\\1" ${RESULT}_YEAR ${${RESULT}}) string(REGEX REPLACE "[0-9][0-9][0-9][0-9]([0-9][0-9])[0-9][0-9]" "\\1" ${RESULT}_MONTH ${${RESULT}}) string(REGEX REPLACE "[0-9][0-9][0-9][0-9][0-9][0-9]([0-9][0-9])" "\\1" ${RESULT}_DAY ${${RESULT}}) endmacro(TODAY)