diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt index e6de8df5cef15..1fc033a10e628 100644 --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -228,6 +228,11 @@ if (FLANG_STANDALONE_BUILD) add_custom_target(doxygen ALL) endif() + # Override the value from installed CMake files, as they refer + # to the directory used during the original MLIR package build, + # which may be no longer available. Instead, use the current checkout. + set(MLIR_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../mlir ) + else() option(FLANG_INCLUDE_TESTS "Generate build targets for the Flang unit tests." diff --git a/flang/cmake/modules/AddFlang.cmake b/flang/cmake/modules/AddFlang.cmake index 1f178772067ed..7406586c5168e 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 81eef2d468d8c..80d63fca6fb76 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 c9b249781552e..87dc2a052796a 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 c4dae898f8e57..4d4ad882c27d3 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 f8faeaa81c90c..f0563d092e3dc 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 d39dca8ed0000..61f9c6110491e 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 a0f58504eff05..713bd0e97bac3 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 e483b4a164113..5b398f2ad506a 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 bfdd5279b6f29..a85d9521af1c4 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 8a646bedf94b8..99e31a43e01e5 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 09286aced6089..7eb3cb4001d5f 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 04d351ac265d6..56f625aa0f441 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 86ae93f3207cc..4a48d6e0936db 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 f8e4fc5bcefea..7ccdd4fd9c25c 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/CMakeLists.txt b/flang/test/CMakeLists.txt index e398e0786147a..f0d4f54b71092 100644 --- a/flang/test/CMakeLists.txt +++ b/flang/test/CMakeLists.txt @@ -59,26 +59,30 @@ set(FLANG_TEST_PARAMS set(FLANG_TEST_DEPENDS flang - llvm-config - FileCheck - count - not module_files fir-opt tco bbc - llvm-dis - llvm-objdump - llvm-readobj - split-file FortranDecimal ) +if (NOT FLANG_STANDALONE_BUILD) + list(APPEND FLANG_TEST_DEPENDS + llvm-config + FileCheck + count + not + llvm-dis + llvm-objdump + llvm-readobj + split-file + ) +endif () if (FLANG_INCLUDE_RUNTIME) list(APPEND FLANG_TEST_DEPENDS FortranRuntime) endif () -if (LLVM_ENABLE_PLUGINS AND NOT WIN32) +if (LLVM_ENABLE_PLUGINS AND NOT WIN32 AND NOT FLANG_STANDALONE_BUILD) list(APPEND FLANG_TEST_DEPENDS Bye) endif() diff --git a/flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt b/flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt index cba47a4114517..16df2b607ca93 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 diff --git a/flang/test/lib/OpenACC/CMakeLists.txt b/flang/test/lib/OpenACC/CMakeLists.txt index e296827ef53be..1c0ac748f85e8 100644 --- a/flang/test/lib/OpenACC/CMakeLists.txt +++ b/flang/test/lib/OpenACC/CMakeLists.txt @@ -5,16 +5,18 @@ add_flang_library(FIRTestOpenACCInterfaces FIRDialect FIROpenACCSupport FIRSupport - MLIRIR - MLIROpenACCDialect - MLIRPass - MLIRSupport LINK_LIBS FIRDialect FIROpenACCSupport FIRSupport + MLIR_DEPS + MLIRIR + MLIROpenACCDialect + MLIRPass + MLIRSupport + MLIR_LIBS MLIRIR MLIROpenACCDialect diff --git a/flang/unittests/Optimizer/CMakeLists.txt b/flang/unittests/Optimizer/CMakeLists.txt index f535677c19fd2..1289341619118 100644 --- a/flang/unittests/Optimizer/CMakeLists.txt +++ b/flang/unittests/Optimizer/CMakeLists.txt @@ -1,6 +1,10 @@ get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS) +set(LLVM_LINK_COMPONENTS + TargetParser +) + set(LIBS CUFDialect FIRBuilder @@ -9,7 +13,6 @@ set(LIBS FIRDialectSupport FIRSupport HLFIRDialect - LLVMTargetParser ) add_flang_unittest(FlangOptimizerTests @@ -39,8 +42,12 @@ DEPENDS CUFDialect FIRDialect FIRSupport - HLFIRDialect - ${dialect_libs}) + HLFIRDialect) + +if(NOT FLANG_STANDALONE_BUILD) + add_dependencies(FlangOptimizerTests + ${dialect_libs}) +endif() target_link_libraries(FlangOptimizerTests PRIVATE