[flang-commits] [flang] [mlir] [mlir][cmake] Do not export MLIR_MAIN_SRC_DIR (PR #125842)

Nikita Popov via flang-commits flang-commits at lists.llvm.org
Thu Feb 6 05:15:15 PST 2025


https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/125842

>From 82d14cdc61cd7c05152454f703ec3bd1daec3900 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Wed, 5 Feb 2025 12:11:38 +0100
Subject: [PATCH 1/2] [mlir][cmake] Do not export MLIR_MAIN_SRC_DIR

MLIR_MAIN_SRC_DIR points to the source directory, which is not
installed. As such, the installed MLIRConfig.cmake also should
not reference it.

The comment indicates that this is needed for mlir_tablegen(),
but I don't see any related uses.

The motivation for this is the use in flang, where we end up
inheriting a meaningless MLIR_MAIN_SRC_DIR from a previous MLIR
build, whose source directory obviously doesn't exist anymore,
and that cannot be overridden with the correct path, because it's
not a cached variable.

Instead do what all the other projects do (for LLVM_MAIN_SRC_DIR)
and initialize MLIR_MAIN_SRC_DIR to CMAKE_CURRENT_SOURCE_DIR/../mlir.
---
 flang/CMakeLists.txt                   | 3 ++-
 mlir/cmake/modules/MLIRConfig.cmake.in | 1 -
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 2e27bc2279ac479..90881adf0c92db8 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -79,6 +79,8 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 4)
   message(FATAL_ERROR "flang isn't supported on 32 bit CPUs")
 endif()
 
+set(MLIR_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../mlir" CACHE PATH "Path to MLIR source tree")
+
 if (FLANG_STANDALONE_BUILD)
   set(FLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
   set(CMAKE_INCLUDE_CURRENT_DIR ON)
@@ -240,7 +242,6 @@ else()
     set(FLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
   endif()
 
-  set(MLIR_MAIN_SRC_DIR ${LLVM_MAIN_SRC_DIR}/../mlir ) # --src-root
   set(MLIR_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include ) # --includedir
   set(MLIR_TABLEGEN_OUTPUT_DIR ${CMAKE_BINARY_DIR}/tools/mlir/include)
   include_directories(SYSTEM ${MLIR_INCLUDE_DIR})
diff --git a/mlir/cmake/modules/MLIRConfig.cmake.in b/mlir/cmake/modules/MLIRConfig.cmake.in
index 7076d94a32f2bcd..c09af1e4eeee9f7 100644
--- a/mlir/cmake/modules/MLIRConfig.cmake.in
+++ b/mlir/cmake/modules/MLIRConfig.cmake.in
@@ -18,7 +18,6 @@ set(MLIR_ENABLE_EXECUTION_ENGINE "@MLIR_ENABLE_EXECUTION_ENGINE@")
 
 # For mlir_tablegen()
 set(MLIR_INCLUDE_DIR "@MLIR_INCLUDE_DIR@")
-set(MLIR_MAIN_SRC_DIR "@MLIR_MAIN_SRC_DIR@")
 
 set_property(GLOBAL PROPERTY MLIR_ALL_LIBS "@MLIR_ALL_LIBS@")
 set_property(GLOBAL PROPERTY MLIR_DIALECT_LIBS "@MLIR_DIALECT_LIBS@")

>From bb0437ee696ab8d1f9fb345721f7c5137ca73644 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 6 Feb 2025 14:04:39 +0100
Subject: [PATCH 2/2] Also drop MLIR_INCLUDE_DIR

---
 flang/CMakeLists.txt                                 | 4 ++--
 flang/include/flang/Optimizer/Dialect/CMakeLists.txt | 2 +-
 mlir/cmake/modules/MLIRConfig.cmake.in               | 3 ---
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 90881adf0c92db8..685d68284eef50e 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -242,9 +242,9 @@ else()
     set(FLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
   endif()
 
-  set(MLIR_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include ) # --includedir
+  set(MLIR_INCLUDE_DIRS ${MLIR_MAIN_SRC_DIR}/include ) # --includedir
   set(MLIR_TABLEGEN_OUTPUT_DIR ${CMAKE_BINARY_DIR}/tools/mlir/include)
-  include_directories(SYSTEM ${MLIR_INCLUDE_DIR})
+  include_directories(SYSTEM ${MLIR_INCLUDE_DIRS})
   include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR})
 endif()
 
diff --git a/flang/include/flang/Optimizer/Dialect/CMakeLists.txt b/flang/include/flang/Optimizer/Dialect/CMakeLists.txt
index 10ab213b30b0270..73f388cbab6c9d9 100644
--- a/flang/include/flang/Optimizer/Dialect/CMakeLists.txt
+++ b/flang/include/flang/Optimizer/Dialect/CMakeLists.txt
@@ -37,7 +37,7 @@ set_target_properties(flang-doc PROPERTIES FOLDER "Flang/Docs")
 set(dialect_doc_filename "FIRLangRef")
 
 set(LLVM_TARGET_DEFINITIONS FIROps.td)
-tablegen(MLIR ${dialect_doc_filename}.md -gen-op-doc "-I${MLIR_INCLUDE_DIR}")
+tablegen(MLIR ${dialect_doc_filename}.md -gen-op-doc)
 set(GEN_DOC_FILE ${FLANG_BINARY_DIR}/docs/Dialect/${dialect_doc_filename}.md)
 add_custom_command(
         OUTPUT ${GEN_DOC_FILE}
diff --git a/mlir/cmake/modules/MLIRConfig.cmake.in b/mlir/cmake/modules/MLIRConfig.cmake.in
index c09af1e4eeee9f7..c695b5787af6685 100644
--- a/mlir/cmake/modules/MLIRConfig.cmake.in
+++ b/mlir/cmake/modules/MLIRConfig.cmake.in
@@ -16,9 +16,6 @@ set(MLIR_INSTALL_AGGREGATE_OBJECTS "@MLIR_INSTALL_AGGREGATE_OBJECTS@")
 set(MLIR_ENABLE_BINDINGS_PYTHON "@MLIR_ENABLE_BINDINGS_PYTHON@")
 set(MLIR_ENABLE_EXECUTION_ENGINE "@MLIR_ENABLE_EXECUTION_ENGINE@")
 
-# For mlir_tablegen()
-set(MLIR_INCLUDE_DIR "@MLIR_INCLUDE_DIR@")
-
 set_property(GLOBAL PROPERTY MLIR_ALL_LIBS "@MLIR_ALL_LIBS@")
 set_property(GLOBAL PROPERTY MLIR_DIALECT_LIBS "@MLIR_DIALECT_LIBS@")
 set_property(GLOBAL PROPERTY MLIR_CONVERSION_LIBS "@MLIR_CONVERSION_LIBS@")



More information about the flang-commits mailing list