1# Building libmlir-cpp.so fails if LLVM_ENABLE_PIC=Off 2if (NOT LLVM_ENABLE_PIC) 3 return() 4endif() 5 6# Building libmlir-cpp.so may not work on MSVC 7if (MSVC) 8 return() 9endif() 10 11get_property(mlir_libs GLOBAL PROPERTY MLIR_STATIC_LIBS) 12get_property(mlir_llvm_link_components GLOBAL PROPERTY MLIR_LLVM_LINK_COMPONENTS) 13list(REMOVE_DUPLICATES mlir_libs) 14list(REMOVE_DUPLICATES mlir_llvm_link_components) 15 16foreach (lib ${mlir_libs}) 17 if(XCODE) 18 # Xcode doesn't support object libraries, so we have to trick it into 19 # linking the static libraries instead. 20 list(APPEND _DEPS "-force_load" ${lib}) 21 else() 22 list(APPEND _OBJECTS $<TARGET_OBJECTS:obj.${lib}>) 23 endif() 24 # libClang needs this, but it causes problems for MLIR (probably 25 # because we use public library dependencies within MLIR.) 26 # list(APPEND _DEPS $<TARGET_PROPERTY:${lib},LINK_LIBRARIES>) 27endforeach () 28 29if(MLIR_LINK_MLIR_DYLIB) 30 set(INSTALL_WITH_TOOLCHAIN INSTALL_WITH_TOOLCHAIN) 31endif() 32 33if(LLVM_BUILD_LLVM_DYLIB) 34 add_mlir_library( 35 MLIR 36 SHARED 37 EXCLUDE_FROM_LIBMLIR 38 ${INSTALL_WITH_TOOLCHAIN} 39 mlir-shlib.cpp 40 ${_OBJECTS} 41 LINK_LIBS 42 ${_DEPS} 43 44 LINK_COMPONENTS 45 ${mlir_llvm_link_components} 46 ) 47 target_link_libraries(MLIR PRIVATE ${LLVM_PTHREAD_LIB}) 48endif() 49 50#message("Libraries included in libMLIR.so: ${mlir_libs}") 51#message("LLVM Components included in libMLIR.so: ${mlir_llvm_link_components}") 52 53mlir_check_all_link_libraries(MLIR) 54