Skip to content

Commit d1d43f0

Browse files
authored
[CIR] Fix tests with LLVM_LINK_LLVM_DYLIB (#1222)
This option creates and links all tools against a single libLLVM shared library (and the corresponding CLANG_LINK_CLANG_DYLIB option also gets turned on by default). In order for this to work, we need to use LINK_COMPONENTS instead of LINK_LIBS for all LLVM dependencies, and clang_target_link_libraries for all Clang dependencies, so that they get rewritten to use the dylib. Remove llvm_update_compile_flags while I'm here, since the build macros handle that internally. Before this change, we'd link against certain LLVM libraries both statically and dynamically, leading to test failures from duplicate singletons. The way this works for MLIR is fragile right now: MLIR can create its own dylib as well but doesn't have build system support for linking against that dylib. We end up folding the MLIR libraries into libclang-cpp.so (because all Clang dependencies get pulled into it), but MLIR tools still link the MLIR libraries statically. It'll still work, but BUILD_SHARED_LIBS is possibly a better alternative for development. Distributions like Fedora build their LLVM packages with LLVM_LINK_LLVM_DYLIB, so we'll want to eventually have good MLIR support for that setup too.
1 parent 994ceb5 commit d1d43f0

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

clang/lib/CIR/Dialect/Transforms/TargetLowering/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ add_clang_library(TargetLowering
2222
DEPENDS
2323
clangBasic
2424

25+
LINK_COMPONENTS
26+
TargetParser
27+
2528
LINK_LIBS PUBLIC
2629

2730
clangBasic
28-
LLVMTargetParser
2931
MLIRIR
3032
MLIRPass
3133
MLIRDLTIDialect

clang/tools/cir-opt/CMakeLists.txt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,24 @@ get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
44
include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include)
55
include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include)
66

7-
set(LIBS
8-
${dialect_libs}
9-
${conversion_libs}
7+
add_clang_tool(cir-opt
8+
cir-opt.cpp
9+
)
10+
11+
clang_target_link_libraries(cir-opt
12+
PRIVATE
1013
clangCIR
1114
clangCIRLoweringThroughMLIR
1215
clangCIRLoweringDirectToLLVM
13-
MLIRAnalysis
1416
MLIRCIR
1517
MLIRCIRTransforms
18+
)
19+
20+
target_link_libraries(cir-opt
21+
PRIVATE
22+
${dialect_libs}
23+
${conversion_libs}
24+
MLIRAnalysis
1625
MLIRDialect
1726
MLIRIR
1827
MLIRMemRefDialect
@@ -23,13 +32,3 @@ set(LIBS
2332
MLIRTransforms
2433
MLIRTransformUtils
2534
)
26-
27-
add_clang_tool(cir-opt
28-
cir-opt.cpp
29-
30-
DEPENDS
31-
${LIBS}
32-
)
33-
34-
target_link_libraries(cir-opt PRIVATE ${LIBS})
35-
llvm_update_compile_flags(cir-opt)

clang/tools/cir-translate/CMakeLists.txt

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@ get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS)
55
include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include)
66
include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include)
77

8-
set(LIBS
9-
${dialect_libs}
10-
${conversion_libs}
11-
${translation_libs}
8+
add_clang_tool(cir-translate
9+
cir-translate.cpp
10+
)
11+
12+
clang_target_link_libraries(cir-translate
13+
PRIVATE
1214
clangCIR
1315
clangCIRLoweringDirectToLLVM
14-
MLIRAnalysis
1516
MLIRCIR
1617
MLIRCIRTransforms
18+
)
19+
20+
target_link_libraries(cir-translate
21+
PRIVATE
22+
${dialect_libs}
23+
${conversion_libs}
24+
${translation_libs}
25+
MLIRAnalysis
1726
MLIRDialect
1827
MLIRIR
1928
MLIROptLib
@@ -24,13 +33,3 @@ set(LIBS
2433
MLIRTranslateLib
2534
MLIRSupport
2635
)
27-
28-
add_clang_tool(cir-translate
29-
cir-translate.cpp
30-
31-
DEPENDS
32-
${LIBS}
33-
)
34-
35-
target_link_libraries(cir-translate PRIVATE ${LIBS})
36-
llvm_update_compile_flags(cir-translate)

0 commit comments

Comments
 (0)