Use CMake string(TIMESTAMP) for portable compile timestamp

The previous usage of the date command is not portable across different platforms. date is not guaranteed to be available and the format varies.

Replace it with CMake's built-in string(TIMESTAMP) command which generates a string with the given timestamp format independent of the platform. This commit changes it to use "%y%m%d" format for a YYMMDD timestamp commonly used for compilation.
This commit is contained in:
xixiha5230 2024-02-24 17:57:12 +08:00 committed by GitHub
parent 2a2686fa11
commit d7328953ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -28,11 +28,7 @@ string (REGEX REPLACE "[\n\t\r]" "" CURRENT_BRANCH ${CURRENT_BRANCH})
message(STATUS "git current branch = ${CURRENT_BRANCH}") message(STATUS "git current branch = ${CURRENT_BRANCH}")
# #
execute_process( string(TIMESTAMP COMPILE_TIME "%y%m%d")
COMMAND date +"%y%m%d"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE COMPILE_TIME
)
string (REGEX REPLACE "[\n\t\r]" "" COMPILE_TIME ${COMPILE_TIME}) string (REGEX REPLACE "[\n\t\r]" "" COMPILE_TIME ${COMPILE_TIME})
string(REGEX REPLACE "\"" "" COMPILE_TIME ${COMPILE_TIME}) string(REGEX REPLACE "\"" "" COMPILE_TIME ${COMPILE_TIME})