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

Mehdi Amini via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Sep 7 06:53:36 PDT 2026


https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/221738

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, record MLIR in LLVM_DEPENDENCY_ONLY_PROJECTS unless it is already available. This configures the MLIR targets used by CIR without changing LLVM_ENABLE_PROJECTS or enabling MLIR's aggregate targets.

Keep explicit MLIR selections unchanged and retain the existing standalone ClangIR restriction. Clang builds with CIR disabled continue to omit MLIR.

Assisted-by: Codex

>From 538acace3b8e25b25855ac64ae76c176bcd95fae 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, record MLIR in
LLVM_DEPENDENCY_ONLY_PROJECTS unless it is already available. This configures
the MLIR targets used by CIR without changing LLVM_ENABLE_PROJECTS or enabling
MLIR's aggregate targets.

Keep explicit MLIR selections unchanged and retain the existing standalone
ClangIR restriction. Clang builds with CIR disabled continue to omit MLIR.

Assisted-by: Codex
---
 clang/CMakeLists.txt | 5 +++--
 llvm/CMakeLists.txt  | 7 +++++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index fc71cf45dbb34..9ca77a33c21c2 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -195,9 +195,10 @@ 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 AND
+      NOT "mlir" IN_LIST LLVM_DEPENDENCY_ONLY_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 5552a61466f6d..3c8ae556b387f 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -205,6 +205,13 @@ 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 AND
+    NOT "mlir" IN_LIST LLVM_DEPENDENCY_ONLY_PROJECTS)
+  message(STATUS "Enabling MLIR as a dependency to ClangIR")
+  list(APPEND LLVM_DEPENDENCY_ONLY_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