[clang] [cmake] Respect CLANG_LINK_CLANG_DYLIB for objlibs (PR #93454)
Nikita Popov via cfe-commits
cfe-commits at lists.llvm.org
Mon May 27 03:01:21 PDT 2024
https://github.com/nikic created https://github.com/llvm/llvm-project/pull/93454
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.
>From 410dfb1a1ade79344e2e28c63c1819a5cb3c55ba Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Mon, 27 May 2024 11:56:41 +0200
Subject: [PATCH] [cmake] Respect CLANG_LINK_CLANG_DYLIB for objlibs
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.
---
clang/cmake/modules/AddClang.cmake | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
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()
More information about the cfe-commits
mailing list