From 4a88950a1401640a176ccd59e4e22bc8812fe330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E9=A3=8E=E9=80=8D=E9=81=A5=E6=B8=B8?= Date: Sat, 29 Aug 2026 10:53:29 +0800 Subject: [PATCH] feat(build): add MSVC cl.exe wrapper for UTF-8 compatibility in Ninja builds --- CMakeLists.txt | 15 +++++++++++++++ Makefile | 4 ++-- cmake/msvc-cl.cmd | 7 +++++++ cmake/with-msvc.cmd | 2 ++ 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 cmake/msvc-cl.cmd diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a1a89b6..eac83886 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,21 @@ endif() project(EVEngine) +if(WIN32 AND MSVC AND CMAKE_GENERATOR MATCHES "Ninja") + # sccache (and any other launcher) CreateProcess()es cl.exe with a pipe; + # localized cl then writes ACP /showIncludes (GBK) while Ninja's + # msvc_deps_prefix is UTF-8, so every header leaks into the build log. + # Route compiles through cmake/msvc-cl.cmd so cl inherits CP65001. + set(_eve_msvc_cl_wrap "${CMAKE_SOURCE_DIR}/cmake/msvc-cl.cmd") + foreach(_eve_lang IN ITEMS C CXX) + get_filename_component(_eve_comp_name "${CMAKE_${_eve_lang}_COMPILER}" NAME) + if(_eve_comp_name MATCHES "^cl(\\.exe)?$") + set(CMAKE_${_eve_lang}_COMPILER "${_eve_msvc_cl_wrap}" + CACHE FILEPATH "MSVC cl UTF-8 /showIncludes wrapper" FORCE) + endif() + endforeach() +endif() + if(_eve_sccache_enabled AND MSVC) if(POLICY CMP0141) # Embed debug information in each object. Cached objects are then diff --git a/Makefile b/Makefile index f211aef5..6038fed2 100644 --- a/Makefile +++ b/Makefile @@ -260,8 +260,8 @@ ARCHITECTURE_BASE ?= HEAD # Reusable configure command lines: used both by the first-configure rules and # by the on-change reconfigure inside the build recipes below. -WIN32_CMAKE_ARGS = -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl $(CMAKE_EXTRA_ARGS) -B build/win32 -S . -WIN32_DEBUG_CMAKE_ARGS = -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl $(CMAKE_EXTRA_ARGS) -B build/win32-debug -S . +WIN32_CMAKE_ARGS = -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=cmake/msvc-cl.cmd -DCMAKE_CXX_COMPILER=cmake/msvc-cl.cmd $(CMAKE_EXTRA_ARGS) -B build/win32 -S . +WIN32_DEBUG_CMAKE_ARGS = -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=cmake/msvc-cl.cmd -DCMAKE_CXX_COMPILER=cmake/msvc-cl.cmd $(CMAKE_EXTRA_ARGS) -B build/win32-debug -S . LINUX_CMAKE_ARGS = -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Release -DBUILD_PLATFORM=linux $(CMAKE_EXTRA_ARGS) -B build/linux -S . LINUX_DEBUG_CMAKE_ARGS = -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Debug -DBUILD_PLATFORM=linux $(CMAKE_EXTRA_ARGS) -B build/linux-debug -S . MACOSX_CMAKE_ARGS = -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Release -DBUILD_PLATFORM=macosx $(CMAKE_EXTRA_ARGS) -B build/macosx -S . diff --git a/cmake/msvc-cl.cmd b/cmake/msvc-cl.cmd new file mode 100644 index 00000000..7f29d8e1 --- /dev/null +++ b/cmake/msvc-cl.cmd @@ -0,0 +1,7 @@ +@echo off +rem Used as CMAKE_C/CXX_COMPILER under Ninja+sccache so cl.exe is a child of +rem this cmd (CP65001), not of sccache's ACP pipe. +chcp 65001 >nul +set "VSLANG=1033" +cl.exe %* +exit /b %ERRORLEVEL% diff --git a/cmake/with-msvc.cmd b/cmake/with-msvc.cmd index 0aa2c8e2..b1cbb0bf 100644 --- a/cmake/with-msvc.cmd +++ b/cmake/with-msvc.cmd @@ -1,6 +1,8 @@ @echo off chcp 65001 >nul setlocal +rem Prefer English cl.exe messages when the 1033 language pack is installed. +set "VSLANG=1033" set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" if not exist "%VSWHERE%" ( echo error: vswhere.exe not found at "%VSWHERE%" >&2