Re-land: Add Clang shared library with C++ exports

Summary:
This patch adds a libClang_shared library on *nix systems which exports the entire C++ API. In order to support this on Windows we should really refactor llvm-shlib and share code between the two.

This also uses a slightly different method for generating the shared library, which I should back-port to llvm-shlib. Instead of linking the static archives and passing linker flags to force loading the whole libraries, this patch creates object libraries for every library (which has no cost in the build system), and link the object libraries.

llvm-svn: 360985
This commit is contained in:
Chris Bieneman 2019-05-17 04:20:01 +00:00
parent 1d16515fb4
commit 876e39937e
4 changed files with 27 additions and 2 deletions

View File

@ -81,9 +81,12 @@ macro(add_clang_library name)
)
endif()
if(ARG_SHARED)
set(ARG_ENABLE_SHARED SHARED)
set(LIBTYPE SHARED)
else()
set(LIBTYPE STATIC OBJECT)
set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
endif()
llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
if(TARGET ${name})
target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})

View File

@ -13,6 +13,9 @@ add_clang_subdirectory(c-index-test)
add_clang_subdirectory(clang-rename)
add_clang_subdirectory(clang-refactor)
if(UNIX)
add_clang_subdirectory(clang-shlib)
endif()
if(CLANG_ENABLE_ARCMT)
add_clang_subdirectory(arcmt-test)

View File

@ -0,0 +1,18 @@
# Building libclang_shared.so fails if LLVM_ENABLE_PIC=Off
if (NOT LLVM_ENABLE_PIC)
return()
endif()
get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS)
foreach (lib ${clang_libs})
list(APPEND _OBJECTS $<TARGET_OBJECTS:obj.${lib}>)
list(APPEND _DEPS $<TARGET_PROPERTY:${lib},INTERFACE_LINK_LIBRARIES>)
endforeach ()
add_clang_library(clang_shared
SHARED
clang-shlib.cpp
${_OBJECTS}
LINK_LIBS
${_DEPS})

View File

@ -0,0 +1 @@
// Intentionally empty source file to make CMake happy