CMake support for iree::compiler::Dialect
In the Bazel configuration `iree-translate` depends on `"//iree/compiler/Dialect/VM/Target/Bytecode"`. This further pulls in several other dependencies. Right now, the build fails witt
```
[ 96%] Building VMEnums.h.inc...
mlir-tblgen: Unknown command line argument '-gen-iree-vm-op-encoder-defs'. Try: '../../../../../third_party/llvm-project/llvm/bin/mlir-tblgen --help'
mlir-tblgen: Did you mean '--gen-op-interface-defs'?
make[2]: *** [iree/compiler/Dialect/VM/IR/CMakeFiles/iree_compiler_Dialect_VM_IR_IR.dir/build.make:72: iree/compiler/Dialect/VM/IR/VMOpEncoder.cpp.inc] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:29821: iree/compiler/Dialect/VM/IR/CMakeFiles/iree_compiler_Dialect_VM_IR_IR.dir/all] Error 2
make: *** [Makefile:152: all] Error 2
```
This is because `iree-tblgen` has to be run and not `mlir-tblgen`. Within this context I noticed the comment "Runs iree-tablegen to produce some artifacts." in `iree_tablegen_library`. So is there a way to exec `iree-tblgen` instead of `mlir-tblgen` which I have overlooked or is the comment wrong? If the latter is true, do we need *another* `iree_tablegen_library` function which really runs `iree-tblgen` or do somebody sees a simple way how to fix this?
Closes #165
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/iree/pull/165 from marbre:cmake-4 dbacc0aed2aa0de1b540b3fa4de53721f6355963
PiperOrigin-RevId: 284992923
diff --git a/build_tools/cmake/iree_tablegen_library.cmake b/build_tools/cmake/iree_tablegen_library.cmake
index 705e214..55e72e6 100644
--- a/build_tools/cmake/iree_tablegen_library.cmake
+++ b/build_tools/cmake/iree_tablegen_library.cmake
@@ -21,7 +21,7 @@
cmake_parse_arguments(
_RULE
"TESTONLY"
- "NAME"
+ "NAME;TBLGEN"
"SRCS;OUTS"
${ARGN}
)
@@ -31,6 +31,12 @@
iree_package_name(_PACKAGE_NAME)
set(_NAME "${_PACKAGE_NAME}_${_RULE_NAME}")
+ if(${_RULE_TBLGEN} MATCHES "IREE")
+ set(_TBLGEN "IREE")
+ else()
+ set(_TBLGEN "MLIR")
+ endif()
+
set(LLVM_TARGET_DEFINITIONS ${_RULE_SRCS})
set(_INCLUDE_DIRS ${IREE_COMMON_INCLUDE_DIRS})
list(APPEND _INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
@@ -41,7 +47,7 @@
list(REMOVE_AT _RULE_OUTS 0)
list(GET _RULE_OUTS 0 _FILE)
list(REMOVE_AT _RULE_OUTS 0)
- tablegen(MLIR ${_FILE} ${_COMMAND} ${_INCLUDE_DIRS})
+ tablegen(${_TBLGEN} ${_FILE} ${_COMMAND} ${_INCLUDE_DIRS})
list(APPEND _OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/${_FILE})
endwhile()
add_custom_target(${_NAME}_target DEPENDS ${_OUTPUTS})