summaryrefslogtreecommitdiffstats
path: root/Source/cmTimestamp.cxx
diff options
context:
space:
mode:
authorAntons Jeļkins <Antons.Jelkins@bmw.de>2021-07-21 13:52:45 (GMT)
committerAntons Jeļkins <Antons.Jelkins@bmw.de>2021-08-02 14:31:53 (GMT)
commitaafa392c12f6fe04893bc5327af429f5321fbb9d (patch)
treec91285a67da474d5e21ca96d025d2823fa8260ef /Source/cmTimestamp.cxx
parenta915f691adbcac96bd5c3d421ef519900ee79c02 (diff)
downloadCMake-aafa392c12f6fe04893bc5327af429f5321fbb9d.zip
CMake-aafa392c12f6fe04893bc5327af429f5321fbb9d.tar.gz
CMake-aafa392c12f6fe04893bc5327af429f5321fbb9d.tar.bz2
string(TIMESTAMP): Add %V specifier for ISO 8601 week number
In ISO 8601 weeks begin with Monday. The first week of the year is the week which contains the first Thursday of the year.
Diffstat (limited to 'Source/cmTimestamp.cxx')
-rw-r--r--Source/cmTimestamp.cxx23
1 files changed, 23 insertions, 0 deletions
diff --git a/Source/cmTimestamp.cxx b/Source/cmTimestamp.cxx
index 056696d..cfea4cf 100644
--- a/Source/cmTimestamp.cxx
+++ b/Source/cmTimestamp.cxx
@@ -18,6 +18,10 @@
#include <cstring>
#include <sstream>
+#ifdef __MINGW32__
+# include <libloaderapi.h>
+#endif
+
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
@@ -159,6 +163,7 @@ std::string cmTimestamp::AddTimestampComponent(char flag,
case 'M':
case 'S':
case 'U':
+ case 'V':
case 'w':
case 'y':
case 'Y':
@@ -187,6 +192,24 @@ std::string cmTimestamp::AddTimestampComponent(char flag,
}
}
+#ifdef __MINGW32__
+ /* See a bug in MinGW: https://sourceforge.net/p/mingw-w64/bugs/793/. A work
+ * around is to try to use strftime() from ucrtbase.dll. */
+ using T = size_t(WINAPI*)(char*, size_t, const char*, const struct tm*);
+ auto loadStrftime = [] {
+ auto handle =
+ LoadLibraryExA("ucrtbase.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
+ if (handle) {
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wcast-function-type"
+ return reinterpret_cast<T>(GetProcAddress(handle, "strftime"));
+# pragma GCC diagnostic pop
+ }
+ return strftime;
+ };
+ static T strftime = loadStrftime();
+#endif
+
char buffer[16];
size_t size =