Skip to content

Commit 5766e93

Browse files
committedMay 17, 2019
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360985 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 84c9929 commit 5766e93

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed
 

‎cmake/modules/AddClang.cmake

+5-2
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,12 @@ macro(add_clang_library name)
8181
)
8282
endif()
8383
if(ARG_SHARED)
84-
set(ARG_ENABLE_SHARED SHARED)
84+
set(LIBTYPE SHARED)
85+
else()
86+
set(LIBTYPE STATIC OBJECT)
87+
set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
8588
endif()
86-
llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
89+
llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
8790

8891
if(TARGET ${name})
8992
target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})

‎tools/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ add_clang_subdirectory(c-index-test)
1313

1414
add_clang_subdirectory(clang-rename)
1515
add_clang_subdirectory(clang-refactor)
16+
if(UNIX)
17+
add_clang_subdirectory(clang-shlib)
18+
endif()
1619

1720
if(CLANG_ENABLE_ARCMT)
1821
add_clang_subdirectory(arcmt-test)

‎tools/clang-shlib/CMakeLists.txt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Building libclang_shared.so fails if LLVM_ENABLE_PIC=Off
2+
if (NOT LLVM_ENABLE_PIC)
3+
return()
4+
endif()
5+
6+
get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS)
7+
8+
foreach (lib ${clang_libs})
9+
list(APPEND _OBJECTS $<TARGET_OBJECTS:obj.${lib}>)
10+
list(APPEND _DEPS $<TARGET_PROPERTY:${lib},INTERFACE_LINK_LIBRARIES>)
11+
endforeach ()
12+
13+
add_clang_library(clang_shared
14+
SHARED
15+
clang-shlib.cpp
16+
${_OBJECTS}
17+
LINK_LIBS
18+
${_DEPS})

‎tools/clang-shlib/clang-shlib.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Intentionally empty source file to make CMake happy

0 commit comments

Comments
 (0)
Please sign in to comment.