Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang] Fix standalone builds against installed MLIR #126387

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mgorny
Copy link
Member

@mgorny mgorny commented Feb 8, 2025

  1. Add a new MLIR_DEPS argument group to flang_add_library(), and move MLIR-specific dependencies to that group. These dependencies are added as usual in regular builds, and are skipped in standalone builds, since MLIR targets are not visible there (and were already built and installed).
  2. Fix the value of MLIR_MAIN_SRC_DIR to refer to the current source directory rather than the directory written into MLIR CMake files. The latter refers to the directory used to build the MLIR package, and is no longer valid.
  3. Fix non-dylib friendly linking of LLVMTargetParser in Optimizer unittests.

With these changes, I can run Flang's regression tests, and get only two failures (to be investigated later, both fail on linker errors):

Failed Tests (2):
  Flang :: Driver/exec.f90
  Flang :: Runtime/no-cpp-dep.c

Add a new `MLIR_DEPS` argument group to `flang_add_library()`, and move
MLIR-specific dependencies to that group.  These dependencies are added
as usual in regular builds, and are skipped in standalone builds,
since MLIR targets are not visible there (and were already built
and installed).

With this change, it is possible to perform a standalone build of Flang
ith `-DFLANG_INCLUDE_TESTS=OFF`.  I will address tests separately.
@llvmbot
Copy link
Member

llvmbot commented Feb 8, 2025

@llvm/pr-subscribers-openacc

@llvm/pr-subscribers-flang-fir-hlfir

Author: Michał Górny (mgorny)

Changes

Add a new MLIR_DEPS argument group to flang_add_library(), and move MLIR-specific dependencies to that group. These dependencies are added as usual in regular builds, and are skipped in standalone builds, since MLIR targets are not visible there (and were already built and installed).

With this change, it is possible to perform a standalone build of Flang ith -DFLANG_INCLUDE_TESTS=OFF. I will address tests separately.


Full diff: https://github.com/llvm/llvm-project/pull/126387.diff

15 Files Affected:

  • (modified) flang/cmake/modules/AddFlang.cmake (+4-1)
  • (modified) flang/lib/Frontend/CMakeLists.txt (+5-3)
  • (modified) flang/lib/Lower/CMakeLists.txt (+4-2)
  • (modified) flang/lib/Optimizer/Analysis/CMakeLists.txt (+4-2)
  • (modified) flang/lib/Optimizer/Builder/CMakeLists.txt (+4-2)
  • (modified) flang/lib/Optimizer/Dialect/CMakeLists.txt (+3-1)
  • (modified) flang/lib/Optimizer/Dialect/CUF/Attributes/CMakeLists.txt (+3-1)
  • (modified) flang/lib/Optimizer/Dialect/CUF/CMakeLists.txt (+3-1)
  • (modified) flang/lib/Optimizer/Dialect/Support/CMakeLists.txt (+3-1)
  • (modified) flang/lib/Optimizer/HLFIR/IR/CMakeLists.txt (+3-1)
  • (modified) flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt (+3-1)
  • (modified) flang/lib/Optimizer/OpenACC/CMakeLists.txt (+3-1)
  • (modified) flang/lib/Optimizer/OpenMP/CMakeLists.txt (+3-1)
  • (modified) flang/lib/Optimizer/Support/CMakeLists.txt (+5-3)
  • (modified) flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt (+3-1)
diff --git a/flang/cmake/modules/AddFlang.cmake b/flang/cmake/modules/AddFlang.cmake
index 1f178772067edc7..7406586c5168e94 100644
--- a/flang/cmake/modules/AddFlang.cmake
+++ b/flang/cmake/modules/AddFlang.cmake
@@ -18,7 +18,7 @@ endmacro()
 
 function(add_flang_library name)
   set(options SHARED STATIC INSTALL_WITH_TOOLCHAIN)
-  set(multiValueArgs ADDITIONAL_HEADERS CLANG_LIBS MLIR_LIBS)
+  set(multiValueArgs ADDITIONAL_HEADERS CLANG_LIBS MLIR_LIBS MLIR_DEPS)
   cmake_parse_arguments(ARG
     "${options}"
     ""
@@ -69,6 +69,9 @@ function(add_flang_library name)
   if (ARG_MLIR_LIBS)
     mlir_target_link_libraries(${name} PRIVATE ${ARG_MLIR_LIBS})
   endif()
+  if (ARG_MLIR_DEPS AND NOT FLANG_STANDALONE_BUILD)
+    add_dependencies(${name} ${ARG_MLIR_DEPS})
+  endif()
 
   if (TARGET ${name})
 
diff --git a/flang/lib/Frontend/CMakeLists.txt b/flang/lib/Frontend/CMakeLists.txt
index 81eef2d468d8c63..80d63fca6fb769a 100644
--- a/flang/lib/Frontend/CMakeLists.txt
+++ b/flang/lib/Frontend/CMakeLists.txt
@@ -18,9 +18,6 @@ add_flang_library(flangFrontend
   FIROptCodeGenPassIncGen
   FIROptTransformsPassIncGen
   HLFIRDialect
-  MLIRIR
-  ${dialect_libs}
-  ${extension_libs}
 
   LINK_LIBS
   CUFDialect
@@ -56,6 +53,11 @@ add_flang_library(flangFrontend
   FrontendOpenACC
   FrontendOpenMP
 
+  MLIR_DEPS
+  MLIRIR
+  ${dialect_libs}
+  ${extension_libs}
+
   MLIR_LIBS
   MLIRTransforms
   MLIRBuiltinToLLVMIRTranslation
diff --git a/flang/lib/Lower/CMakeLists.txt b/flang/lib/Lower/CMakeLists.txt
index c9b249781552e31..87dc2a052796abc 100644
--- a/flang/lib/Lower/CMakeLists.txt
+++ b/flang/lib/Lower/CMakeLists.txt
@@ -44,8 +44,6 @@ add_flang_library(FortranLower
   FIRDialect
   FIRTransforms
   HLFIRDialect
-  ${dialect_libs}
-  ${extension_libs}
 
   LINK_LIBS
   CUFAttrs
@@ -64,6 +62,10 @@ add_flang_library(FortranLower
   LINK_COMPONENTS
   Support
 
+  MLIR_DEPS
+  ${dialect_libs}
+  ${extension_libs}
+
   MLIR_LIBS
   ${dialect_libs}
   ${extension_libs}
diff --git a/flang/lib/Optimizer/Analysis/CMakeLists.txt b/flang/lib/Optimizer/Analysis/CMakeLists.txt
index c4dae898f8e5722..4d4ad882c27d374 100644
--- a/flang/lib/Optimizer/Analysis/CMakeLists.txt
+++ b/flang/lib/Optimizer/Analysis/CMakeLists.txt
@@ -6,8 +6,6 @@ add_flang_library(FIRAnalysis
   FIRDialect
   FIRSupport
   HLFIRDialect
-  MLIRIR
-  MLIROpenMPDialect
 
   LINK_LIBS
   FIRBuilder
@@ -15,6 +13,10 @@ add_flang_library(FIRAnalysis
   FIRSupport
   HLFIRDialect
 
+  MLIR_DEPS
+  MLIRIR
+  MLIROpenMPDialect
+
   MLIR_LIBS
   MLIRFuncDialect
   MLIRLLVMDialect
diff --git a/flang/lib/Optimizer/Builder/CMakeLists.txt b/flang/lib/Optimizer/Builder/CMakeLists.txt
index f8faeaa81c90cd2..f0563d092e3dc62 100644
--- a/flang/lib/Optimizer/Builder/CMakeLists.txt
+++ b/flang/lib/Optimizer/Builder/CMakeLists.txt
@@ -40,8 +40,6 @@ add_flang_library(FIRBuilder
   CUFDialect
   FIRDialect
   HLFIRDialect
-  ${dialect_libs}
-  ${extension_libs}
 
   LINK_LIBS
   CUFAttrs
@@ -52,6 +50,10 @@ add_flang_library(FIRBuilder
   FortranEvaluate
   HLFIRDialect
 
+  MLIR_DEPS
+  ${dialect_libs}
+  ${extension_libs}
+
   MLIR_LIBS
   ${dialect_libs}
   ${extension_libs}
diff --git a/flang/lib/Optimizer/Dialect/CMakeLists.txt b/flang/lib/Optimizer/Dialect/CMakeLists.txt
index d39dca8ed0000bb..61f9c6110491e09 100644
--- a/flang/lib/Optimizer/Dialect/CMakeLists.txt
+++ b/flang/lib/Optimizer/Dialect/CMakeLists.txt
@@ -12,7 +12,6 @@ add_flang_library(FIRDialect
 
   DEPENDS
   CanonicalizationPatternsIncGen
-  MLIRIR
   FIROpsIncGen
   CUFAttrsIncGen
   intrinsics_gen
@@ -26,6 +25,9 @@ add_flang_library(FIRDialect
   AsmPrinter
   Remarks
 
+  MLIR_DEPS
+  MLIRIR
+
   MLIR_LIBS
   MLIRArithDialect
   MLIRBuiltinToLLVMIRTranslation
diff --git a/flang/lib/Optimizer/Dialect/CUF/Attributes/CMakeLists.txt b/flang/lib/Optimizer/Dialect/CUF/Attributes/CMakeLists.txt
index a0f58504eff05d2..713bd0e97bac311 100644
--- a/flang/lib/Optimizer/Dialect/CUF/Attributes/CMakeLists.txt
+++ b/flang/lib/Optimizer/Dialect/CUF/Attributes/CMakeLists.txt
@@ -3,7 +3,6 @@ add_flang_library(CUFAttrs
   CUFAttr.cpp
 
   DEPENDS
-  MLIRIR
   CUFAttrsIncGen
   CUFOpsIncGen
 
@@ -12,6 +11,9 @@ add_flang_library(CUFAttrs
   AsmPrinter
   Remarks
 
+  MLIR_DEPS
+  MLIRIR
+
   MLIR_LIBS
   MLIRTargetLLVMIRExport
 )
diff --git a/flang/lib/Optimizer/Dialect/CUF/CMakeLists.txt b/flang/lib/Optimizer/Dialect/CUF/CMakeLists.txt
index e483b4a1641130c..5b398f2ad506aea 100644
--- a/flang/lib/Optimizer/Dialect/CUF/CMakeLists.txt
+++ b/flang/lib/Optimizer/Dialect/CUF/CMakeLists.txt
@@ -6,7 +6,6 @@ add_flang_library(CUFDialect
   CUFToLLVMIRTranslation.cpp
 
   DEPENDS
-  MLIRIR
   CUFAttrsIncGen
   CUFOpsIncGen
 
@@ -20,6 +19,9 @@ add_flang_library(CUFDialect
   AsmPrinter
   Remarks
 
+  MLIR_DEPS
+  MLIRIR
+
   MLIR_LIBS
   MLIRIR
   MLIRGPUDialect
diff --git a/flang/lib/Optimizer/Dialect/Support/CMakeLists.txt b/flang/lib/Optimizer/Dialect/Support/CMakeLists.txt
index bfdd5279b6f293b..a85d9521af1c447 100644
--- a/flang/lib/Optimizer/Dialect/Support/CMakeLists.txt
+++ b/flang/lib/Optimizer/Dialect/Support/CMakeLists.txt
@@ -5,9 +5,11 @@ add_flang_library(FIRDialectSupport
   FIRContext.cpp
 
   DEPENDS
-  MLIRIR
   intrinsics_gen
 
+  MLIR_DEPS
+  MLIRIR
+
   MLIR_LIBS
   ${dialect_libs}
 )
diff --git a/flang/lib/Optimizer/HLFIR/IR/CMakeLists.txt b/flang/lib/Optimizer/HLFIR/IR/CMakeLists.txt
index 8a646bedf94b840..99e31a43e01e50b 100644
--- a/flang/lib/Optimizer/HLFIR/IR/CMakeLists.txt
+++ b/flang/lib/Optimizer/HLFIR/IR/CMakeLists.txt
@@ -8,7 +8,6 @@ add_flang_library(HLFIRDialect
   CUFAttrsIncGen
   FIRDialect
   HLFIROpsIncGen
-  ${dialect_libs}
 
   LINK_LIBS
   CUFAttrs
@@ -19,6 +18,9 @@ add_flang_library(HLFIRDialect
   AsmPrinter
   Remarks
 
+  MLIR_DEPS
+  ${dialect_libs}
+
   MLIR_LIBS
   MLIRIR
   ${dialect_libs}
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt b/flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt
index 09286aced608909..7eb3cb4001d5fdf 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt
@@ -15,7 +15,6 @@ add_flang_library(HLFIRTransforms
   CUFAttrsIncGen
   FIRDialect
   HLFIROpsIncGen
-  ${dialect_libs}
 
   LINK_LIBS
   CUFAttrs
@@ -33,6 +32,9 @@ add_flang_library(HLFIRTransforms
   AsmPrinter
   Remarks
 
+  MLIR_DEPS
+  ${dialect_libs}
+
   MLIR_LIBS
   MLIRIR
   ${dialect_libs}
diff --git a/flang/lib/Optimizer/OpenACC/CMakeLists.txt b/flang/lib/Optimizer/OpenACC/CMakeLists.txt
index 04d351ac265d638..56f625aa0f44142 100644
--- a/flang/lib/Optimizer/OpenACC/CMakeLists.txt
+++ b/flang/lib/Optimizer/OpenACC/CMakeLists.txt
@@ -10,7 +10,6 @@ add_flang_library(FIROpenACCSupport
   FIRDialectSupport
   FIRSupport
   HLFIRDialect
-  MLIROpenACCDialect
 
   LINK_LIBS
   FIRBuilder
@@ -19,6 +18,9 @@ add_flang_library(FIROpenACCSupport
   FIRSupport
   HLFIRDialect
 
+  MLIR_DEPS
+  MLIROpenACCDialect
+
   MLIR_LIBS
   MLIROpenACCDialect
 )
diff --git a/flang/lib/Optimizer/OpenMP/CMakeLists.txt b/flang/lib/Optimizer/OpenMP/CMakeLists.txt
index 86ae93f3207cc3d..4a48d6e0936db0d 100644
--- a/flang/lib/Optimizer/OpenMP/CMakeLists.txt
+++ b/flang/lib/Optimizer/OpenMP/CMakeLists.txt
@@ -12,7 +12,6 @@ add_flang_library(FlangOpenMPTransforms
   FIRDialect
   HLFIROpsIncGen
   FlangOpenMPPassesIncGen
-  ${dialect_libs}
 
   LINK_LIBS
   FIRAnalysis
@@ -24,6 +23,9 @@ add_flang_library(FlangOpenMPTransforms
   FortranSupport
   HLFIRDialect
 
+  MLIR_DEPS
+  ${dialect_libs}
+
   MLIR_LIBS
   MLIRFuncDialect
   MLIROpenMPDialect
diff --git a/flang/lib/Optimizer/Support/CMakeLists.txt b/flang/lib/Optimizer/Support/CMakeLists.txt
index f8e4fc5bcefea43..7ccdd4fd9c25ca1 100644
--- a/flang/lib/Optimizer/Support/CMakeLists.txt
+++ b/flang/lib/Optimizer/Support/CMakeLists.txt
@@ -10,9 +10,6 @@ add_flang_library(FIRSupport
   DEPENDS
   FIROpsIncGen
   HLFIROpsIncGen
-  MLIRIR
-  ${dialect_libs}
-  ${extension_libs}
 
   LINK_LIBS
   FIRDialect
@@ -20,6 +17,11 @@ add_flang_library(FIRSupport
   LINK_COMPONENTS
   TargetParser
 
+  MLIR_DEPS
+  MLIRIR
+  ${dialect_libs}
+  ${extension_libs}
+
   MLIR_LIBS
   ${dialect_libs}
   ${extension_libs}
diff --git a/flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt b/flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt
index cba47a41145171c..16df2b607ca931e 100644
--- a/flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt
+++ b/flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt
@@ -8,7 +8,6 @@ add_flang_library(FIRTestAnalysis
   FIRSupport
   FIRTransforms
   FIRAnalysis
-  ${dialect_libs}
 
   LINK_LIBS
   FIRDialect
@@ -18,6 +17,9 @@ add_flang_library(FIRTestAnalysis
   FIRAnalysis
   MLIRTestAnalysis
 
+  MLIR_DEPS
+  ${dialect_libs}
+
   MLIR_LIBS
   ${dialect_libs}
   MLIRFuncDialect

@llvmbot
Copy link
Member

llvmbot commented Feb 8, 2025

@llvm/pr-subscribers-flang-driver

Author: Michał Górny (mgorny)

Changes

Add a new MLIR_DEPS argument group to flang_add_library(), and move MLIR-specific dependencies to that group. These dependencies are added as usual in regular builds, and are skipped in standalone builds, since MLIR targets are not visible there (and were already built and installed).

With this change, it is possible to perform a standalone build of Flang ith -DFLANG_INCLUDE_TESTS=OFF. I will address tests separately.


Full diff: https://github.com/llvm/llvm-project/pull/126387.diff

15 Files Affected:

  • (modified) flang/cmake/modules/AddFlang.cmake (+4-1)
  • (modified) flang/lib/Frontend/CMakeLists.txt (+5-3)
  • (modified) flang/lib/Lower/CMakeLists.txt (+4-2)
  • (modified) flang/lib/Optimizer/Analysis/CMakeLists.txt (+4-2)
  • (modified) flang/lib/Optimizer/Builder/CMakeLists.txt (+4-2)
  • (modified) flang/lib/Optimizer/Dialect/CMakeLists.txt (+3-1)
  • (modified) flang/lib/Optimizer/Dialect/CUF/Attributes/CMakeLists.txt (+3-1)
  • (modified) flang/lib/Optimizer/Dialect/CUF/CMakeLists.txt (+3-1)
  • (modified) flang/lib/Optimizer/Dialect/Support/CMakeLists.txt (+3-1)
  • (modified) flang/lib/Optimizer/HLFIR/IR/CMakeLists.txt (+3-1)
  • (modified) flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt (+3-1)
  • (modified) flang/lib/Optimizer/OpenACC/CMakeLists.txt (+3-1)
  • (modified) flang/lib/Optimizer/OpenMP/CMakeLists.txt (+3-1)
  • (modified) flang/lib/Optimizer/Support/CMakeLists.txt (+5-3)
  • (modified) flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt (+3-1)
diff --git a/flang/cmake/modules/AddFlang.cmake b/flang/cmake/modules/AddFlang.cmake
index 1f178772067edc7..7406586c5168e94 100644
--- a/flang/cmake/modules/AddFlang.cmake
+++ b/flang/cmake/modules/AddFlang.cmake
@@ -18,7 +18,7 @@ endmacro()
 
 function(add_flang_library name)
   set(options SHARED STATIC INSTALL_WITH_TOOLCHAIN)
-  set(multiValueArgs ADDITIONAL_HEADERS CLANG_LIBS MLIR_LIBS)
+  set(multiValueArgs ADDITIONAL_HEADERS CLANG_LIBS MLIR_LIBS MLIR_DEPS)
   cmake_parse_arguments(ARG
     "${options}"
     ""
@@ -69,6 +69,9 @@ function(add_flang_library name)
   if (ARG_MLIR_LIBS)
     mlir_target_link_libraries(${name} PRIVATE ${ARG_MLIR_LIBS})
   endif()
+  if (ARG_MLIR_DEPS AND NOT FLANG_STANDALONE_BUILD)
+    add_dependencies(${name} ${ARG_MLIR_DEPS})
+  endif()
 
   if (TARGET ${name})
 
diff --git a/flang/lib/Frontend/CMakeLists.txt b/flang/lib/Frontend/CMakeLists.txt
index 81eef2d468d8c63..80d63fca6fb769a 100644
--- a/flang/lib/Frontend/CMakeLists.txt
+++ b/flang/lib/Frontend/CMakeLists.txt
@@ -18,9 +18,6 @@ add_flang_library(flangFrontend
   FIROptCodeGenPassIncGen
   FIROptTransformsPassIncGen
   HLFIRDialect
-  MLIRIR
-  ${dialect_libs}
-  ${extension_libs}
 
   LINK_LIBS
   CUFDialect
@@ -56,6 +53,11 @@ add_flang_library(flangFrontend
   FrontendOpenACC
   FrontendOpenMP
 
+  MLIR_DEPS
+  MLIRIR
+  ${dialect_libs}
+  ${extension_libs}
+
   MLIR_LIBS
   MLIRTransforms
   MLIRBuiltinToLLVMIRTranslation
diff --git a/flang/lib/Lower/CMakeLists.txt b/flang/lib/Lower/CMakeLists.txt
index c9b249781552e31..87dc2a052796abc 100644
--- a/flang/lib/Lower/CMakeLists.txt
+++ b/flang/lib/Lower/CMakeLists.txt
@@ -44,8 +44,6 @@ add_flang_library(FortranLower
   FIRDialect
   FIRTransforms
   HLFIRDialect
-  ${dialect_libs}
-  ${extension_libs}
 
   LINK_LIBS
   CUFAttrs
@@ -64,6 +62,10 @@ add_flang_library(FortranLower
   LINK_COMPONENTS
   Support
 
+  MLIR_DEPS
+  ${dialect_libs}
+  ${extension_libs}
+
   MLIR_LIBS
   ${dialect_libs}
   ${extension_libs}
diff --git a/flang/lib/Optimizer/Analysis/CMakeLists.txt b/flang/lib/Optimizer/Analysis/CMakeLists.txt
index c4dae898f8e5722..4d4ad882c27d374 100644
--- a/flang/lib/Optimizer/Analysis/CMakeLists.txt
+++ b/flang/lib/Optimizer/Analysis/CMakeLists.txt
@@ -6,8 +6,6 @@ add_flang_library(FIRAnalysis
   FIRDialect
   FIRSupport
   HLFIRDialect
-  MLIRIR
-  MLIROpenMPDialect
 
   LINK_LIBS
   FIRBuilder
@@ -15,6 +13,10 @@ add_flang_library(FIRAnalysis
   FIRSupport
   HLFIRDialect
 
+  MLIR_DEPS
+  MLIRIR
+  MLIROpenMPDialect
+
   MLIR_LIBS
   MLIRFuncDialect
   MLIRLLVMDialect
diff --git a/flang/lib/Optimizer/Builder/CMakeLists.txt b/flang/lib/Optimizer/Builder/CMakeLists.txt
index f8faeaa81c90cd2..f0563d092e3dc62 100644
--- a/flang/lib/Optimizer/Builder/CMakeLists.txt
+++ b/flang/lib/Optimizer/Builder/CMakeLists.txt
@@ -40,8 +40,6 @@ add_flang_library(FIRBuilder
   CUFDialect
   FIRDialect
   HLFIRDialect
-  ${dialect_libs}
-  ${extension_libs}
 
   LINK_LIBS
   CUFAttrs
@@ -52,6 +50,10 @@ add_flang_library(FIRBuilder
   FortranEvaluate
   HLFIRDialect
 
+  MLIR_DEPS
+  ${dialect_libs}
+  ${extension_libs}
+
   MLIR_LIBS
   ${dialect_libs}
   ${extension_libs}
diff --git a/flang/lib/Optimizer/Dialect/CMakeLists.txt b/flang/lib/Optimizer/Dialect/CMakeLists.txt
index d39dca8ed0000bb..61f9c6110491e09 100644
--- a/flang/lib/Optimizer/Dialect/CMakeLists.txt
+++ b/flang/lib/Optimizer/Dialect/CMakeLists.txt
@@ -12,7 +12,6 @@ add_flang_library(FIRDialect
 
   DEPENDS
   CanonicalizationPatternsIncGen
-  MLIRIR
   FIROpsIncGen
   CUFAttrsIncGen
   intrinsics_gen
@@ -26,6 +25,9 @@ add_flang_library(FIRDialect
   AsmPrinter
   Remarks
 
+  MLIR_DEPS
+  MLIRIR
+
   MLIR_LIBS
   MLIRArithDialect
   MLIRBuiltinToLLVMIRTranslation
diff --git a/flang/lib/Optimizer/Dialect/CUF/Attributes/CMakeLists.txt b/flang/lib/Optimizer/Dialect/CUF/Attributes/CMakeLists.txt
index a0f58504eff05d2..713bd0e97bac311 100644
--- a/flang/lib/Optimizer/Dialect/CUF/Attributes/CMakeLists.txt
+++ b/flang/lib/Optimizer/Dialect/CUF/Attributes/CMakeLists.txt
@@ -3,7 +3,6 @@ add_flang_library(CUFAttrs
   CUFAttr.cpp
 
   DEPENDS
-  MLIRIR
   CUFAttrsIncGen
   CUFOpsIncGen
 
@@ -12,6 +11,9 @@ add_flang_library(CUFAttrs
   AsmPrinter
   Remarks
 
+  MLIR_DEPS
+  MLIRIR
+
   MLIR_LIBS
   MLIRTargetLLVMIRExport
 )
diff --git a/flang/lib/Optimizer/Dialect/CUF/CMakeLists.txt b/flang/lib/Optimizer/Dialect/CUF/CMakeLists.txt
index e483b4a1641130c..5b398f2ad506aea 100644
--- a/flang/lib/Optimizer/Dialect/CUF/CMakeLists.txt
+++ b/flang/lib/Optimizer/Dialect/CUF/CMakeLists.txt
@@ -6,7 +6,6 @@ add_flang_library(CUFDialect
   CUFToLLVMIRTranslation.cpp
 
   DEPENDS
-  MLIRIR
   CUFAttrsIncGen
   CUFOpsIncGen
 
@@ -20,6 +19,9 @@ add_flang_library(CUFDialect
   AsmPrinter
   Remarks
 
+  MLIR_DEPS
+  MLIRIR
+
   MLIR_LIBS
   MLIRIR
   MLIRGPUDialect
diff --git a/flang/lib/Optimizer/Dialect/Support/CMakeLists.txt b/flang/lib/Optimizer/Dialect/Support/CMakeLists.txt
index bfdd5279b6f293b..a85d9521af1c447 100644
--- a/flang/lib/Optimizer/Dialect/Support/CMakeLists.txt
+++ b/flang/lib/Optimizer/Dialect/Support/CMakeLists.txt
@@ -5,9 +5,11 @@ add_flang_library(FIRDialectSupport
   FIRContext.cpp
 
   DEPENDS
-  MLIRIR
   intrinsics_gen
 
+  MLIR_DEPS
+  MLIRIR
+
   MLIR_LIBS
   ${dialect_libs}
 )
diff --git a/flang/lib/Optimizer/HLFIR/IR/CMakeLists.txt b/flang/lib/Optimizer/HLFIR/IR/CMakeLists.txt
index 8a646bedf94b840..99e31a43e01e50b 100644
--- a/flang/lib/Optimizer/HLFIR/IR/CMakeLists.txt
+++ b/flang/lib/Optimizer/HLFIR/IR/CMakeLists.txt
@@ -8,7 +8,6 @@ add_flang_library(HLFIRDialect
   CUFAttrsIncGen
   FIRDialect
   HLFIROpsIncGen
-  ${dialect_libs}
 
   LINK_LIBS
   CUFAttrs
@@ -19,6 +18,9 @@ add_flang_library(HLFIRDialect
   AsmPrinter
   Remarks
 
+  MLIR_DEPS
+  ${dialect_libs}
+
   MLIR_LIBS
   MLIRIR
   ${dialect_libs}
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt b/flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt
index 09286aced608909..7eb3cb4001d5fdf 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt
@@ -15,7 +15,6 @@ add_flang_library(HLFIRTransforms
   CUFAttrsIncGen
   FIRDialect
   HLFIROpsIncGen
-  ${dialect_libs}
 
   LINK_LIBS
   CUFAttrs
@@ -33,6 +32,9 @@ add_flang_library(HLFIRTransforms
   AsmPrinter
   Remarks
 
+  MLIR_DEPS
+  ${dialect_libs}
+
   MLIR_LIBS
   MLIRIR
   ${dialect_libs}
diff --git a/flang/lib/Optimizer/OpenACC/CMakeLists.txt b/flang/lib/Optimizer/OpenACC/CMakeLists.txt
index 04d351ac265d638..56f625aa0f44142 100644
--- a/flang/lib/Optimizer/OpenACC/CMakeLists.txt
+++ b/flang/lib/Optimizer/OpenACC/CMakeLists.txt
@@ -10,7 +10,6 @@ add_flang_library(FIROpenACCSupport
   FIRDialectSupport
   FIRSupport
   HLFIRDialect
-  MLIROpenACCDialect
 
   LINK_LIBS
   FIRBuilder
@@ -19,6 +18,9 @@ add_flang_library(FIROpenACCSupport
   FIRSupport
   HLFIRDialect
 
+  MLIR_DEPS
+  MLIROpenACCDialect
+
   MLIR_LIBS
   MLIROpenACCDialect
 )
diff --git a/flang/lib/Optimizer/OpenMP/CMakeLists.txt b/flang/lib/Optimizer/OpenMP/CMakeLists.txt
index 86ae93f3207cc3d..4a48d6e0936db0d 100644
--- a/flang/lib/Optimizer/OpenMP/CMakeLists.txt
+++ b/flang/lib/Optimizer/OpenMP/CMakeLists.txt
@@ -12,7 +12,6 @@ add_flang_library(FlangOpenMPTransforms
   FIRDialect
   HLFIROpsIncGen
   FlangOpenMPPassesIncGen
-  ${dialect_libs}
 
   LINK_LIBS
   FIRAnalysis
@@ -24,6 +23,9 @@ add_flang_library(FlangOpenMPTransforms
   FortranSupport
   HLFIRDialect
 
+  MLIR_DEPS
+  ${dialect_libs}
+
   MLIR_LIBS
   MLIRFuncDialect
   MLIROpenMPDialect
diff --git a/flang/lib/Optimizer/Support/CMakeLists.txt b/flang/lib/Optimizer/Support/CMakeLists.txt
index f8e4fc5bcefea43..7ccdd4fd9c25ca1 100644
--- a/flang/lib/Optimizer/Support/CMakeLists.txt
+++ b/flang/lib/Optimizer/Support/CMakeLists.txt
@@ -10,9 +10,6 @@ add_flang_library(FIRSupport
   DEPENDS
   FIROpsIncGen
   HLFIROpsIncGen
-  MLIRIR
-  ${dialect_libs}
-  ${extension_libs}
 
   LINK_LIBS
   FIRDialect
@@ -20,6 +17,11 @@ add_flang_library(FIRSupport
   LINK_COMPONENTS
   TargetParser
 
+  MLIR_DEPS
+  MLIRIR
+  ${dialect_libs}
+  ${extension_libs}
+
   MLIR_LIBS
   ${dialect_libs}
   ${extension_libs}
diff --git a/flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt b/flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt
index cba47a41145171c..16df2b607ca931e 100644
--- a/flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt
+++ b/flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt
@@ -8,7 +8,6 @@ add_flang_library(FIRTestAnalysis
   FIRSupport
   FIRTransforms
   FIRAnalysis
-  ${dialect_libs}
 
   LINK_LIBS
   FIRDialect
@@ -18,6 +17,9 @@ add_flang_library(FIRTestAnalysis
   FIRAnalysis
   MLIRTestAnalysis
 
+  MLIR_DEPS
+  ${dialect_libs}
+
   MLIR_LIBS
   ${dialect_libs}
   MLIRFuncDialect

Skip test dependencies on targets from other LLVM projects when
performing a standalone build, to fix missing target errors.  This patch
makes it possible to run CMake with `-DFLANG_INCLUDE_TESTS=ON`
when building standalone.
Set `MLIR_MAIN_SRC_DIR` in standalone builds relatively to the current
source directory, rather than relying on the value embedded
in the installed CMake files.  The latter refers to the directory used
to build the MLIR package, and is no longer correct after it is
installed.
@mgorny mgorny changed the title [flang] Skip MLIR target dependencies in standalone builds [flang] Fix full-fledged standalone builds Feb 9, 2025
@mgorny mgorny marked this pull request as draft February 9, 2025 13:09
@mgorny
Copy link
Member Author

mgorny commented Feb 9, 2025

I'm going to try including all changes necessary to make standalone builds work 100% for us.

@mgorny mgorny changed the title [flang] Fix full-fledged standalone builds [flang] Fix standalone builds against installed MLIR Feb 9, 2025
@mgorny mgorny marked this pull request as ready for review February 9, 2025 15:20
@mgorny
Copy link
Member Author

mgorny commented Feb 9, 2025

With these changes, I am able to successfully build Flang and run its regression tests.

@mgorny mgorny requested a review from vzakhari February 12, 2025 18:03
@mgorny
Copy link
Member Author

mgorny commented Feb 12, 2025

The test failures were fixed by #126920.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:driver flang:fir-hlfir flang Flang issues not falling into any other category openacc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants