Skip to content

Commit 933ee07

Browse files
committed
[cmake] Do not link to the libLLVM.so file if LLVM_LINK_LLVM_DYLIB is on.
1 parent d8c73d1 commit 933ee07

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

lib/Interpreter/CMakeLists.txt

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,71 @@ if (USE_REPL)
2020
#Use DML optional sources
2121
endif(USE_REPL)
2222

23-
add_llvm_library(clangCppInterOp OBJECT
24-
CppInterOp.cpp
25-
${DLM}
26-
)
27-
2823
if (USE_CLING)
2924
set(cling_clang_interp clingInterpreter)
3025
endif()
3126
if (USE_REPL)
3227
set(cling_clang_interp clangInterpreter)
3328
endif()
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

4589
string(REPLACE ";" "\;" _VER CPPINTEROP_VERSION)
4690
set_source_files_properties(CppInterOp.cpp PROPERTIES COMPILE_DEFINITIONS

unittests/CppInterOp/TestSharedLib/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
add_llvm_library(TestSharedLib SHARED BUILDTREE_ONLY TestSharedLib.cpp)
1+
add_llvm_library(TestSharedLib
2+
SHARED
3+
DISABLE_LLVM_LINK_LLVM_DYLIB
4+
BUILDTREE_ONLY
5+
TestSharedLib.cpp)
26
# Put TestSharedLib next to the unit test executable.
37
set_output_directory(TestSharedLib
48
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../

0 commit comments

Comments
 (0)