[Mlir-commits] [mlir] [mlir][cmake] Respect MLIR_TABLEGEN_EXE overrides in MLIRConfig.cmake (PR #189918)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Oct 29 00:11:39 PDT 2026
https://github.com/Acture updated https://github.com/llvm/llvm-project/pull/189918
>From 08f631aac2b6c6a9ab224394ba1658e5150cfe28 Mon Sep 17 00:00:00 2001
From: acture <acturea at gmail.com>
Date: Tue, 29 Jul 2025 00:11:25 +0800
Subject: [PATCH 1/2] [mlir][cmake] Respect MLIR_TABLEGEN_EXE overrides in
MLIRConfig.cmake
MLIRConfig.cmake.in unconditionally overwrites MLIR_TABLEGEN_EXE,
discarding user-provided overrides. For the install tree, it sets the
value to the bare name "mlir-tblgen", which CMake then misinterprets
as a relative file path in add_custom_command(DEPENDS).
This patch:
- Makes MLIR_TABLEGEN_EXE (and siblings) conditional, respecting overrides
- Resolves bare names to full paths via find_program
- Creates an imported mlir-tblgen target as fallback for TableGen.cmake
- Sets MLIR_TABLEGEN_TARGET (never previously exported)
- Removes the previous workaround from flang/CMakeLists.txt
Fixes #150986
---
mlir/cmake/modules/MLIRConfig.cmake.in | 36 +++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/mlir/cmake/modules/MLIRConfig.cmake.in b/mlir/cmake/modules/MLIRConfig.cmake.in
index 4f672a16071053..ad79bb61d27ac2 100644
--- a/mlir/cmake/modules/MLIRConfig.cmake.in
+++ b/mlir/cmake/modules/MLIRConfig.cmake.in
@@ -15,9 +15,16 @@ find_package(LLVM ${LLVM_VERSION} EXACT REQUIRED CONFIG
set(MLIR_EXPORTED_TARGETS "@MLIR_EXPORTS@")
set(MLIR_CMAKE_DIR "@MLIR_CONFIG_CMAKE_DIR@")
set(MLIR_INCLUDE_DIRS "@MLIR_CONFIG_INCLUDE_DIRS@")
-set(MLIR_TABLEGEN_EXE "@MLIR_CONFIG_TABLEGEN_EXE@")
-set(MLIR_PDLL_TABLEGEN_EXE "@MLIR_CONFIG_PDLL_TABLEGEN_EXE@")
-set(MLIR_SRC_SHARDER_TABLEGEN_EXE "@MLIR_CONFIG_SRC_SHARDER_TABLEGEN_EXE@")
+# Allow users to override tablegen executables (e.g. for sandboxed builds).
+if(NOT MLIR_TABLEGEN_EXE)
+ set(MLIR_TABLEGEN_EXE "@MLIR_CONFIG_TABLEGEN_EXE@")
+endif()
+if(NOT MLIR_PDLL_TABLEGEN_EXE)
+ set(MLIR_PDLL_TABLEGEN_EXE "@MLIR_CONFIG_PDLL_TABLEGEN_EXE@")
+endif()
+if(NOT MLIR_SRC_SHARDER_TABLEGEN_EXE)
+ set(MLIR_SRC_SHARDER_TABLEGEN_EXE "@MLIR_CONFIG_SRC_SHARDER_TABLEGEN_EXE@")
+endif()
set(MLIR_IRDL_TO_CPP_EXE "@MLIR_CONFIG_IRDL_TO_CPP_EXE@")
set(MLIR_INSTALL_AGGREGATE_OBJECTS "@MLIR_INSTALL_AGGREGATE_OBJECTS@")
set(MLIR_ENABLE_BINDINGS_PYTHON "@MLIR_ENABLE_BINDINGS_PYTHON@")
@@ -39,6 +46,29 @@ if(NOT TARGET MLIRSupport)
@MLIR_CONFIG_INCLUDE_EXPORTS@
endif()
+# Ensure MLIR_TABLEGEN_EXE is a full path and has a corresponding imported
+# target. In install trees, MLIR_TABLEGEN_EXE may be a bare name
+# ("mlir-tblgen") rather than an absolute path. Resolve it so that
+# TableGen.cmake can use it as both a COMMAND and a DEPENDS entry.
+if(MLIR_TABLEGEN_EXE AND NOT IS_ABSOLUTE "${MLIR_TABLEGEN_EXE}"
+ AND NOT TARGET "${MLIR_TABLEGEN_EXE}")
+ find_program(_mlir_tblgen_exe "${MLIR_TABLEGEN_EXE}"
+ HINTS "${LLVM_TOOLS_BINARY_DIR}")
+ if(_mlir_tblgen_exe)
+ set(MLIR_TABLEGEN_EXE "${_mlir_tblgen_exe}")
+ endif()
+ unset(_mlir_tblgen_exe)
+endif()
+
+if(NOT TARGET mlir-tblgen AND MLIR_TABLEGEN_EXE)
+ add_executable(mlir-tblgen IMPORTED GLOBAL)
+ set_target_properties(mlir-tblgen PROPERTIES
+ IMPORTED_LOCATION "${MLIR_TABLEGEN_EXE}")
+endif()
+if(NOT DEFINED MLIR_TABLEGEN_TARGET)
+ set(MLIR_TABLEGEN_TARGET mlir-tblgen)
+endif()
+
# By creating these targets here, subprojects that depend on MLIR's
# tablegen-generated headers can always depend on these targets whether building
# in-tree with MLIR or not.
>From 3ef2aefc2894d1c89a75d6f4d4d893169d7d4cd9 Mon Sep 17 00:00:00 2001
From: acture <acturea at gmail.com>
Date: Thu, 29 Oct 2026 08:11:29 +0100
Subject: [PATCH 2/2] Update mlir/cmake/modules/MLIRConfig.cmake.in
Co-authored-by: Anutosh Bhat <andersonbhat491 at gmail.com>
---
mlir/cmake/modules/MLIRConfig.cmake.in | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/mlir/cmake/modules/MLIRConfig.cmake.in b/mlir/cmake/modules/MLIRConfig.cmake.in
index ad79bb61d27ac2..26e05e70f5e27b 100644
--- a/mlir/cmake/modules/MLIRConfig.cmake.in
+++ b/mlir/cmake/modules/MLIRConfig.cmake.in
@@ -46,29 +46,21 @@ if(NOT TARGET MLIRSupport)
@MLIR_CONFIG_INCLUDE_EXPORTS@
endif()
-# Ensure MLIR_TABLEGEN_EXE is a full path and has a corresponding imported
-# target. In install trees, MLIR_TABLEGEN_EXE may be a bare name
-# ("mlir-tblgen") rather than an absolute path. Resolve it so that
-# TableGen.cmake can use it as both a COMMAND and a DEPENDS entry.
+# Resolve bare executable names to file paths for TableGen's dependencies.
if(MLIR_TABLEGEN_EXE AND NOT IS_ABSOLUTE "${MLIR_TABLEGEN_EXE}"
AND NOT TARGET "${MLIR_TABLEGEN_EXE}")
+ unset(_mlir_tblgen_exe CACHE)
find_program(_mlir_tblgen_exe "${MLIR_TABLEGEN_EXE}"
HINTS "${LLVM_TOOLS_BINARY_DIR}")
if(_mlir_tblgen_exe)
set(MLIR_TABLEGEN_EXE "${_mlir_tblgen_exe}")
endif()
- unset(_mlir_tblgen_exe)
+ unset(_mlir_tblgen_exe CACHE)
endif()
-if(NOT TARGET mlir-tblgen AND MLIR_TABLEGEN_EXE)
- add_executable(mlir-tblgen IMPORTED GLOBAL)
- set_target_properties(mlir-tblgen PROPERTIES
- IMPORTED_LOCATION "${MLIR_TABLEGEN_EXE}")
-endif()
if(NOT DEFINED MLIR_TABLEGEN_TARGET)
- set(MLIR_TABLEGEN_TARGET mlir-tblgen)
+ set(MLIR_TABLEGEN_TARGET "${MLIR_TABLEGEN_EXE}")
endif()
-
# By creating these targets here, subprojects that depend on MLIR's
# tablegen-generated headers can always depend on these targets whether building
# in-tree with MLIR or not.
More information about the Mlir-commits
mailing list