[PATCH] D61909: Add Clang shared library with C++ exports
Chris Bieneman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 14 08:51:12 PDT 2019
beanz created this revision.
beanz added reviewers: tstellar, winksaville.
Herald added a subscriber: mgorny.
Herald added a project: clang.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D61909
Files:
clang/cmake/modules/AddClang.cmake
clang/tools/CMakeLists.txt
clang/tools/clang-shlib/CMakeLists.txt
clang/tools/clang-shlib/clang-shlib.cpp
Index: clang/tools/clang-shlib/clang-shlib.cpp
===================================================================
--- /dev/null
+++ clang/tools/clang-shlib/clang-shlib.cpp
@@ -0,0 +1 @@
+// Intentionally empty source file to make CMake happy
Index: clang/tools/clang-shlib/CMakeLists.txt
===================================================================
--- /dev/null
+++ clang/tools/clang-shlib/CMakeLists.txt
@@ -0,0 +1,13 @@
+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})
Index: clang/tools/CMakeLists.txt
===================================================================
--- clang/tools/CMakeLists.txt
+++ clang/tools/CMakeLists.txt
@@ -13,6 +13,9 @@
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)
Index: clang/cmake/modules/AddClang.cmake
===================================================================
--- clang/cmake/modules/AddClang.cmake
+++ clang/cmake/modules/AddClang.cmake
@@ -81,9 +81,12 @@
)
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})
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61909.199464.patch
Type: text/x-patch
Size: 1906 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190514/504b337d/attachment-0001.bin>
More information about the cfe-commits
mailing list