llvm-project/mlir/tools/mlir-opt/CMakeLists.txt
Michał Górny 047e8e47c1
Reapply "[mlir] Link libraries that aren't included in libMLIR to libMLIR" (#123910)
Use `mlir_target_link_libraries()` to link dependencies of libraries
that are not included in libMLIR, to ensure that they link to the dylib
when they are used in Flang. Otherwise, they implicitly pull in all
their static dependencies, effectively causing Flang binaries to
simultaneously link to the dylib and to static libraries, which is never
a good idea.

I have only covered the libraries that are used by Flang. If you wish, I
can extend this approach to all non-libMLIR libraries in MLIR, making
MLIR itself also link to the dylib consistently.

[v3 with more `-DBUILD_SHARED_LIBS=ON` fixes]
2025-01-22 09:01:50 +00:00

111 lines
2.3 KiB
CMake

set(LLVM_OPTIONAL_SOURCES
null.cpp
)
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS)
set(LLVM_LINK_COMPONENTS
Core
Support
AsmParser
)
if(MLIR_INCLUDE_TESTS)
set(test_libs
${cuda_test_libs}
MLIRTestFuncToLLVM
MLIRAffineTransformsTestPasses
MLIRArithTestPasses
MLIRArmNeonTestPasses
MLIRArmSMETestPasses
MLIRBufferizationTestPasses
MLIRControlFlowTestPasses
MLIRDLTITestPasses
MLIRFuncTestPasses
MLIRGPUTestPasses
MLIRLinalgTestPasses
MLIRLoopLikeInterfaceTestPasses
MLIRMathTestPasses
MLIRTestMathToVCIX
MLIRMemRefTestPasses
MLIRMeshTest
MLIRNVGPUTestPasses
MLIRSCFTestPasses
MLIRShapeTestPasses
MLIRSPIRVTestPasses
MLIRTensorTestPasses
MLIRTestAnalysis
MLIRTestConvertToSPIRV
MLIRTestDialect
MLIRTestDynDialect
MLIRTestIR
MLIRTestOneToNTypeConversionPass
MLIRTestPass
MLIRTestReducer
MLIRTestTransforms
MLIRTilingInterfaceTestPasses
MLIRTosaTestPasses
MLIRVectorTestPasses
MLIRTestVectorToSPIRV
MLIRLLVMTestPasses
)
set(test_libs ${test_libs}
MLIRTestPDLL
MLIRTestTransformDialect
)
if (MLIR_ENABLE_PDL_IN_PATTERNMATCH)
set(test_libs ${test_libs}
MLIRTestPDLL
MLIRTestRewrite
)
endif()
endif()
set(LIBS
${dialect_libs}
${conversion_libs}
${extension_libs}
MLIRAffineAnalysis
MLIRAnalysis
MLIRCastInterfaces
MLIRDialect
MLIROptLib
MLIRParser
MLIRPass
MLIRTransforms
MLIRTransformUtils
MLIRSupport
MLIRIR
# TODO: Remove when registerAllGPUToLLVMIRTranslations is no longer
# registered directly in mlir-opt.cpp.
MLIRToLLVMIRTranslationRegistration
)
# Exclude from libMLIR.so because this has static options intended for
# opt-like tools only.
add_mlir_library(MLIRMlirOptMain
mlir-opt.cpp
EXCLUDE_FROM_LIBMLIR
)
mlir_target_link_libraries(MLIRMlirOptMain PUBLIC
${LIBS}
${test_libs}
)
add_mlir_tool(mlir-opt
mlir-opt.cpp
SUPPORT_PLUGINS
)
mlir_target_link_libraries(mlir-opt PRIVATE ${LIBS})
target_link_libraries(mlir-opt PRIVATE ${test_libs})
llvm_update_compile_flags(mlir-opt)
mlir_check_all_link_libraries(mlir-opt)
export_executable_symbols_for_plugins(mlir-opt)