Visual Studio /utf-8 source files
The MSVC compiler needs the /utf-8
flag when UTF-8 strings are in the source file.
If not specified, too many bytes are assigned to each character, leading to incorrect string lengths.
This will lead to failures with string width conversions such as
WideCharToMultiByte.
Windows Intel oneAPI compiler didn’t need the /utf-8
flag when tested.
In CMake, apply the /utf-8
flag like:
add_compile_options($<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/utf-8>)
In Meson, the /utf-8
flag is applied automatically to C++ source files with MSVC compilers.