From 9f5572c525e7cff19d544d4d03a1ab3fa04f5bd1 Mon Sep 17 00:00:00 2001 From: fanlusky <1730976608@qq.com> Date: Wed, 30 Sep 2026 15:37:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(build):=20=E6=89=80=E6=9C=89=20MSVC=20?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E6=98=BE=E5=BC=8F=E6=8C=89=20UTF-8=20?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E6=BA=90=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #548 修了 ngram,同类问题还有几处:源文件或头文件是无 BOM 的 UTF-8, 目标却没有 /utf-8,在代码页 936 的系统上注释会吞掉换行。 - ui:Controls.h 让 msimeui 与各 demo 单独构建失败,/utf-8 设为 PUBLIC - server/tests/portable:input_key_policy.h 让 MSVC 构建失败 - engine test_windows_ipc_contract、tests/pipe-probe、windows/tests:C4819 - windows DLL:此前只靠 fmt 的 INTERFACE 选项带来 /utf-8,改为显式设置, 否则 L"“" 等宽字符标点会在去掉 fmt 后静默变成乱码 --- engine/CMakeLists.txt | 3 +++ server/tests/portable/CMakeLists.txt | 5 ++++- tests/pipe-probe/CMakeLists.txt | 3 +++ ui/CMakeLists.txt | 3 +++ windows/CMakeLists.txt | 3 +++ windows/tests/CMakeLists.txt | 4 ++++ 6 files changed, 20 insertions(+), 1 deletion(-) diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index 58fe544d..5a1425fc 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -157,6 +157,9 @@ if(BUILD_TESTING) add_test(NAME segmentation_contract COMMAND test_segmentation_contract) add_executable(test_windows_ipc_contract contracts/tests/windows_ipc_contract.cpp) + if(MSVC) + target_compile_options(test_windows_ipc_contract PRIVATE /utf-8) + endif() add_test(NAME windows_ipc_contract COMMAND test_windows_ipc_contract) add_executable(test_punctuation_contract contracts/tests/punctuation_contract.cpp) diff --git a/server/tests/portable/CMakeLists.txt b/server/tests/portable/CMakeLists.txt index 7d8c6692..542057af 100644 --- a/server/tests/portable/CMakeLists.txt +++ b/server/tests/portable/CMakeLists.txt @@ -32,7 +32,10 @@ if(MSIME_PORTABLE_TESTS_SANITIZE AND NOT MSVC) target_link_options(portable_tests PRIVATE -fsanitize=address,undefined) endif() -if(NOT MSVC) +if(MSVC) + # Standalone project, so the server's directory-wide /utf-8 does not reach it. + target_compile_options(portable_tests PRIVATE /utf-8) +else() target_compile_options(portable_tests PRIVATE -Wall -Wextra -Wpedantic -Werror) endif() diff --git a/tests/pipe-probe/CMakeLists.txt b/tests/pipe-probe/CMakeLists.txt index 9ac39505..b89c5c47 100644 --- a/tests/pipe-probe/CMakeLists.txt +++ b/tests/pipe-probe/CMakeLists.txt @@ -8,3 +8,6 @@ add_executable(msime-ipc-probe main.cpp) target_compile_features(msime-ipc-probe PRIVATE cxx_std_17) target_compile_definitions(msime-ipc-probe PRIVATE NOMINMAX UNICODE _UNICODE) target_include_directories(msime-ipc-probe PRIVATE "${MSIME_CONTRACTS_DIR}") +if(MSVC) + target_compile_options(msime-ipc-probe PRIVATE /utf-8) +endif() diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index ebaab879..ce64f633 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -143,6 +143,9 @@ target_link_libraries(msimeui-handwriting-demo PRIVATE msimeui windowsapp.lib) target_compile_features(msimeui-handwriting-demo PRIVATE cxx_std_20) if(MSVC) + # include/msimeui/Controls.h is UTF-8 without a BOM, so every consumer of msimeui has to read + # it as UTF-8 too; otherwise a CJK-locale build (code page 936) swallows lines and fails. + target_compile_options(msimeui PUBLIC /utf-8) target_compile_options(msimeui PRIVATE /W4 /permissive-) target_compile_options(msimeui-demo PRIVATE /W4 /permissive-) target_compile_options(msimeui-emoji-panel PRIVATE /W4 /permissive-) diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index 4e3e3b07..04ea68b8 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -13,6 +13,9 @@ project(${PROJECT_NAME} LANGUAGES CXX C) # Release binaries need usable symbols for crash diagnosis. Keep the PDB beside the DLL so the # release job can validate and publish it without changing the binary's install layout. if(MSVC) + # Sources are UTF-8 without a BOM and hold wide punctuation literals (L"“" and the like). /utf-8 + # used to arrive only through fmt's interface options, which the tests below never link. + add_compile_options(/utf-8) set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "ProgramDatabase") add_compile_options("$<$:/Zi>") add_link_options("$<$:/DEBUG>") diff --git a/windows/tests/CMakeLists.txt b/windows/tests/CMakeLists.txt index 6a44dc6f..e3e2b506 100644 --- a/windows/tests/CMakeLists.txt +++ b/windows/tests/CMakeLists.txt @@ -4,6 +4,10 @@ cmake_minimum_required(VERSION 3.25) if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) project(MsimeTsfLocalPolicyTests LANGUAGES CXX) enable_testing() + # windows/CMakeLists.txt sets this for the in-tree build; the sources and headers are UTF-8. + if(MSVC) + add_compile_options(/utf-8) + endif() endif() add_executable(test_client_fallback client_fallback.cpp)