[PATCH] D67321: Respect CLANG_LINK_CLANG_DYLIB=ON in libclang and c-index-test
Aaron Puchert via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 9 17:27:15 PDT 2019
aaronpuchert added inline comments.
================
Comment at: clang/tools/libclang/CMakeLists.txt:115
+clang_target_link_libraries(libclang
+ PRIVATE
+ ${CLANG_LIB_DEPS}
----------------
beanz wrote:
> tstellar wrote:
> > aaronpuchert wrote:
> > > This might not be correct for static builds, I think we need `INTERFACE` here.
> > This patch looks OK to me, but you should find someone with more CMake knowledge to answer this question.
> This part of the patch is a bit tricky.
>
> As implemented it is fine for the most common build configurations, but will be a problem if `LIBCLANG_BUILD_STATIC=On` or if `LLVM_ENABLE_PIC=Off`.
>
> The correct solution is probably to wrap this code in `if (ENABLE_SHARED)`, and to have another code block that handles `if (ENABLE_STATIC)`. In that block you need to call this with `INTERFACE` as the linkage type, and you'll need to handle the case where both `ENABLE_SHARED` and `ENABLE_STATIC` is set. In that case the static library target is named `libclang_static`.
I agree with your analysis. What do you think about modifying `clang_target_link_libraries` instead? I thought we could make it do what `llvm_add_library` does with its `LINK_LIBS` argument (code which we are basically replacing here):
```
if(ARG_STATIC)
set(libtype INTERFACE)
else()
# We can use PRIVATE since SO knows its dependent libs.
set(libtype PRIVATE)
endif()
target_link_libraries(${name} ${libtype}
${ARG_LINK_LIBS}
${lib_deps}
${llvm_libs}
)
```
We could query `get_target_property(TARGET_TYPE ${target} TYPE)` and use that to determine the correct dependency type.
You're also right that it's possible to build both static and dynamic libraries. We could check for the existence of `${target}_static` and add the dependencies there as well.
If we handle it there, we'll also solve it for other libraries that depend on Clang components. (I'm thinking of libraries in clang-tools-extra and lldb, where I'd like to propose similar changes to this one.)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D67321/new/
https://reviews.llvm.org/D67321
More information about the cfe-commits
mailing list