Skip to content

Commit

Permalink
chore: 支持 VC6 编译 UTF-8 字符串字面量
Browse files Browse the repository at this point in the history
  • Loading branch information
chirsz-ever committed Apr 7, 2024
1 parent dd4c523 commit 5c27c1f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release
编译配置中的 `-DCMAKE_BUILD_TYPE=Release` 是构建类型(Build type),表示生成优化级别较高的
发布版。
如果编译的源文件中使用 UTF-8 字符串字面量, 那么在之后的编译阶段需要临时修改 locale 来让 VC6 能够
处理 UTF-8 字符串。相关处理已经位于 `utils\patch-locale.bat` 脚本中, 使用此脚本执行编译命令即可。
例如编译示例程序:
```bat
.\utils\patch-locale.bat cmake --build build --target demos
```
### Visual Studio
使用 `cmake -G` 命令查看支持的 Visual Studio 版本,选择自己安装的 VS 版本,
Expand Down
30 changes: 30 additions & 0 deletions utils/patch-locale.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@echo off

rem USAGE: patch-locale.bat <command> <args...>

setlocal enableDelayedExpansion

call :localeName patch
%*
call :localeName unpatch
exit /b

rem https://raymai97.github.io/myblog/msvc-support-utf8-string-literal-since-vc6#update-for-vc60-the-key-is-localename

:localeName
set _path_="HKCU\Control Panel\International"
set _name_=LocaleName
if "%~1"=="patch" (
call :localeName get _localeName_
call :localeName set en-US
) else if "%~1"=="unpatch" (
call :localeName set !_localeName_!
) else if "%~1"=="get" (
for /f "tokens=3 skip=2" %%i in ('reg query !_path_! /v !_name_!') do (
set _localeName_=%%i
)
) else if "%~1"=="set" (
reg add !_path_! /v !_name_! /d "%~2" /f >nul || exit/b 1
)
exit /b
:localeNameEnd

0 comments on commit 5c27c1f

Please sign in to comment.