@@ -20,27 +20,71 @@ if (USE_REPL)
2020 #Use DML optional sources
2121endif (USE_REPL)
2222
23- add_llvm_library(clangCppInterOp OBJECT
24- CppInterOp.cpp
25- ${DLM}
26- )
27-
2823if (USE_CLING)
2924 set (cling_clang_interp clingInterpreter)
3025endif ()
3126if (USE_REPL)
3227 set (cling_clang_interp clangInterpreter)
3328endif ()
3429
35- target_link_libraries (clangCppInterOp PRIVATE
30+ set (link_libs
3631 ${cling_clang_interp}
3732 clangAST
3833 clangBasic
3934 clangFrontend
4035 clangLex
4136 clangSema
4237 dl
43- )
38+ )
39+
40+ # Get rid of libLLVM-X.so which is appended to the list of static libraries.
41+ if (LLVM_LINK_LLVM_DYLIB)
42+ set (new_libs ${link_libs} )
43+ set (libs ${new_libs} )
44+ while (NOT "${new_libs} " STREQUAL "" )
45+ foreach (lib ${new_libs} )
46+ if (TARGET ${lib} )
47+ get_target_property (transitive_libs ${lib} INTERFACE_LINK_LIBRARIES)
48+ if (NOT transitive_libs)
49+ continue ()
50+ endif ()
51+ foreach (transitive_lib ${transitive_libs} )
52+ get_target_property (lib_type ${transitive_lib} TYPE )
53+ if ("${lib_type} " STREQUAL "STATIC_LIBRARY" )
54+ list (APPEND static_transitive_libs ${transitive_lib} )
55+ else ()
56+ # Filter our libLLVM.so and friends.
57+ continue ()
58+ endif ()
59+ if (NOT ${transitive_lib} IN_LIST libs)
60+ list (APPEND newer_libs ${transitive_lib} )
61+ list (APPEND libs ${transitive_lib} )
62+ endif ()
63+ endforeach (transitive_lib)
64+ # Update the target properties with the list of only static libraries.
65+ set_target_properties (${lib} PROPERTIES INTERFACE_LINK_LIBRARIES "${static_transitive_libs} " )
66+ set (static_transitive_libs "" )
67+ endif ()
68+ endforeach (lib)
69+ set (new_libs ${newer_libs} )
70+ set (newer_libs "" )
71+ endwhile ()
72+ # We just got rid of the libLLVM.so and other components shipped as shared
73+ # libraries, we need to make up for the missing dependency.
74+ list (APPEND LLVM_LINK_COMPONENTS
75+ Coverage
76+ FrontendHLSL
77+ LTO
78+ )
79+ endif (LLVM_LINK_LLVM_DYLIB)
80+
81+ add_llvm_library(clangCppInterOp
82+ DISABLE_LLVM_LINK_LLVM_DYLIB
83+ CppInterOp.cpp
84+ ${DLM}
85+ LINK_LIBS
86+ ${link_libs}
87+ )
4488
4589string (REPLACE ";" "\; " _VER CPPINTEROP_VERSION)
4690set_source_files_properties (CppInterOp.cpp PROPERTIES COMPILE_DEFINITIONS
0 commit comments