From 3606a42c525b7f04fec4f6d2b814ac6af30c49c0 Mon Sep 17 00:00:00 2001 From: "Bernhard M. Wiedemann" Date: Sun, 22 Jan 2017 16:54:24 +0000 Subject: [PATCH] make build reproducible by allowing build systems to use a constant date instead of the current one see https://reproducible-builds.org/ for why this is good and https://reproducible-builds.org/specs/source-date-epoch/ for the definition of this variable This call is designed to work with GNU date. If BSD support is a concern, it can be added. --- cmake/today.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/today.cmake b/cmake/today.cmake index 51d0031..8d00852 100644 --- a/cmake/today.cmake +++ b/cmake/today.cmake @@ -7,7 +7,11 @@ MACRO (TODAY RESULT) EXECUTE_PROCESS(COMMAND "cmd" " /C date +%Y-%m-%d" OUTPUT_VARIABLE ${RESULT}) string(REGEX REPLACE "(..)/(..)/..(..).*" "\\1/\\2/\\3" ${RESULT} ${${RESULT}}) ELSEIF(UNIX) - EXECUTE_PROCESS(COMMAND "date" "+%Y-%m-%d" OUTPUT_VARIABLE ${RESULT}) + if (DEFINED ENV{SOURCE_DATE_EPOCH}) + EXECUTE_PROCESS(COMMAND "date" "-u" "-d" "@$ENV{SOURCE_DATE_EPOCH}" "+%Y-%m-%d" OUTPUT_VARIABLE ${RESULT}) + else () + EXECUTE_PROCESS(COMMAND "date" "+%Y-%m-%d" OUTPUT_VARIABLE ${RESULT}) + endif () string(REGEX REPLACE "(..)/(..)/..(..).*" "\\1/\\2/\\3" ${RESULT} ${${RESULT}}) ELSE (WIN32) MESSAGE(SEND_ERROR "date not implemented") -- 2.7.4