diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -488,6 +488,7 @@ add_dependencies(${obj_name} ${link_lib}) endif() endforeach() + target_link_libraries(${obj_name} ${ARG_LINK_LIBS}) endif() endif() @@ -748,7 +749,7 @@ "COMPONENT_NAME;ADD_TO_COMPONENT" "" ${ARGN}) - add_llvm_library(${name} COMPONENT_LIB ${ARG_UNPARSED_ARGUMENTS}) + add_llvm_library(${name} COMPONENT_LIB OBJECT ${ARG_UNPARSED_ARGUMENTS}) string(REGEX REPLACE "^LLVM" "" component_name ${name}) set_property(TARGET ${name} PROPERTY LLVM_COMPONENT_NAME ${component_name}) diff --git a/llvm/tools/llvm-shlib/CMakeLists.txt b/llvm/tools/llvm-shlib/CMakeLists.txt --- a/llvm/tools/llvm-shlib/CMakeLists.txt +++ b/llvm/tools/llvm-shlib/CMakeLists.txt @@ -33,6 +33,10 @@ add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${INSTALL_WITH_TOOLCHAIN} ${SOURCES}) list(REMOVE_DUPLICATES LIB_NAMES) + + # Link against the object libraries instead of static libraries. + list(TRANSFORM LIB_NAMES PREPEND "obj.") + if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR (MINGW) OR (HAIKU) OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD") OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "GNU")