[clang] [cmake] Respect CLANG_LINK_CLANG_DYLIB for objlibs (PR #93454)

via cfe-commits cfe-commits at lists.llvm.org
Mon May 27 03:01:51 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Nikita Popov (nikic)

<details>
<summary>Changes</summary>

add_clang_library() will create a library clangFoo that depends on objlib obj.clangFoo. Then clang_target_link_libraries() will add a clang-cpp dependency to clangFoo, but obj.clangFoo will instead get dependencies on the individual clangXYZ libraries, instead of the shared object. The final outcome is that we will link both the static libraries and the shared object, leading to an increase in binary size and link times (when using LTO).

Make sure we use the same logic for the obj and non-obj libs.

I believe this regressed with the addition of the llvm-driver functionality in https://github.com/llvm/llvm-project/commit/f06abbb393800b0d466c88e283c06f75561c432c.

---
Full diff: https://github.com/llvm/llvm-project/pull/93454.diff


1 Files Affected:

- (modified) clang/cmake/modules/AddClang.cmake (+6-4) 


``````````diff
diff --git a/clang/cmake/modules/AddClang.cmake b/clang/cmake/modules/AddClang.cmake
index a5ef639187d9d..534c7b84ecfb1 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -194,10 +194,6 @@ macro(add_clang_symlink name dest)
 endmacro()
 
 function(clang_target_link_libraries target type)
-  if (TARGET obj.${target})
-    target_link_libraries(obj.${target} ${ARGN})
-  endif()
-
   get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
   if(LLVM_TOOL_LLVM_DRIVER_BUILD AND ${target} IN_LIST LLVM_DRIVER_TOOLS)
     set(target llvm-driver)
@@ -205,7 +201,13 @@ function(clang_target_link_libraries target type)
 
   if (CLANG_LINK_CLANG_DYLIB)
     target_link_libraries(${target} ${type} clang-cpp)
+    if (TARGET obj.${target})
+      target_link_libraries(obj.${target} clang-cpp)
+    endif()
   else()
     target_link_libraries(${target} ${type} ${ARGN})
+    if (TARGET obj.${target})
+      target_link_libraries(obj.${target} ${ARGN})
+    endif()
   endif()
 endfunction()

``````````

</details>


https://github.com/llvm/llvm-project/pull/93454


More information about the cfe-commits mailing list