build(cmake): add /utf-8 MSVC compile option to fix builds on Chinese Windows #43

Closed
opened 2026-11-26 19:11:24 +00:00 by github-bot · 1 comment
Owner

@⁠californiaAlmonds on GitHub · 2026-11-23 13:30 UTC · original

Summary

Add add_compile_options(/utf-8) under if(MSVC) in CMakeLists.txt so builds succeed reliably on non-UTF-8 Windows system locales — specifically Chinese versions of Windows (e.g., CP936 / GBK).

Why

Without /utf-8, MSVC interprets source files using the active Windows ANSI code page instead of UTF-8. On Chinese Windows (and other CJK / non-UTF-8 locales), UTF-8 source files containing non-ASCII characters (such as —, →, ×, or UTF-8 string literals/comments) trigger C4819 warnings and can cause syntax/encoding compilation errors when multi-byte sequences consume adjacent quotes or newlines.

Proposed Change

In CMakeLists.txt inside the top-level if(MSVC) block (around lines 40–45):

if(MSVC)
    # Force UTF-8 source & execution character sets so builds succeed on non-UTF-8
    # Windows locales (e.g., Chinese Windows CP936/GBK) without C4819 or parse errors.
    add_compile_options(/utf-8)

    # Restore runtime std::mutex initialization so binaries built with VS 2022 17.10+
    # remain ABI-compatible with all msvcp140.dll versions (< 14.40) and never crash
    # with 0xC0000005 inside _Mtx_lock when an older VC++ runtime is loaded.
    add_compile_definitions(_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR)
endif()

(Note: clang-cl also defines MSVC in CMake and supports /utf-8, while MinGW/GCC already defaults to UTF-8.)

Acceptance Criteria

  • add_compile_options(/utf-8) added under if(MSVC) in CMakeLists.txt
  • Clean build (0 warnings) and full CTest pass on MSVC and Clang-CL CI jobs
  • No C4819 or encoding-related parse errors on Chinese Windows (CP936 / GBK locale)
**@⁠californiaAlmonds** on GitHub · 2026-11-23 13:30 UTC · [original](https://github.com/californiaAlmonds/OpenScarlett/issues/43) ## Summary Add `add_compile_options(/utf-8)` under `if(MSVC)` in `CMakeLists.txt` so builds succeed reliably on non-UTF-8 Windows system locales — specifically Chinese versions of Windows (e.g., CP936 / GBK). ## Why Without `/utf-8`, MSVC interprets source files using the active Windows ANSI code page instead of UTF-8. On Chinese Windows (and other CJK / non-UTF-8 locales), UTF-8 source files containing non-ASCII characters (such as `—`, `→`, `×`, or UTF-8 string literals/comments) trigger `C4819` warnings and can cause syntax/encoding compilation errors when multi-byte sequences consume adjacent quotes or newlines. ## Proposed Change In `CMakeLists.txt` inside the top-level `if(MSVC)` block (around lines 40–45): ```cmake if(MSVC) # Force UTF-8 source & execution character sets so builds succeed on non-UTF-8 # Windows locales (e.g., Chinese Windows CP936/GBK) without C4819 or parse errors. add_compile_options(/utf-8) # Restore runtime std::mutex initialization so binaries built with VS 2022 17.10+ # remain ABI-compatible with all msvcp140.dll versions (< 14.40) and never crash # with 0xC0000005 inside _Mtx_lock when an older VC++ runtime is loaded. add_compile_definitions(_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR) endif() ``` *(Note: `clang-cl` also defines `MSVC` in CMake and supports `/utf-8`, while MinGW/GCC already defaults to UTF-8.)* ## Acceptance Criteria - [ ] `add_compile_options(/utf-8)` added under `if(MSVC)` in `CMakeLists.txt` - [ ] Clean build (`0` warnings) and full CTest pass on MSVC and Clang-CL CI jobs - [ ] No `C4819` or encoding-related parse errors on Chinese Windows (`CP936` / GBK locale)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:11:24 +00:00
Author
Owner

@⁠californiaAlmonds on GitHub · 2026-11-26 07:52 UTC · original

Fixed by PR #50 (merged to main — thanks @⁠leonredfish!).

**@⁠californiaAlmonds** on GitHub · 2026-11-26 07:52 UTC · [original](https://github.com/californiaAlmonds/OpenScarlett/issues/43#issuecomment-7185928994) Fixed by PR #50 (merged to main — thanks @⁠leonredfish!).
This discussion has been locked. Commenting is limited to contributors.
No description provided.