[cmake-developers] [PATCH] Improve encoding handling on Windows

Daniel Pfeifer daniel at pfeifer-mail.de
Fri Jul 1 08:25:02 EDT 2016


Hi Dāvis,

On Fri, Jul 1, 2016 at 4:18 AM, Dāvis Mosāns <davispuh at gmail.com> wrote:
> On Windows getenv uses ANSI codepage so it needs to be encoded to
> internally used encoding (eg. UTF-8). Here we use _wgetenv instead
> and encode that.

Your change to the SystemTools::GetEnv function introduces memory
leaks, since you return a pointer to a new[]-ed array.
It seems impossible to refactor SystemTools::GetEnv to use _wgetenv
and provide interface compatability.
You should probably introduce a function that returns std::string and
uses GetEnvironmentVariableW internally.

> Also typically Windows applications (eg. MSVC compiler) use current
> console's codepage for output to pipes so we need to encode that
> to internally used encoding (KWSYS_ENCODING_DEFAULT_CODEPAGE).
>
> Next, when we're outputing to console need to use wide functions.
>
> This change allows that compilers such as MSVC on Windows can be
> installed in non-ASCII path and will work correctly for all
> console's codepages which supports that path's characters.

Sounds useful. I cannot really comment on this.

Cheers, Daniel


More information about the cmake-developers mailing list