Repository navigation
Split lib target types in their own export groups - #4494
Conversation
This allows for the non-primary library to be missing in the Config.cmake file, e.g. if the devel files have a separate static-devel package Signed-off-by: Cristian Le <git@lecris.dev>
|
Could the developers please comment on this? This would be very helpful for Fedora packaging. |
There was a problem hiding this comment.
This is a solid attempt at separating the CMake export targets:
- zstdTargets_shared.cmake - exports libzstd_shared
- zstdTargets_static.cmake - exports libzstd_static
- zstdTargets.cmake - exports the interface libzstd target
This allows Linux distros to package static libraries separately (e.g., libzstd-static-devel) without breaking the main package's CMake config.
The core idea is correct and solves a real packaging problem.
However:
-
The interface target (
zstd::libzstd) may still break. Iflibzstdwas configured to link againstlibzstd_static(whenBUILD_SHARED_LIBS=OFF), butzstdTargets_static.cmakeis missing, then usingzstd::libzstdwill fail at CMake configure time. The PR doesn't fully handle this dependency chain. -
Consumer guidance is missing. Users should know:
- Use
zstd::libzstd_sharedif you explicitly want the shared library - Use
zstd::libzstd_staticif you explicitly want the static library - Use
zstd::libzstdfor the default (respectsBUILD_SHARED_LIBSat zstd build time) - Check
if(TARGET zstd::libzstd_static)before using it
- Use
| foreach(lib_suffix IN ITEMS "_shared" "_static") | ||
| include("${CMAKE_CURRENT_LIST_DIR}/zstdTargets${lib_suffix}.cmake" OPTIONAL) | ||
| endforeach() | ||
| include("${CMAKE_CURRENT_LIST_DIR}/zstdTargets.cmake") |
There was a problem hiding this comment.
This one is not optional: the libzstd interface target's dependency is baked in at build time.
That's fine, but the files it depends on can be split at package time. There's a hidden assumption that whoever packages zstd will keep the dependency chain intact.
The edge case described (building with BUILD_SHARED_LIBS=OFF then stripping the static package) is unlikely.
But it could be worth adding a runtime check in zstdConfig.cmake.in that the target libzstd depends on actually exists.
This is a downstream packaging issue. I would bot recommend upstream to carry the logic to support this as it will be hard to test cover this and it can hide various other issues. Downstream already need to be fully aware of all the building logic to produce and separate the artifacts, at which point they should be checking how each config.cmake are being consumed
Honestly only The goal here is to merely unblock the downstream packaging with optional components (i.e. if the consumer only links to If you wish to refactor the consumer interface then sure thing, I can give some detailed tips amd reviews on that, but I don't think it should be in this PR. |
|
The rationale behind this logic is that, since the primary consumers of this niche capability are package managers, Regarding refactoring, I had considered utilizing the |
|
Note: CI errors reported here are unrelated. |
Do you mean
|
This allows for the non-primary library to be missing in the Config.cmake file, e.g. if the devel files have a separate static-devel package