<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/134237>134237</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            CMake prefers llvm-mt even when compiled without libxml2
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            platform:windows,
            llvm-mt
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Meinersbur
      </td>
    </tr>
</table>

<pre>
    Since CMake 3.31 (commit https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9847) LLVM's llvm-mt.exe is prefered over Microsoft's mt.exe when compiling with clang-cl. When LLVM is not compiled with libxml2, the build fails with:
```
 Run Build Command(s): C:/ProgramData/chocolatey/bin/ninja.exe -v cmTC_bdbfc
 0.049 [1/1/1] C:\\buildbot\\flang-x86_64-windows\\build\\bin\\clang-cl.exe --target=x86_64-pc-windows-msvc  /nologo   /DWIN32 /D_WINDOWS  /Ob0 /Od /RTC1 -MDd -Zi /showIncludes /FoCMakeFiles\\cmTC_bdbfc.dir\\CMakeCCompilerABI.c.obj /FdCMakeFiles\\cmTC_bdbfc.dir\\ -c -- "C:\\Program Files\\CMake\\share\\cmake-3.31\\Modules\\CMakeCCompilerABI.c"
 0.247 [0/1/2] C:\\Windows\\system32\\cmd.exe /C "cd . && "C:\\Program Files\\CMake\\bin\\cmake.exe" -E vs_link_exe --msvc-ver=1943 --intdir=CMakeFiles\\cmTC_bdbfc.dir --rc=C:\\buildbot\\flang-x86_64-windows\\build\\.\\bin\\llvm-rc.exe --mt=C:\\buildbot\\flang-x86_64-windows\\build\\bin\\llvm-mt.exe --manifests  -- C:\\PROGRA~1\\MICROS~2\\2022\\COMMUN~1\\VC\\Tools\\MSVC\\1443~1.348\\bin\\Hostx64\\x64\\link.exe /nologo CMakeFiles\\cmTC_bdbfc.dir\\CMakeCCompilerABI.c.obj /out:cmTC_bdbfc.exe /implib:cmTC_bdbfc.lib /pdb:cmTC_bdbfc.pdb /version:0.0 /machine:x64  /debug /INCREMENTAL /subsystem:console   && cd ."
 FAILED: cmTC_bdbfc.exe 
        C:\\Windows\\system32\\cmd.exe /C "cd . && "C:\\Program Files\\CMake\\bin\\cmake.exe" -E vs_link_exe --msvc-ver=1943 --intdir=CMakeFiles\\cmTC_bdbfc.dir --rc=C:\\buildbot\\flang-x86_64-windows\\build\\.\\bin\\llvm-rc.exe --mt=C:\\buildbot\\flang-x86_64-windows\\build\\bin\\llvm-mt.exe --manifests  -- C:\\PROGRA~1\\MICROS~2\\2022\\COMMUN~1\\VC\\Tools\\MSVC\\1443~1.348\\bin\\Hostx64\\x64\\link.exe /nologo CMakeFiles\\cmTC_bdbfc.dir\\CMakeCCompilerABI.c.obj /out:cmTC_bdbfc.exe /implib:cmTC_bdbfc.lib /pdb:cmTC_bdbfc.pdb /version:0.0 /machine:x64  /debug /INCREMENTAL /subsystem:console   && cd ."
        MT: command "C:\\buildbot\\flang-x86_64-windows\\build\\bin\\llvm-mt.exe /nologo /manifest CMakeFiles\\cmTC_bdbfc.dir/intermediate.manifest /out:CMakeFiles\\cmTC_bdbfc.dir/embed.manifest /notify_update" failed (exit code 0x1) with the following output:
        llvm-mt: error: no libxml2\x0d
        ninja: build stopped: subcommand failed.
```

When building a bootstapping runtimes build (e.g. `LLVM_ENABLE_RUNTIMES=flang-rt`) what happens depends whether `llvm-mt.exe` has been built before `ninja runtimes` or not. If it was, the runtimes build fails with:

```
901.041 [16/12/6860] Performing configure step for 'runtimes'
Not searching for unused variables given on the command line.
loading initial cache file C:/buildbot/flang-x86_64-windows/build/projects/runtimes/tmp/runtimes-cache-Release.cmake
-- Performing bootstrapping runtimes build.
CMake Deprecation Warning at C:/buildbot/flang-x86_64-windows/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):
  The OLD behavior for policy CMP0116 will be removed from a future version
  of CMake.
  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  CMakeLists.txt:18 (include)
-- The C compiler identification is Clang 21.0.0 with MSVC-like command-line
-- The CXX compiler identification is Clang 21.0.0 with MSVC-like command-line
-- The ASM compiler identification is Clang with MSVC-like command-line
-- Found assembler: C:/buildbot/flang-x86_64-windows/build/bin/clang-cl.exe
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
[...]
```
With ABI info detection failed, some CMake features are not available, such as `target_compile_features`.

Observed with the [flang-x86_64-windows](https://lab.llvm.org/staging/#/builders/36) builder which failes irregularly because of this.



Related:
 * https://discourse.llvm.org/t/cannot-cmake-self-hosted-clang-on-windows-for-lack-of-libxml2/58793/8
 * https://github.com/llvm/llvm-project/issues/55817
 * https://gitlab.kitware.com/cmake/cmake/-/commit/73d0d4e4b5dd937dcc913a94a6ebac3085a01896
 * https://gitlab.kitware.com/cmake/cmake/-/issues/26319
 
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWM1y2zgSfhr40kUWBUqUdNBBlqxdV1l2yvaMp_aiAsmmhBgEuAAo25c8-1aDpCJ7MpvsZo5xKREINj58_asGhHNyrxEXbHLJJusL0fqDsYstSo3W5a29yE35tniQukBYbcUzQhqnI2B8Vpi6lh4O3jeOpUvGN4xv9tIrkcfP0r8Ii3FhasY3RS2e8ew7YnxTo93jzuK_W3TeMb6Zz8ZTxudwc_P7lvGpA6WOdVT7GF8RpIPGYoUWSzBHtLCVhTXOVD6I9lIvB9RQmLqRSuo9vEh_gEIJvY8KFcMTvSV0QtPG95JYdoJK5q-14oyvwB8Q8laqEiohlQvvScNkybKk_yRLuG81XAaxlalroUvGZ47xOUuXsOos8smavRX1WnhB-h9MYZTw-Mb4Jpea8Y2W-rMI5KMjFPXjapeXeVUQfBIn4zmwyeWI8U33b7LugCcrNlkFhrnx3VMV9HydZbtsHL1IXZoXdybXD6XuBierhJ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