Skip to content

Commit bc0a0ef

Browse files
committed
[mlir] Link libraries that aren't included in libMLIR to libMLIR
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.
1 parent fcedf98 commit bc0a0ef

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

mlir/test/lib/Analysis/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ add_mlir_library(MLIRTestAnalysis
2121
EXCLUDE_FROM_LIBMLIR
2222

2323
LINK_LIBS PUBLIC
24+
MLIRTestDialect
25+
)
26+
27+
# Since this library is excluded from libMLIR, link it to the dylib
28+
# to ensure that it can be used in flang without implicitly pulling in
29+
# static libraries.
30+
mlir_target_link_libraries(MLIRTestAnalysis PUBLIC
2431
MLIRAffineDialect
2532
MLIRAnalysis
2633
MLIRFunctionInterfaces
2734
MLIRMemRefDialect
2835
MLIRPass
29-
MLIRTestDialect
3036
)
3137

3238
target_include_directories(MLIRTestAnalysis

mlir/test/lib/Dialect/Test/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@ add_mlir_library(MLIRTestDialect
6868
MLIRTestOpsIncGen
6969
MLIRTestOpsSyntaxIncGen
7070
MLIRTestOpsShardGen
71+
)
7172

72-
LINK_LIBS PUBLIC
73+
# Since this library is excluded from libMLIR, link it to the dylib
74+
# to ensure that it can be used in flang without implicitly pulling in
75+
# static libraries.
76+
mlir_target_link_libraries(MLIRTestDialect PUBLIC
7377
MLIRControlFlowInterfaces
7478
MLIRDataLayoutInterfaces
7579
MLIRDerivedAttributeOpInterface

mlir/test/lib/IR/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ add_mlir_library(MLIRTestIR
2727
TestVisitorsGeneric.cpp
2828

2929
EXCLUDE_FROM_LIBMLIR
30+
)
3031

31-
LINK_LIBS PUBLIC
32+
# Since this library is excluded from libMLIR, link it to the dylib
33+
# to ensure that it can be used in flang without implicitly pulling in
34+
# static libraries.
35+
mlir_target_link_libraries(MLIRTestIR PUBLIC
3236
MLIRPass
3337
MLIRBytecodeReader
3438
MLIRBytecodeWriter

0 commit comments

Comments
 (0)