Skip to content

Invalid cmakelists generator when clang with msvc frontend used #7526

@Northn

Description

@Northn

Xmake Version

3.0.8

Operating System Version and Architecture

Windows 11 25H2 (build 26200.8246)

Describe Bug

xmake is generating incorrect cmakelists file, leading to many unknown argument ignored in clang-cl warnings when used with clang-cl

Expected Behavior

xmake should generate more strict checks for msvc frontend and pick the compiling arguments based on this information

Project Configuration

hello-world.zip

xmake project -y -k cmake -a x64 .
cmake -B build -A x64 -T ClangCL
cmake --build build

Additional Information and Error Logs

D:\hello-world>xmake f -y -c -p windows -a x64 -m debug --toolchain=clang-cl -vD
checking for clang-cl.exe ... C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin\clang-cl.exe
checking for LLVM Clang C/C++ Compiler (x64) ... ok
checking for llvm resource dir ... C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\lib\clang\19
checking for llvm target triple ... x86_64-pc-windows-msvc
checking for Microsoft Visual Studio (x64) version ... 2022
checking for clang-cl ... C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin\clang-cl
checking for the c++ compiler (cxx) ... clang-cl
checking for link.exe ... C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64\link.exe
checking for the linker (ld) ... link.exe
configure
{
    ccache = true
    toolchain = clang-cl
    mode = debug
    plat = windows
    ndk_stdcxx = true
    vs = 2022
    builddir = build
    arch = x64
    clean = true
    kind = static
    host = windows
}

D:\hello-world>xmake project -y -k cmake -a x64 -vD .
configure
{
    ndk_stdcxx = true
    toolchain = clang-cl
    vs = 2022
    host = windows
    plat = windows
    arch = x64
    builddir = build
    mode = debug
    ccache = true
    kind = static
    clean = true
}
checking for cmake ... C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe
checking for clang-cl ... C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin\clang-cl
checking for the c compiler (cc) ... clang-cl
checking for the c++ compiler (cxx) ... clang-cl
create ok!

D:\hello-world>cmake -B build -A x64 -T ClangCL
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.26100.0 to target Windows 10.0.26200.
-- The CXX compiler identification is Clang 19.1.5 with MSVC-like command-line
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/Llvm/x64/bin/clang-cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (2.7s)
-- Generating done (0.0s)
-- Build files have been written to: D:/hello-world/build

D:\hello-world>cmake --build build -v
Change Dir: 'D:/hello-world/build'

Run Build Command(s): "C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe" ALL_BUILD.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=17.0 /v:n
MSBuild version 17.14.23+b0019275e for .NET Framework
Build started 04.05.2026 11:43:40.

Project "D:\hello-world\build\ALL_BUILD.vcxproj" on node 1 (default targets).
Project "D:\hello-world\build\ALL_BUILD.vcxproj" (1) is building "D:\hello-world\build\ZERO_CHECK.vcxproj" (2) on node 1 (default targets).
PrepareForBuild:
  Creating directory "x64\Debug\ZERO_CHECK\".
  Structured output is enabled. The formatting of compiler diagnostics will reflect the error hierarchy. See https://aka.ms/cpp/structured-output for more details.
  Creating directory "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\".
InitializeBuildStatus:
  Creating "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
  Touching "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild".
CustomBuild:
  1>Checking Build System
FinalizeBuildStatus:
  Deleting file "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild".
  Touching "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\ZERO_CHECK.lastbuildstate".
Done Building Project "D:\hello-world\build\ZERO_CHECK.vcxproj" (default targets).

Project "D:\hello-world\build\ALL_BUILD.vcxproj" (1) is building "D:\hello-world\build\hello-world.vcxproj" (3) on node 1 (default targets).
PrepareForBuild:
  Creating directory "hello-world.dir\Debug\".
  Structured output is enabled. The formatting of compiler diagnostics will reflect the error hierarchy. See https://aka.ms/cpp/structured-output for more details.
  Creating directory "D:\hello-world\build\windows\x64\debug\Debug\".
  Creating directory "hello-world.dir\Debug\hello-world.tlog\".
InitializeBuildStatus:
  Creating "hello-world.dir\Debug\hello-world.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
  Touching "hello-world.dir\Debug\hello-world.tlog\unsuccessfulbuild".
CustomBuild:
  Building Custom Rule D:/hello-world/CMakeLists.txt
ClCompile:
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin\clang-cl.exe /c /Z7 /nologo /W1 /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /EHs
  c /MDd /GS /fp:precise /GR /Fo"hello-world.dir\Debug\\" /Gd /TP --target=amd64-pc-windows-msvc   -clang:-std=c++23 --target=x86_64-pc-windows-msvc -fexceptions -fcxx-exceptions -O0 -g "D:\hello-world\src\ma
  in.cpp"
clang-cl : warning : unknown argument ignored in clang-cl: '-fexceptions' [-Wunknown-argument] [D:\hello-world\build\hello-world.vcxproj]
clang-cl : warning : unknown argument ignored in clang-cl: '-fcxx-exceptions' [-Wunknown-argument] [D:\hello-world\build\hello-world.vcxproj]
clang-cl : warning : argument unused during compilation: '-O0' [-Wunused-command-line-argument] [D:\hello-world\build\hello-world.vcxproj]
MakeDirsForLink:
  Creating directory "D:\hello-world\build\Debug\".
Link:
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin\lld-link.exe /OUT:"D:\hello-world\build\windows\x64\debug\Debug\hello-world.exe" /INCREMENTAL kernel32.lib user32.lib gdi32.lib
  winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG:FULL /PDB:"D:/hello-world/build/windows/
  x64/debug/Debug/hello-world.pdb" /SUBSYSTEM:CONSOLE /DYNAMICBASE /NXCOMPAT /IMPLIB:"D:/hello-world/build/Debug/hello-world.lib"   /machine:x64 "hello-world.dir\Debug\main.obj"
  hello-world.vcxproj -> D:\hello-world\build\windows\x64\debug\Debug\hello-world.exe
FinalizeBuildStatus:
  Deleting file "hello-world.dir\Debug\hello-world.tlog\unsuccessfulbuild".
  Touching "hello-world.dir\Debug\hello-world.tlog\hello-world.lastbuildstate".
Done Building Project "D:\hello-world\build\hello-world.vcxproj" (default targets).

PrepareForBuild:
  Creating directory "x64\Debug\ALL_BUILD\".
  Structured output is enabled. The formatting of compiler diagnostics will reflect the error hierarchy. See https://aka.ms/cpp/structured-output for more details.
  Creating directory "x64\Debug\ALL_BUILD\ALL_BUILD.tlog\".
InitializeBuildStatus:
  Creating "x64\Debug\ALL_BUILD\ALL_BUILD.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
  Touching "x64\Debug\ALL_BUILD\ALL_BUILD.tlog\unsuccessfulbuild".
CustomBuild:
  Building Custom Rule D:/hello-world/CMakeLists.txt
FinalizeBuildStatus:
  Deleting file "x64\Debug\ALL_BUILD\ALL_BUILD.tlog\unsuccessfulbuild".
  Touching "x64\Debug\ALL_BUILD\ALL_BUILD.tlog\ALL_BUILD.lastbuildstate".
Done Building Project "D:\hello-world\build\ALL_BUILD.vcxproj" (default targets).


Build succeeded.

"D:\hello-world\build\ALL_BUILD.vcxproj" (default target) (1) ->
"D:\hello-world\build\hello-world.vcxproj" (default target) (3) ->
(ClCompile target) ->
  clang-cl : warning : unknown argument ignored in clang-cl: '-fexceptions' [-Wunknown-argument] [D:\hello-world\build\hello-world.vcxproj]
  clang-cl : warning : unknown argument ignored in clang-cl: '-fcxx-exceptions' [-Wunknown-argument] [D:\hello-world\build\hello-world.vcxproj]
  clang-cl : warning : argument unused during compilation: '-O0' [-Wunused-command-line-argument] [D:\hello-world\build\hello-world.vcxproj]

    3 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.42


D:\hello-world>
clang-cl --version
clang version 19.1.5
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin

cmake --version
cmake version 3.31.6-msvc6

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions