In downstream (e.g., Nix-based) builds of Flang, explicitly setting MLIR_TABLEGEN_EXE is ignored due to MLIRConfig.cmake redefining the mlir-tblgen target.
This causes build failures such as:
ninja: error: 'include/flang/Optimizer/Dialect/CUF/Attributes/mlir-tblgen', needed by '.../CUFEnumAttr.h.inc', missing and no known rule to make it
Root cause:
TableGen.cmake expects mlir-tblgen to already be defined. But MLIRConfig overwrites the target, causing CMake to misresolve the executable.
Proposed fix:
Define a dummy imported target (mlir-tblgen and MLIR-TBLGen) early in flang/CMakeLists.txt if not already defined. This prevents accidental overwriting.
As shown in #150987
See attached PR for the patch.
Related:
• Previous Nixpkgs PR encountering this
• My downstream patch discussion
Would appreciate feedback on whether this is an appropriate fix or if a deeper MLIR-side solution is needed.