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,7 +488,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) @@ -746,7 +752,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/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 @@ -6,6 +6,10 @@ include_directories( ${FFI_INCLUDE_PATH} ) endif() +if( LLVM_ENABLE_FFI ) + set(link_libs ${FFI_LIBRARY_PATH}) +endif() + add_llvm_component_library(LLVMInterpreter Execution.cpp ExternalFunctions.cpp @@ -14,13 +18,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_LIBRARY_PATH} ) -endif() 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")