Skip to content

Commit 32ef417

Browse files
authored
Fix CMake dependencies on mlir-linalg-ods-yaml-gen (llvm#113565)
Fix a number of dependencies issue to build mlir-linalg-ods-yaml-gen host binary which make a cross-build using the Make generator fail. Namely: - do not use binary path for the custom target created when LLVM_USE_HOST_TOOLS is true; - use target name instead of name of variable holding the target name for add_custom_target and set_target_properties in setup_host_tool(); - force setting of executable and target cache variable which are only used as global variables; - remove dependency on target defined in different directory in add_linalg_ods_yaml_gen() since add_custom_target DEPENDS can only be used on "files and outputs of custom commands created with add_custom_command() command calls in the same directory"; - remove unneeded dependency on ${MLIR_LINALG_ODS_YAML_GEN_EXE}, the target dependency will ensure the binary will be built. Note that we keep using ${MLIR_LINALG_ODS_YAML_GEN_EXE} in the COMMAND rather than use ${MLIR_LINALG_ODS_YAML_GEN_TARGET} because when LLVM_NATIVE_TOOL_DIR is used the latter is an empty string. Testing-wise, all three codepaths in get_host_tool_path() were tested with both GNU Make and Ninja generators: - cross-compiling with LLVM_NATIVE_TOOL_DIR checks the if path; - cross-compiling without LLVM_NATIVE_TOOL_DIR checks the elseif path; - native build without LLVM_NATIVE_TOOL_DIR checks the else path.
1 parent b7749ef commit 32ef417

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

llvm/cmake/modules/AddLLVM.cmake

+8-5
Original file line numberDiff line numberDiff line change
@@ -2618,22 +2618,25 @@ function(get_host_tool_path tool_name setting_name exe_var_name target_var_name)
26182618
set(target_name "")
26192619
elseif(LLVM_USE_HOST_TOOLS)
26202620
get_native_tool_path(${tool_name} exe_name)
2621-
set(target_name ${exe_name})
2621+
set(target_name host_${tool_name})
26222622
else()
26232623
set(exe_name $<TARGET_FILE:${tool_name}>)
26242624
set(target_name ${tool_name})
26252625
endif()
2626-
set(${exe_var_name} "${exe_name}" CACHE STRING "")
2627-
set(${target_var_name} "${target_name}" CACHE STRING "")
2626+
# Force setting the cache variable because they are only used for being
2627+
# global in scope. Using regular variables would require careful audit of the
2628+
# code with several parent scope set commands.
2629+
set(${exe_var_name} "${exe_name}" CACHE STRING "" FORCE)
2630+
set(${target_var_name} "${target_name}" CACHE STRING "" FORCE)
26282631
endfunction()
26292632

26302633
function(setup_host_tool tool_name setting_name exe_var_name target_var_name)
26312634
get_host_tool_path(${tool_name} ${setting_name} ${exe_var_name} ${target_var_name})
26322635
# Set up a native tool build if necessary
26332636
if(LLVM_USE_HOST_TOOLS AND NOT ${setting_name})
26342637
build_native_tool(${tool_name} exe_name DEPENDS ${tool_name})
2635-
add_custom_target(${target_var_name} DEPENDS ${exe_name})
2638+
add_custom_target(${${target_var_name}} DEPENDS ${exe_name})
26362639
get_subproject_title(subproject_title)
2637-
set_target_properties(${target_var_name} PROPERTIES FOLDER "${subproject_title}/Native")
2640+
set_target_properties(${${target_var_name}} PROPERTIES FOLDER "${subproject_title}/Native")
26382641
endif()
26392642
endfunction()

mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt

-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ function(add_linalg_ods_yaml_gen yaml_ast_file output_file)
1515
MAIN_DEPENDENCY
1616
${YAML_AST_SOURCE}
1717
DEPENDS
18-
${MLIR_LINALG_ODS_YAML_GEN_EXE}
1918
${MLIR_LINALG_ODS_YAML_GEN_TARGET})
2019
add_custom_target(
2120
MLIR${output_file}YamlIncGen
2221
DEPENDS
23-
${MLIR_LINALG_ODS_YAML_GEN_EXE}
24-
${MLIR_LINALG_ODS_YAML_GEN_TARGET}
2522
${GEN_ODS_FILE} ${GEN_CPP_FILE})
2623
set_target_properties(MLIR${output_file}YamlIncGen PROPERTIES FOLDER "MLIR/Tablegenning")
2724
list(APPEND LLVM_TARGET_DEPENDS ${GEN_ODS_FILE})

0 commit comments

Comments
 (0)