[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
Wed Feb 5 03:37:15 PST 2025


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

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 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.

>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] [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@")



More information about the flang-commits mailing list