summaryrefslogtreecommitdiffstats
path: root/Source/cmTimestamp.cxx
diff options
context:
space:
mode:
authorBernhard M. Wiedemann <bwiedemann@suse.de>2017-01-25 06:15:40 (GMT)
committerBrad King <brad.king@kitware.com>2017-01-26 15:21:41 (GMT)
commit243aed525a2fd8e5fe32139fd0f8d0cc0e40cc33 (patch)
tree43bb5febd43b6892d0736aad02bdbc1fa586a61d /Source/cmTimestamp.cxx
parenta007f15344007a6261209a409c6988b0e4c4b7e0 (diff)
downloadCMake-243aed525a2fd8e5fe32139fd0f8d0cc0e40cc33.zip
CMake-243aed525a2fd8e5fe32139fd0f8d0cc0e40cc33.tar.gz
CMake-243aed525a2fd8e5fe32139fd0f8d0cc0e40cc33.tar.bz2
cmTimestamp: Support SOURCE_DATE_EPOCH to override current time
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.
Diffstat (limited to 'Source/cmTimestamp.cxx')
-rw-r--r--Source/cmTimestamp.cxx11
1 files changed, 11 insertions, 0 deletions
diff --git a/Source/cmTimestamp.cxx b/Source/cmTimestamp.cxx
index 4a97114..1e5ac5b 100644
--- a/Source/cmTimestamp.cxx
+++ b/Source/cmTimestamp.cxx
@@ -5,6 +5,7 @@
#include <cmConfigure.h>
#include <cstring>
#include <sstream>
+#include <stdlib.h>
#include "cmSystemTools.h"
@@ -12,6 +13,16 @@ std::string cmTimestamp::CurrentTime(const std::string& formatString,
bool utcFlag)
{
time_t currentTimeT = time(CM_NULLPTR);
+ std::string source_date_epoch;
+ cmSystemTools::GetEnv("SOURCE_DATE_EPOCH", source_date_epoch);
+ if (!source_date_epoch.empty()) {
+ std::istringstream iss(source_date_epoch);
+ iss >> currentTimeT;
+ if (iss.fail() || !iss.eof()) {
+ cmSystemTools::Error("Cannot parse SOURCE_DATE_EPOCH as integer");
+ exit(27);
+ }
+ }
if (currentTimeT == time_t(-1)) {
return std::string();
}