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 @@ -556,7 +556,13 @@ add_dependencies(${obj_name} ${link_lib}) endif() endforeach() + target_link_libraries(${obj_name} ${ARG_LINK_LIBS}) endif() + + # Add target include directories from the main target. This makes it + # possible to call target_include_directories() with ${name} after + # calling llvm_add_library() and still have it apply to the object library. + set_target_properties(${obj_name} PROPERTIES INCLUDE_DIRECTORIES "$") endif() if(ARG_SHARED AND ARG_STATIC) @@ -822,7 +828,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}) @@ -1118,8 +1124,11 @@ # Add static plugins to the Extension component foreach(llvm_extension ${LLVM_STATIC_EXTENSIONS}) - set_property(TARGET LLVMExtensions APPEND PROPERTY LINK_LIBRARIES ${llvm_extension}) - set_property(TARGET LLVMExtensions APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${llvm_extension}) + # Update the properties for the normal library and the object library. + foreach (lib "LLVMExtensions;obj.LLVMExtensions") + set_property(TARGET ${lib} APPEND PROPERTY LINK_LIBRARIES ${llvm_extension}) + set_property(TARGET ${lib} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${llvm_extension}) + endforeach() endforeach() # Eventually generate the extension headers, and store config to a cmake file diff --git a/llvm/lib/ExecutionEngine/Interpreter/CMakeLists.txt b/llvm/lib/ExecutionEngine/Interpreter/CMakeLists.txt --- a/llvm/lib/ExecutionEngine/Interpreter/CMakeLists.txt +++ b/llvm/lib/ExecutionEngine/Interpreter/CMakeLists.txt @@ -1,3 +1,7 @@ +if( LLVM_ENABLE_FFI ) + set(link_libs FFI::ffi) +endif() + add_llvm_component_library(LLVMInterpreter Execution.cpp ExternalFunctions.cpp @@ -6,13 +10,10 @@ DEPENDS intrinsics_gen + LINK_LIBS PRIVATE ${link_libs} LINK_COMPONENTS CodeGen Core ExecutionEngine Support ) - -if( LLVM_ENABLE_FFI ) - target_link_libraries( LLVMInterpreter PRIVATE FFI::ffi ) -endif() diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt --- a/llvm/lib/Support/CMakeLists.txt +++ b/llvm/lib/Support/CMakeLists.txt @@ -249,7 +249,6 @@ Z3Solver.cpp ${ALLOCATOR_FILES} - $ # System Atomic.cpp @@ -274,6 +273,7 @@ LINK_LIBS ${system_libs} ${imported_libs} ${delayload_flags} + $ LINK_COMPONENTS Demangle 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")