summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntons Jeļkins <Antons.Jelkins@bmw.de>2021-11-16 18:34:48 +0100
committerBrad King <brad.king@kitware.com>2021-11-18 09:17:38 -0500
commit26c9fbab4618d53f49f92ff3a000951a1d9b9fde (patch)
tree4105ae4556efc6b57de918413a6b77dfdca86b02
parentf0eae9292baa9932e6c5eb8d95b7552c291cfeb4 (diff)
downloadcmake-26c9fbab4618d53f49f92ff3a000951a1d9b9fde.tar.gz
MINGW-w64: Fix string(TIMESTAMP) build on 32bits.
Rephrase the string(TIMESTAMP) implementation not to cause gcc-11 ICE on MSYS2/mingw32. Fixes: #22916
-rw-r--r--Source/cmTimestamp.cxx12
1 files changed, 9 insertions, 3 deletions
diff --git a/Source/cmTimestamp.cxx b/Source/cmTimestamp.cxx
index 9125d7eea1..c8f5a4b222 100644
--- a/Source/cmTimestamp.cxx
+++ b/Source/cmTimestamp.cxx
@@ -198,7 +198,7 @@ std::string cmTimestamp::AddTimestampComponent(char flag,
/* 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 loadUcrtStrftime = []() -> T {
auto handle =
LoadLibraryExA("ucrtbase.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (handle) {
@@ -207,9 +207,15 @@ std::string cmTimestamp::AddTimestampComponent(char flag,
return reinterpret_cast<T>(GetProcAddress(handle, "strftime"));
# pragma GCC diagnostic pop
}
- return strftime;
+ return nullptr;
};
- static T strftime = loadStrftime();
+ static T ucrtStrftime = loadUcrtStrftime();
+
+ if (ucrtStrftime) {
+ size_t size =
+ ucrtStrftime(buffer, sizeof(buffer), formatString.c_str(), &timeStruct);
+ return std::string(buffer, size);
+ }
#endif
size_t size =