[Reland][Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
[llvm-project.git] / mlir / tools / mlir-shlib / CMakeLists.txt
bloba33c70c5807bea99a5f6c76e10d9128b07e88152
1 # Building libmlir-cpp.so fails if LLVM_ENABLE_PIC=Off
2 if (NOT LLVM_ENABLE_PIC)
3   return()
4 endif()
6 # Building libmlir-cpp.so may not work on MSVC
7 if (MSVC)
8   return()
9 endif()
11 get_property(mlir_libs GLOBAL PROPERTY MLIR_STATIC_LIBS)
12 get_property(mlir_llvm_link_components GLOBAL PROPERTY MLIR_LLVM_LINK_COMPONENTS)
13 list(REMOVE_DUPLICATES mlir_libs)
14 list(REMOVE_DUPLICATES mlir_llvm_link_components)
16 foreach (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>)
27 endforeach ()
29 if(MLIR_LINK_MLIR_DYLIB)
30   set(INSTALL_WITH_TOOLCHAIN INSTALL_WITH_TOOLCHAIN)
31 endif()
33 if(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}
44     LINK_COMPONENTS
45     ${mlir_llvm_link_components}
46   )
47   target_link_libraries(MLIR PRIVATE ${LLVM_PTHREAD_LIB})
48 endif()
50 #message("Libraries included in libMLIR.so: ${mlir_libs}")
51 #message("LLVM Components included in libMLIR.so: ${mlir_llvm_link_components}")
53 mlir_check_all_link_libraries(MLIR)