diff options
Diffstat (limited to 'Source/cmTimestamp.cxx')
-rw-r--r-- | Source/cmTimestamp.cxx | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/Source/cmTimestamp.cxx b/Source/cmTimestamp.cxx index 6a8c9c60a6..3d42e262e2 100644 --- a/Source/cmTimestamp.cxx +++ b/Source/cmTimestamp.cxx @@ -2,18 +2,27 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmTimestamp.h" -#include <cstdlib> +#include <cmConfigure.h> #include <cstring> #include <sstream> +#include <stdlib.h> -#include <sys/types.h> -// include sys/stat.h after sys/types.h -#include <sys/stat.h> +#include "cmSystemTools.h" 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(); } @@ -84,7 +93,7 @@ time_t cmTimestamp::CreateUtcTimeTFromTm(struct tm& tm) const #else // From Linux timegm() manpage. - std::string tz_old = ""; + std::string tz_old; cmSystemTools::GetEnv("TZ", tz_old); tz_old = "TZ=" + tz_old; @@ -127,6 +136,7 @@ std::string cmTimestamp::AddTimestampComponent(char flag, case 'w': case 'y': case 'Y': + case '%': break; case 's': // Seconds since UNIX epoch (midnight 1-jan-1970) { |