[clang] [cmake] Respect CLANG_LINK_CLANG_DYLIB for objlibs (PR #93454)
Nikita Popov via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 6 01:34:19 PDT 2024
https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/93454
>From b0bcd36b62a93e7d8bd0f7f01e857ce9aa7544c2 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 1/2] [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 a5ef639187d9..534c7b84ecfb 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()
>From 1cc7f9a4dc8d406886188797858e314f2d7634c6 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 6 Jun 2024 10:05:35 +0200
Subject: [PATCH 2/2] Use INTERFACE dep
---
clang/cmake/modules/AddClang.cmake | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/cmake/modules/AddClang.cmake b/clang/cmake/modules/AddClang.cmake
index 534c7b84ecfb..2528c16a09e5 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -202,12 +202,12 @@ 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)
+ target_link_libraries(obj.${target} INTERFACE clang-cpp)
endif()
else()
target_link_libraries(${target} ${type} ${ARGN})
if (TARGET obj.${target})
- target_link_libraries(obj.${target} ${ARGN})
+ target_link_libraries(obj.${target} INTERFACE ${ARGN})
endif()
endif()
endfunction()
More information about the cfe-commits
mailing list