Rename CMake targets to avoid clashes when used as a subproject#1970
Rename CMake targets to avoid clashes when used as a subproject#1970Dead2 merged 3 commits intozlib-ng:developfrom
Conversation
Summary by CodeRabbit
WalkthroughReplace public CMake targets and exports from Changes
Sequence Diagram(s)Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (4)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (65)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Half of the build directories are broken due to lack of updating... Not sure if this is even a good idea as any third-party build scripts will break too. |
|
This will break a lot of downstream projects that rely on the old CMake project names. |
|
This might be relevant: |
5ffa3c0 to
27a9803
Compare
There was a problem hiding this comment.
Actionable comments posted: 6
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
test/CMakeLists.txt (1)
16-53: Don't unconditionally require the shared target.
target_link_libraries(example zlib-ng)now hard-depends on the shared library, butzlib-ngis only created whenZLIBNG_ENABLE_SHARED(or equivalent) is on. In a static-only build (the default on several CI jobs), this statement errors out because thezlib-ngtarget simply doesn't exist; previouslyexamplelinked to the always-availablezlibtarget (shared or static depending on configuration). Please switch this and the similar calls below to the static target when the shared one is absent—either by reusing the existingBUILD_SHARED_LIBSguard or, preferably, by linking via the newzlib-ng::zlib/zlib-ng::zlibstaticaliases that resolve correctly in both modes.Apply this diff to restore conditional linking:
-target_link_libraries(example zlib-ng) +if(TARGET zlib-ng) + target_link_libraries(example zlib-ng) +else() + target_link_libraries(example zlib-ng-static) +endif()
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
CMakeLists.txt(5 hunks)test/CMakeLists.txt(4 hunks)test/add-subdirectory-project/CMakeLists.txt(1 hunks)test/benchmarks/CMakeLists.txt(2 hunks)test/fuzz/CMakeLists.txt(1 hunks)test/pigz/CMakeLists.txt(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- test/benchmarks/CMakeLists.txt
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-04T16:59:44.725Z
Learnt from: mtl1979
PR: zlib-ng/zlib-ng#1925
File: arch/loongarch/lasxintrin_ext.h:38-65
Timestamp: 2025-07-04T16:59:44.725Z
Learning: In zlib-ng, the policy for supporting old compilers is to maintain compatibility for up to two years after GitHub removes support for them in CI, or when there is no long-time contributor left testing for the architecture if the architecture was not supported by GitHub Actions at all.
Applied to files:
test/CMakeLists.txttest/pigz/CMakeLists.txtCMakeLists.txt
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1970 +/- ##
===========================================
+ Coverage 81.40% 82.47% +1.07%
===========================================
Files 161 161
Lines 13748 13748
Branches 3149 3149
===========================================
+ Hits 11191 11339 +148
+ Misses 1533 1360 -173
- Partials 1024 1049 +25 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fixed.
I've added optional aliases for the old names - projects can now use |
This is a good idea and cause less trouble, especially with older CMake versions that can't handle duplicate target names. Eventually, in future major release, we might want to drop the support for short target names as recent releases of stock zlib already support the namespaced target names. |
|
What about the GH issue where the customize the entire name? |
Customizing the entire name might cause own issues... It might be better for a zlib-ng fork instead of the main repository just to keep things wandering too much and becoming maintaining nightmare. |
|
In minizip-ng I do support specifying a suffix to the project name. |
When the aliases are disabled, nothing stops from supporting specifying a suffix for a target name, but it might warrant separate PR after this one is merged... Biggest issue with supporting completely different name for targets in zlib-ng is that the new name can clash with any random target in any project and then people come to us complaining things break. Later CMake versions can already handle duplicate target names in subprojects, so this is mainly for backwards compatibility until we stop supporting old enough CMake versions. |
We can’t fix stupid people. My point in mentioning that other GH issue is that we should just implement that and these changes in this PR would not be needed. |
We also shouldn't make things easier for stupid people... It's always about choosing what is the best way to implement things, sometimes it's not the one with smallest or least complicated change. I've been software designer and developer for over 40 years and I've had quite a lot of experience with choosing what is the best option of many choices... But in the end it's just one opinion when I'm not the project maintainer. |
What do you think about point 3 @ccawley2011, is this something you would want to implement as well? |
|
@ccawley2011 Would you please rebase this PR, so we can see that it still works after other PRs. And I'd also like your reply on the above question if you could. |
594db7a to
7673a22
Compare
Dead2
left a comment
There was a problem hiding this comment.
This LGTM. Perhaps someone else wants to make a PR to add CMake target aliases
Adding "target aliases" needs proper discussion or it will flood us with complains from people who try to use the feature without knowing the restrictions for target names. In my professional opinion, we should only allow adding extra suffix to the library base name(s), as that should be enough for portable builds, which would be the biggest user of the feature. |
|
The use case in the linked issue suggests that this might be sufficient since it both renames the target to be different from standard zlib and adds |
|
For portable builds, we need to adjust A lot of the information is scattered through several sections of various books about CMake, with very little information in actual CMake documentation except notes about deprecated features. This will make sure |
Summary by CodeRabbit