[llvm-branch-commits] [clang] e2c0c70 - [cmake] Fix clang builds with BUILD_SHARED=ON and CLANG_LINK_CLANG_DYLIB=ON

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Feb 10 04:34:53 PST 2020


Author: Tom Stellard
Date: 2020-02-10T13:34:01+01:00
New Revision: e2c0c70101ae4419917b232beae37b3d3a713b0c

URL: https://github.com/llvm/llvm-project/commit/e2c0c70101ae4419917b232beae37b3d3a713b0c
DIFF: https://github.com/llvm/llvm-project/commit/e2c0c70101ae4419917b232beae37b3d3a713b0c.diff

LOG: [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)

Added: 
    

Modified: 
    clang/tools/clang-shlib/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/clang/tools/clang-shlib/CMakeLists.txt b/clang/tools/clang-shlib/CMakeLists.txt
index a0fc8f6bfbde..07ee0f0a9a92 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 $<TARGET_OBJECTS:obj.${lib}>)
   endif()
   list(APPEND _DEPS $<TARGET_PROPERTY:${lib},INTERFACE_LINK_LIBRARIES>)
-  list(APPEND _DEPS $<TARGET_PROPERTY:${lib},LINK_LIBRARIES>)
+
+  # 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
+  # $<FILTER:list,INCLUDE|EXCLUDE,regex>
+  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)


        


More information about the llvm-branch-commits mailing list