mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-30 19:19:32 -05:00
Merge topic 'fix-mingw32-gcc11-ice' into release-3.22
26c9fbab46MINGW-w64: Fix string(TIMESTAMP) build on 32bits.f0eae9292bcmTimestamp: Declare component buffer before MinGW-specific code Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6737
This commit is contained in:
+11
-5
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user