KWSys 2025-03-01 (1d82baee)

Code extracted from:

    https://gitlab.kitware.com/utils/kwsys.git

at commit 1d82baee88db598a77d9b1a07f7a5fb9b1860f83 (master).

Upstream Shortlog
-----------------

leha-bot (1):
      1079929c Status: Fix encoding of error strings on Windows
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 106ea83..d6d43f5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -173,6 +173,9 @@
   set(KWSYS_USE_System 1)
   set(KWSYS_USE_Encoding 1)
 endif()
+if(KWSYS_USE_Status)
+  set(KWSYS_USE_Encoding 1)
+endif()
 if(KWSYS_USE_SystemInformation)
   set(KWSYS_USE_Process 1)
 endif()
diff --git a/Status.cxx b/Status.cxx
index edda7a0..17cb0eb 100644
--- a/Status.cxx
+++ b/Status.cxx
@@ -2,10 +2,12 @@
    file Copyright.txt or https://cmake.org/licensing#kwsys for details.  */
 #include "kwsysPrivate.h"
 #include KWSYS_HEADER(Status.hxx)
+#include KWSYS_HEADER(Encoding.hxx)
 
 // Work-around CMake dependency scanning limitation.  This must
 // duplicate the above list of headers.
 #if 0
+#  include "Encoding.hxx.in"
 #  include "Status.hxx.in"
 #endif
 
@@ -43,13 +45,13 @@
       break;
 #ifdef _WIN32
     case Kind::Windows: {
-      LPSTR message = NULL;
-      DWORD size = FormatMessageA(
+      LPWSTR message = NULL;
+      DWORD size = FormatMessageW(
         FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
           FORMAT_MESSAGE_IGNORE_INSERTS,
         NULL, this->Windows_, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-        (LPSTR)&message, 0, NULL);
-      err = std::string(message, size);
+        (LPWSTR)&message, 0, NULL);
+      err = kwsys::Encoding::ToNarrow(message);
       LocalFree(message);
     } break;
 #endif