Skip to content

Commit ebafcb8

Browse files
mstorsjotru
authored andcommitted
[CMake] Respect variables for specifying host tools even without LLVM_USE_HOST_TOOLS set
When LLVM_NATIVE_TOOL_DIR was introduced in d3da906 / D131052, it consisted of refactoring a couple cases of manual logic for tools in clang-tools-extra/clang-tidy, clang-tools-extra/pseudo/include and mlir/tools/mlir-linalg-ods-gen. The former two had the same consistent behaviour while the latter was slightly different, so the refactoring would end up slightly adjusting one or the other. The difference was that the clang-tools-extra tools respected the external variable for setting the tool name, regardless of the LLVM_USE_HOST_TOOLS variable, while mlir-linalg-ods-gen tool only checked its external variable if LLVM_USE_HOST_TOOLS was set. LLVM_USE_HOST_TOOLS is supposed to be enabled automatically whenever cross compiling, so this shouldn't have been an issue. In #60784, it seems like some users do cross compile LLVM, without CMake knowing about it (without CMAKE_CROSSCOMPILING being set). In these cases, their build broke, as the variables for pointing to external host tools no longer were being respected. The fact that CMAKE_CROSSCOMPILING wasn't set stems from a non-obvious behaviour of CMake; CMAKE_CROSSCOMPILING isn't supposed to be set by the user (and if it was, it gets overridden), but one has to set CMAKE_SYSTEM_NAME to indicate that one is cross compiling, even if the target OS is the same as the current host. Skip the checks for LLVM_USE_HOST_TOOLS and always respect the variables for pointing to external tools (both the old tool specific variables, and the new LLVM_NATIVE_TOOL_DIR), if they're set. This makes the logic within setup_host_tool more exactly match the logic for the clang-tools-extra tools from before the refactoring in d3da906. This makes the behaviour consistent with that of the tablegen executables, which also respect the externally set variables regardless of LLVM_USE_HOST_TOOLS. This fixes #60784. Differential Revision: https://reviews.llvm.org/D146666 (cherry picked from commit 4a5bc79)
1 parent 8de1b29 commit ebafcb8

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2400,7 +2400,7 @@ endfunction()
24002400
function(setup_host_tool tool_name setting_name exe_var_name target_var_name)
24012401
set(${setting_name}_DEFAULT "${tool_name}")
24022402

2403-
if(LLVM_USE_HOST_TOOLS AND LLVM_NATIVE_TOOL_DIR)
2403+
if(LLVM_NATIVE_TOOL_DIR)
24042404
if(EXISTS "${LLVM_NATIVE_TOOL_DIR}/${tool_name}${LLVM_HOST_EXECUTABLE_SUFFIX}")
24052405
set(${setting_name}_DEFAULT "${LLVM_NATIVE_TOOL_DIR}/${tool_name}${LLVM_HOST_EXECUTABLE_SUFFIX}")
24062406
endif()
@@ -2409,14 +2409,12 @@ function(setup_host_tool tool_name setting_name exe_var_name target_var_name)
24092409
set(${setting_name} "${${setting_name}_DEFAULT}" CACHE
24102410
STRING "Host ${tool_name} executable. Saves building if cross-compiling.")
24112411

2412-
if(LLVM_USE_HOST_TOOLS)
2413-
if(NOT ${setting_name} STREQUAL "${tool_name}")
2414-
set(exe_name ${${setting_name}})
2415-
set(target_name ${${setting_name}})
2416-
else()
2417-
build_native_tool(${tool_name} exe_name DEPENDS ${tool_name})
2418-
set(target_name ${exe_name})
2419-
endif()
2412+
if(NOT ${setting_name} STREQUAL "${tool_name}")
2413+
set(exe_name ${${setting_name}})
2414+
set(target_name ${${setting_name}})
2415+
elseif(LLVM_USE_HOST_TOOLS)
2416+
build_native_tool(${tool_name} exe_name DEPENDS ${tool_name})
2417+
set(target_name ${exe_name})
24202418
else()
24212419
set(exe_name $<TARGET_FILE:${tool_name}>)
24222420
set(target_name ${tool_name})

0 commit comments

Comments
 (0)