Skip to content

Commit 8b11c39

Browse files
authored
[llvm-mt] Do not build llvm-mt if not functional (#134631)
llvm-mt requires libxml2 to work, so do not even build it without libxml2. CMake 3.31 and later prefer llvm-mt.exe over Microsoft's mt.exe if available and using clang-cl.exe as CMAKE_CXX_COMPILER. When CMake picks up llvm-mt.exe without libxml2, any build will fail with the message ``` llvm-mt: error: no libxml2 ``` Any test except `--help` already uses `REQUIRES: libxml2`. There is no point in having a non-functional executable. Not building llvm-mt.exe will force CMake to use Microsoft's `mt.exe` instead. Fixes: #134237
1 parent b2dea4f commit 8b11c39

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

llvm/docs/CMake.rst

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,16 +1191,6 @@ Windows
11911191
Studio 2010 CMake generator. 0 means use all processors. Default is 0.
11921192

11931193
**CMAKE_MT**:STRING
1194-
When compiling with clang-cl, recent CMake versions will default to selecting
1195-
`llvm-mt` as the Manifest Tool instead of Microsoft's `mt.exe`. This will
1196-
often cause errors like:
1197-
1198-
.. code-block:: console
1199-
1200-
-- Check for working C compiler: [...]clang-cl.exe - broken
1201-
[...]
1202-
MT: command [...] failed (exit code 0x1) with the following output:
1203-
llvm-mt: error: no libxml2
1204-
ninja: build stopped: subcommand failed.
1205-
1206-
To work around this error, set `CMAKE_MT=mt`.
1194+
When compiling with clang-cl, CMake may use `llvm-mt` as the Manifest Tool
1195+
when available. `llvm-mt` is only present when libxml2 is found at build-time.
1196+
To ensure using Microsoft's Manifest Tool set `CMAKE_MT=mt`.

llvm/test/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ set(LLVM_TEST_DEPENDS
111111
llvm-ml
112112
llvm-ml64
113113
llvm-modextract
114-
llvm-mt
115114
llvm-nm
116115
llvm-objcopy
117116
llvm-objdump
@@ -173,6 +172,10 @@ if(TARGET LTO)
173172
set(LLVM_TEST_DEPENDS ${LLVM_TEST_DEPENDS} LTO)
174173
endif()
175174

175+
if (TARGET llvm-mt)
176+
list(APPEND LLVM_TEST_DEPENDS llvm-mt)
177+
endif ()
178+
176179
if(LLVM_BUILD_EXAMPLES)
177180
list(APPEND LLVM_TEST_DEPENDS
178181
Kaleidoscope-Ch3

llvm/test/tools/llvm-mt/help.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
REQUIRES: libxml2
12
RUN: llvm-mt /h | FileCheck %s -check-prefix=HELP
23

34
HELP: OVERVIEW: Manifest Tool

llvm/tools/llvm-mt/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
if (NOT LLVM_ENABLE_LIBXML2)
2+
message(STATUS "Not building llvm-mt${CMAKE_EXECUTABLE_SUFFIX} because libxml2 is not available")
3+
return()
4+
endif ()
5+
16
set(LLVM_LINK_COMPONENTS
27
Option
38
Support

0 commit comments

Comments
 (0)