Skip to content

Commit 0368c1d

Browse files
[MLIR][cmake][NFC] Check for incorrect usage of LLVM components in LINK_LIBS
Using LLVM components in LINK_LIBS means that the mechanisms for replacing component dependencies with libLLVM.so break. Try to catch this incorrect usage up front, instead of waiting until later when we get difficult to understand runtime errors from incorrectly linked libraries. Differential Revision: https://reviews.llvm.org/D80103
1 parent b54635e commit 0368c1d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

mlir/cmake/modules/AddMLIR.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ function(add_mlir_library name)
108108

109109
# MLIR libraries uniformly depend on LLVMSupport. Just specify it once here.
110110
list(APPEND ARG_LINK_COMPONENTS Support)
111+
112+
# LINK_COMPONENTS is necessary to allow libLLVM.so to be properly
113+
# substituted for individual library dependencies if LLVM_LINK_LLVM_DYLIB
114+
# Perhaps this should be in llvm_add_library instead? However, it fails
115+
# on libclang-cpp.so
116+
get_property(llvm_component_libs GLOBAL PROPERTY LLVM_COMPONENT_LIBS)
117+
foreach(lib ${ARG_LINK_LIBS})
118+
if(${lib} IN_LIST llvm_component_libs)
119+
message(SEND_ERROR "${name} specifies LINK_LIBS ${lib}, but LINK_LIBS cannot be used for LLVM libraries. Please use LINK_COMPONENTS instead.")
120+
endif()
121+
endforeach()
122+
111123
list(APPEND ARG_DEPENDS mlir-generic-headers)
112124
llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs} DEPENDS ${ARG_DEPENDS} LINK_COMPONENTS ${ARG_LINK_COMPONENTS} LINK_LIBS ${ARG_LINK_LIBS})
113125

0 commit comments

Comments
 (0)