[llvm-branch-commits] [clang] [llvm] [CIR][CMake] Configure MLIR as a dependency-only project (PR #221739)

Mehdi Amini via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Sep 7 15:02:57 PDT 2026


https://github.com/joker-eph updated https://github.com/llvm/llvm-project/pull/221739

>From 306996404023c2c51606a99a79f95a16093cf451 Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Mon, 7 Sep 2026 06:38:37 -0700
Subject: [PATCH] [CIR][CMake] Configure MLIR as a dependency-only project

ClangIR requires MLIR, but enabling CIR currently requires users to list MLIR
explicitly in LLVM_ENABLE_PROJECTS. That also attaches all MLIR build, install,
unit-test, and lit targets to the corresponding LLVM aggregates.

When Clang is selected and CLANG_ENABLE_CIR is enabled, append MLIR to the
effective LLVM_ENABLE_PROJECTS list. The common project setup compares that
list with the cached user selection, so an explicit MLIR selection retains its
normal behavior while an implicit selection is configured with EXCLUDE_FROM_ALL.

This makes MLIR targets available for CIR dependency resolution without adding
MLIR's aggregate targets. Keep the existing standalone ClangIR restriction and
do not configure MLIR when CIR is disabled.

Validation:
- Configured Clang with CIR and implicit MLIR test support.
- Configured Clang and MLIR explicitly with CIR and tests enabled.
- Configured Clang without CIR and verified that MLIR remains disabled.
- Verified implicit mode omits MLIR unit and lit test-suite targets.
- Verified explicit mode retains check-mlir and MLIRUnitTests.

Assisted-by: Codex
---
 clang/CMakeLists.txt | 4 ++--
 llvm/CMakeLists.txt  | 6 ++++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 6977458da67e9..6e7dbf96fb46d 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -195,9 +195,9 @@ if(CLANG_ENABLE_CIR)
     message(FATAL_ERROR
       "ClangIR is not yet supported in the standalone build.")
   endif()
-  if (NOT "${LLVM_ENABLE_PROJECTS}" MATCHES "MLIR|mlir")
+  if (NOT "mlir" IN_LIST LLVM_ENABLE_PROJECTS)
     message(FATAL_ERROR
-      "Cannot build ClangIR without MLIR in LLVM_ENABLE_PROJECTS")
+      "Cannot build ClangIR without MLIR enabled")
   endif()
 endif()
 
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index b4a99a60b97a5..21adb8f6921de 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -201,6 +201,12 @@ if ("flang" IN_LIST LLVM_ENABLE_PROJECTS)
   endif ()
 endif()
 
+if (CLANG_ENABLE_CIR AND "clang" IN_LIST LLVM_ENABLE_PROJECTS AND
+    NOT "mlir" IN_LIST LLVM_ENABLE_PROJECTS)
+  message(STATUS "Enabling MLIR as a dependency of ClangIR")
+  list(APPEND LLVM_ENABLE_PROJECTS "mlir")
+endif()
+
 if ("lldb" IN_LIST LLVM_ENABLE_PROJECTS)
   if (NOT "clang" IN_LIST LLVM_ENABLE_PROJECTS)
     message(STATUS "Enabling clang as a dependency of lldb")



More information about the llvm-branch-commits mailing list