-
-
Save tigerlei010/a70f47bacc7a61b493d9244c6da36e6d to your computer and use it in GitHub Desktop.
2 CMake macros returning the current date (format yyyy-mm-dd) and the current time (hh:mm:ss)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 2.8) | |
# Return the date (yyyy-mm-dd) | |
macro(DATE RESULT) | |
if(WIN32) | |
execute_process(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE ${RESULT}) | |
string(REGEX REPLACE "(..)/(..)/(....).*" "\\3-\\2-\\1" ${RESULT} ${${RESULT}}) | |
elseif(UNIX) | |
execute_process(COMMAND "date" "+%Y-%m-%d" OUTPUT_VARIABLE ${RESULT}) | |
else() | |
message(SEND_ERROR "Unable to detect date") | |
set(${RESULT} UNKNOWN) | |
endif() | |
endmacro() | |
# Return the time (hh:mm:ss) | |
macro(TIME RESULT) | |
if(WIN32) | |
execute_process(COMMAND "cmd" " /C echo %TIME%" OUTPUT_VARIABLE ${RESULT}) | |
string(REGEX REPLACE "(..:..:..),(..)" "\\1" ${RESULT} ${${RESULT}}) | |
elseif(UNIX) | |
execute_process(COMMAND "date" "+%H:%M:%S" OUTPUT_VARIABLE ${RESULT}) | |
else() | |
message(SEND_ERROR "Unable to detect time") | |
set(${RESULT} UNKNOWN) | |
endif() | |
endmacro() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment