fix(build): 所有 MSVC 目标显式按 UTF-8 编译源文件
#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 后静默变成乱码
This commit is contained in:
1 parent
68742373e3
commit
9f5572c525
6 files changed
+20
-1
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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()
|
||||
@@ -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-)
|
||||
|
||||
@@ -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("$<$<CONFIG:Release>:/Zi>")
|
||||
add_link_options("$<$<CONFIG:Release>:/DEBUG>")
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user