From e2c0c70101ae4419917b232beae37b3d3a713b0c Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Tue, 4 Feb 2020 13:06:54 -0800 Subject: [cmake] Fix clang builds with BUILD_SHARED=ON and CLANG_LINK_CLANG_DYLIB=ON Summary: We were linking all the clang objects and shared libraries into libclang-cpp.so, which was causing the command line options to be registered twice. Reviewers: beanz, mgorny Reviewed By: beanz, mgorny Subscribers: merge_guards_bot, mgorny, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68520 (cherry picked from commit ebcf25ea8100fc9987fd1edd1975194addc2fc05) --- clang/tools/clang-shlib/CMakeLists.txt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/clang/tools/clang-shlib/CMakeLists.txt b/clang/tools/clang-shlib/CMakeLists.txt index a0fc8f6bfbd..07ee0f0a9a9 100644 --- a/clang/tools/clang-shlib/CMakeLists.txt +++ b/clang/tools/clang-shlib/CMakeLists.txt @@ -14,7 +14,22 @@ foreach (lib ${clang_libs}) list(APPEND _OBJECTS $) endif() list(APPEND _DEPS $) - list(APPEND _DEPS $) + + # clang libraries are redundant since we are linking all the individual + # object files into libclang-cpp.so, so filter them out from _DEPS. + # This avoids problems with LLVM global data when building with + # BUILD_SHARED_LIBS=ON + # FIXME: We could use list(FILTER) with cmake >= 3.6 + # FIXME: With cmake >= 3.15 we could use the generator expression + # $ + get_target_property(interface ${lib} LINK_LIBRARIES) + if (interface) + foreach(lib ${interface}) + if (NOT ${lib} MATCHES "^clang") + list(APPEND _DEPS ${lib}) + endif() + endforeach() + endif() endforeach () if (CLANG_LINK_CLANG_DYLIB) -- cgit v1.2.3