let cmake use clang-cl when use ninja, not clang++ ,so people can migrate from visual studio nmake to ninja.
OpenClaw (codebuddy.ai) output translate:
Here’s a natural, technically-accurate English translation (good for a Slack/PR comment or bug report):
Found the root cause — it’s a CMake 4.4 misdetection bug for clang-cl:
In rules.ninja, every C++ compile rule has its command hard-coded to clang++ (the GCC driver):
command = ${LAUNCHER}${CODE_CHECK}clang++ /nologo -TP $DEFINES ...
But the flags are MSVC-style clang-cl flags (/nologo, /Fo, /EHsc, -target x86_64-pc-windows-msvc, -clang:-MD…). CMake identified the compiler as Clang with FRONTEND_VARIANT=MSVC, yet still emitted the binary name as clang++ following the plain-Clang convention — instead of clang-cl. It’s the same binary (identical size, literally the same clang); launched as clang++ it’s in GCC mode and rejects /nologo, while launched as clang-cl it’s in CL mode and accepts everything.
The link rule uses lld-link.exe (full path, fine), and the RC rule uses rc (needs to be on PATH). So as long as we swap clang++ → clang-cl in the rules and add LLVM/bin + SDK/bin to PATH, it builds.
I’ll first replace all clang++ with clang-cl in rules.ninja and verify:
chinese orijin output.
A few wording notes
- 判定 bug → “misdetection bug” / “compiler-identification bug” (more natural than “judgment bug”)
- 写死 → “hard-coded”
- GCC 驱动 / CL 模式 → “GCC driver” / “CL mode” (standard CMake/LLVM terminology)
- 不认 / 全部认 → “rejects … / accepts everything”
- 编过 → “it builds” / “the build goes through”
想要更偏 upstream bug report 的正式语气,或者更短的 IRC/Slack 口语版也可以告诉我~
找到根因了,是个 CMake 4.4 对 clang-cl 的判定 bug:
rules.ninja 里所有 C++ 编译规则的命令被写死成了 clang++(GCC 驱动):
command = ${LAUNCHER}${CODE_CHECK}clang++ /nologo -TP $DEFINES ...
但 flags 却是 clang-cl(MSVC)风格的(/nologo、/Fo、/EHsc、-target x86_64-pc-windows-msvc、-clang:-MD…)。CMake 把编译器识别成了 Clang + FRONTEND_VARIANT=MSVC,却按 Clang 的套路把二进制名写成了 clang++,而不是 clang-cl。同一个二进制(大小完全一致,是同一份 clang),用 clang++ 起来是 GCC 模式,不认 /nologo;用 clang-cl 起来是 CL 模式,全部认。
链接规则用的是 lld-link.exe(完整路径,没问题),RC 规则用的是 rc(PATH 上要有)。所以只要把规则里的 clang++ 改成 clang-cl,并把 LLVM/bin 和 SDK/bin 加进 PATH,就能编过。
我先把 rules.ninja 里的 clang++ 全部替换成 clang-cl 并验证:
cmake output
[10/35] Building CXX object CMakeFiles\photol.dir\photol\photol\lang2.cpp.obj
FAILED: [code=1] CMakeFiles/photol.dir/photol/photol/lang2.cpp.obj
clang++ /nologo -TP -DNDEBUG -DNOMINMAX -DUNICODE -DWIN32_LEAN_AND_MEAN -D_UNICODE -D_USRDLL -D_WINDOWS -Dphotol_EXPORTS -ID:\Community -ID:\Community\third\opencv\opencv-4.8.0_build_vs2019_x64\install\include -ID:\Community\third\libmediainfo_AllInclusive\MediaInfoLib\Source -ID:\Community\third\libmediainfo_AllInclusive\ZenLib\Source -ID:\Community\third\osg-3rdparty-cmake-master\giflib\giflib-5.2.1 -ID:\Community\third\sqlite3mc-1.5.4\sqlite3mc-1.5.4 /DWIN32 /D_WINDOWS /GR /EHsc -target x86_64-pc-windows-msvc /Zi /Ob0 /Od /RTC1 -std:c++17 -MT -include photol/photol/stdafx.h -clang:-MD -clang:-MTCMakeFiles\photol.dir\photol\photol\lang2.cpp.obj -clang:-MFCMakeFiles\photol.dir\photol\photol\lang2.cpp.obj.d /FoCMakeFiles\photol.dir\photol\photol\lang2.cpp.obj /FdCMakeFiles\photol.dir\ -c – D:\Community\photol\photol\lang2.cpp
clang++: error: unknown argument: ‘-std:c++17’
clang++: error: unknown argument: ‘-clang:-MD’
clang++: error: unknown argument: ‘-clang:-MTCMakeFiles\photol.dir\photol\photol\lang2.cpp.obj’
clang++: error: unknown argument: ‘-clang:-MFCMakeFiles\photol.dir\photol\photol\lang2.cpp.obj.d’
clang++: error: no such file or directory: ‘/nologo’
clang++: error: no such file or directory: ‘/DWIN32’
clang++: error: no such file or directory: ‘/D_WINDOWS’
clang++: error: no such file or directory: ‘/GR’
clang++: error: no such file or directory: ‘/EHsc’
clang++: error: no such file or directory: ‘/Zi’
clang++: error: no such file or directory: ‘/Ob0’
clang++: error: no such file or directory: ‘/Od’
clang++: error: no such file or directory: ‘/RTC1’
clang++: warning: treating ‘c-header’ input as ‘c+±header’ when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang++: error: no such file or directory: ‘photol/photol/stdafx.h’
clang++: error: no such file or directory: ‘/FoCMakeFiles\photol.dir\photol\photol\lang2.cpp.obj’
clang++: error: no such file or directory: ‘/FdCMakeFiles\photol.dir’
ninja: build stopped: subcommand failed.