summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-11-18 15:38:01 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-11-18 15:38:23 (GMT)
commit6f613502f884661db7d7e2119f35e771a364f587 (patch)
tree2070987971587016d4edcca60cb3aa2f1815e3d7
parentdfb51bce7a1e77d778fadb253fda8e2845d3040e (diff)
parent26c9fbab4618d53f49f92ff3a000951a1d9b9fde (diff)
downloadCMake-6f613502f884661db7d7e2119f35e771a364f587.zip
CMake-6f613502f884661db7d7e2119f35e771a364f587.tar.gz
CMake-6f613502f884661db7d7e2119f35e771a364f587.tar.bz2
Merge topic 'fix-mingw32-gcc11-ice'
26c9fbab46 MINGW-w64: Fix string(TIMESTAMP) build on 32bits. f0eae9292b cmTimestamp: Declare component buffer before MinGW-specific code Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6737
-rw-r--r--Source/cmTimestamp.cxx16
1 files changed, 11 insertions, 5 deletions
diff --git a/Source/cmTimestamp.cxx b/Source/cmTimestamp.cxx
index cfea4cf..c8f5a4b 100644
--- a/Source/cmTimestamp.cxx
+++ b/Source/cmTimestamp.cxx
@@ -192,11 +192,13 @@ std::string cmTimestamp::AddTimestampComponent(char flag,
}
}
+ char buffer[16];
+
#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 loadUcrtStrftime = []() -> T {
auto handle =
LoadLibraryExA("ucrtbase.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (handle) {
@@ -205,12 +207,16 @@ 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();
-#endif
+ static T ucrtStrftime = loadUcrtStrftime();
- char buffer[16];
+ if (ucrtStrftime) {
+ size_t size =
+ ucrtStrftime(buffer, sizeof(buffer), formatString.c_str(), &timeStruct);
+ return std::string(buffer, size);
+ }
+#endif
size_t size =
strftime(buffer, sizeof(buffer), formatString.c_str(), &timeStruct);