https://github.com/ur4t created https://github.com/llvm/llvm-project/pull/187857

If CLANG_LINK_CLANG_DYLIB is enabled, link clang shared libraries, otherwise 
follow old behaviours.


>From c4570c03761ca57e3e91e077ab085eb3bc2565d5 Mon Sep 17 00:00:00 2001
From: ur4t <[email protected]>
Date: Sat, 21 Mar 2026 11:51:30 +0000
Subject: [PATCH] [libclang] Link clang shared libraries when requested

---
 clang/tools/c-index-test/CMakeLists.txt | 3 +++
 clang/tools/libclang/CMakeLists.txt     | 8 +++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/clang/tools/c-index-test/CMakeLists.txt 
b/clang/tools/c-index-test/CMakeLists.txt
index 56b4d1fe20699..eda39ebf57ac4 100644
--- a/clang/tools/c-index-test/CMakeLists.txt
+++ b/clang/tools/c-index-test/CMakeLists.txt
@@ -25,6 +25,9 @@ else()
   target_link_libraries(c-index-test
     PRIVATE
     libclang
+  )
+  clang_target_link_libraries(c-index-test
+    PRIVATE
     clangAST
     clangBasic
     clangDriver
diff --git a/clang/tools/libclang/CMakeLists.txt 
b/clang/tools/libclang/CMakeLists.txt
index 09322a424f488..1d1f3d996b71a 100644
--- a/clang/tools/libclang/CMakeLists.txt
+++ b/clang/tools/libclang/CMakeLists.txt
@@ -74,11 +74,11 @@ set(LIBS
 )
 
 if (HAVE_LIBDL)
-  list(APPEND LIBS ${CMAKE_DL_LIBS})
+  set(DL_LIBS ${CMAKE_DL_LIBS})
 elseif (CLANG_BUILT_STANDALONE)
   find_library(DL_LIBRARY_PATH dl)
   if (DL_LIBRARY_PATH)
-    list(APPEND LIBS dl)
+    set(DL_LIBS dl)
   endif ()
 endif ()
 
@@ -142,7 +142,7 @@ add_clang_library(libclang ${ENABLE_SHARED} 
${ENABLE_STATIC} INSTALL_WITH_TOOLCH
   clang-resource-headers
 
   LINK_LIBS
-  ${LIBS}
+  ${DL_LIBS}
 
   LINK_COMPONENTS
   ${LLVM_TARGETS_TO_BUILD}
@@ -151,6 +151,8 @@ add_clang_library(libclang ${ENABLE_SHARED} 
${ENABLE_STATIC} INSTALL_WITH_TOOLCH
   TargetParser
   )
 
+clang_target_link_libraries(libclang PRIVATE ${LIBS})
+
 if(ENABLE_STATIC)
   foreach(name libclang obj.libclang libclang_static)
     if (TARGET ${name})

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to