Skip to content

Commit 69ee9b0

Browse files
authored
add cross-compile support (#17)
1 parent f6920fe commit 69ee9b0

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

mlir/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ include_directories(BEFORE
207207
# Adding tools/mlir-tblgen here as calling add_tablegen sets some variables like
208208
# MLIR_TABLEGEN_EXE in PARENT_SCOPE which gets lost if that folder is included
209209
# from another directory like tools
210+
add_subdirectory(tools/mlir-irdl-to-cpp)
210211
add_subdirectory(tools/mlir-linalg-ods-gen)
211212
add_subdirectory(tools/mlir-pdll)
212213
add_subdirectory(tools/mlir-tblgen)

mlir/cmake/modules/IRDLToCpp.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
function(add_irdl_to_cpp_target target irdl_file)
22
add_custom_command(
33
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${irdl_file}.cpp.inc
4-
COMMAND $<TARGET_FILE:mlir-irdl-to-cpp> ${CMAKE_CURRENT_SOURCE_DIR}/${irdl_file} -o ${CMAKE_CURRENT_BINARY_DIR}/${irdl_file}.cpp.inc
5-
DEPENDS mlir-irdl-to-cpp ${irdl_file}
4+
COMMAND ${MLIR_IRDL_TO_CPP_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/${irdl_file} -o ${CMAKE_CURRENT_BINARY_DIR}/${irdl_file}.cpp.inc
5+
DEPENDS ${MLIR_IRDL_TO_CPP_TARGET} ${irdl_file}
66
COMMENT "Building ${irdl_file}..."
77
)
88
add_custom_target(${target} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${irdl_file}.cpp.inc)

mlir/tools/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
add_subdirectory(mlir-irdl-to-cpp)
21
add_subdirectory(mlir-lsp-server)
32
add_subdirectory(mlir-opt)
43
add_subdirectory(mlir-parser-fuzzer)
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1-
add_mlir_tool(mlir-irdl-to-cpp
1+
add_llvm_executable(mlir-irdl-to-cpp
22
mlir-irdl-to-cpp.cpp
33
)
44
mlir_target_link_libraries(mlir-irdl-to-cpp
55
PRIVATE
66
MLIRTargetIRDLToCpp
77
)
8+
9+
# Set up a native build when cross-compiling.
10+
if(LLVM_USE_HOST_TOOLS)
11+
build_native_tool(
12+
mlir-irdl-to-cpp
13+
MLIR_IRDL_TO_CPP_EXE
14+
15+
# Native tool must depend on target tool so that the native tool gets
16+
# properly rebuilt when the target tool changes.
17+
DEPENDS mlir-irdl-to-cpp
18+
)
19+
add_custom_target(mlir-irdl-to-cpp-host DEPENDS ${MLIR_IRDL_TO_CPP_EXE})
20+
set(MLIR_IRDL_TO_CPP_TARGET mlir-irdl-to-cpp-host)
21+
else()
22+
set(MLIR_IRDL_TO_CPP_EXE $<TARGET_FILE:mlir-irdl-to-cpp>)
23+
set(MLIR_IRDL_TO_CPP_TARGET mlir-irdl-to-cpp)
24+
endif()
25+
26+
# Save the executable path and target name to the cache to expose it globally.
27+
set(MLIR_IRDL_TO_CPP_EXE "${MLIR_IRDL_TO_CPP_EXE}" CACHE INTERNAL "")
28+
set(MLIR_IRDL_TO_CPP_TARGET "${MLIR_IRDL_TO_CPP_TARGET}" CACHE INTERNAL "")

0 commit comments

Comments
 (0)