diff --git a/clang/tools/clang-shlib/CMakeLists.txt b/clang/tools/clang-shlib/CMakeLists.txt --- a/clang/tools/clang-shlib/CMakeLists.txt +++ b/clang/tools/clang-shlib/CMakeLists.txt @@ -14,7 +14,22 @@ 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)