From 5b9ebf3d7d072f39ed63007643c75fcc4ed5ffa7 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Thu, 16 May 2019 22:06:07 +0000 Subject: [PATCH] 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. Reviewers: tstellar, winksaville Subscribers: mgorny, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61909 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360946 91177308-0d34-0410-b5e6-96231b3b80d8 --- cmake/modules/AddClang.cmake | 7 +++++-- tools/CMakeLists.txt | 3 +++ tools/clang-shlib/CMakeLists.txt | 13 +++++++++++++ tools/clang-shlib/clang-shlib.cpp | 1 + 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tools/clang-shlib/CMakeLists.txt create mode 100644 tools/clang-shlib/clang-shlib.cpp diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake index 18bac7172b..b598f13ff6 100644 --- a/cmake/modules/AddClang.cmake +++ b/cmake/modules/AddClang.cmake @@ -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}) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 43dfffe149..f5c90ba783 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -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) diff --git a/tools/clang-shlib/CMakeLists.txt b/tools/clang-shlib/CMakeLists.txt new file mode 100644 index 0000000000..733ace3ac0 --- /dev/null +++ b/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 $) + list(APPEND _DEPS $) +endforeach () + +add_clang_library(clang_shared + SHARED + clang-shlib.cpp + ${_OBJECTS} + LINK_LIBS + ${_DEPS}) diff --git a/tools/clang-shlib/clang-shlib.cpp b/tools/clang-shlib/clang-shlib.cpp new file mode 100644 index 0000000000..0093622e6a --- /dev/null +++ b/tools/clang-shlib/clang-shlib.cpp @@ -0,0 +1 @@ +// Intentionally empty source file to make CMake happy -- 2.40.0