[PATCH] D74106: [CMake] Use PUBLIC link mode for static libraries

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 6 14:07:46 PST 2020


phosek added a comment.

In D74106#1862442 <https://reviews.llvm.org/D74106#1862442>, @smeenai wrote:

> I don't quite understand what's going on here. Are you saying that if you have a static library which depends on an imported library as `INTERFACE`, targets that link against the static library won't link against the imported library, but if the static library depends on the imported library as `PUBLIC`, targets that link against the static library will link against the imported library?


If a target A depends on a library B as `INTERFACE`, the library B becomes a part of A's public interface, that is any library that depends on A will "link" against B (link here doesn't just mean regular linking, but also getting appropriate header dependencies), but A itself wouldn't. In case of `PUBLIC`, not only B becomes part of A's public interface, A will also link against B.

I hit this problem with D74102 <https://reviews.llvm.org/D74102> where `Support` would `INTERFACE` depend on `ZLIB::ZLIB` which means that anything depending on `Support` would get `ZLIB::ZLIB` dependency (both headers and linking where appropriate), but `Support` itself wouldn't which defeats the purpose of using the imported library.

I'm not sure when would the `INTERFACE` semantics on static libraries make sense, IIUC the intent was to avoid linking other libraries into static libraries, but that's not something that CMake would ever do since you cannot really link anything to a static library (the only other semantics that would make sense is merging static libraries together but that's not something CMake does).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74106/new/

https://reviews.llvm.org/D74106





More information about the llvm-commits mailing list