Skip to content

Rename CMake targets to avoid clashes when used as a subproject#1970

Merged
Dead2 merged 3 commits intozlib-ng:developfrom
ccawley2011:cmake-target
Oct 28, 2025
Merged

Rename CMake targets to avoid clashes when used as a subproject#1970
Dead2 merged 3 commits intozlib-ng:developfrom
ccawley2011:cmake-target

Conversation

@ccawley2011
Copy link
Copy Markdown
Contributor

@ccawley2011 ccawley2011 commented Sep 25, 2025

Summary by CodeRabbit

  • New Features
    • Added a user-facing option to provide zlib-compatible target aliases.
  • Refactor
    • Public libraries renamed to zlib-ng (shared) and zlib-ng-static (static); naming, versioning, output names and DLL suffix handling standardized.
  • Chores
    • Installation/export and generated config outputs updated to publish zlib-ng‑named libraries and symbols.
  • Tests
    • Tests, benchmarks and fuzz targets updated to link against zlib‑ng variants with no behavior changes.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 25, 2025

Summary by CodeRabbit

  • New Features
    • Added a user-facing option to provide zlib-compatible target aliases.
  • Refactor
    • Public libraries renamed to zlib-ng (shared) and zlib-ng-static (static); naming, versioning, output names and DLL suffix handling standardized.
  • Chores
    • Installation/export and generated config outputs updated to publish zlib-ng‑named libraries and symbols.
  • Tests
    • Tests, benchmarks and fuzz targets updated to link against zlib‑ng variants with no behavior changes.

Walkthrough

Replace public CMake targets and exports from zlib/zlibstatic to zlib-ng/zlib-ng-static, add zlib-ng::zlib and zlib-ng::zlibstatic aliases, introduce ZLIB_ALIASES option, and update install/export, target properties, symbol/version-script references, and all test/benchmark/fuzz/link targets accordingly.

Changes

Cohort / File(s) Summary
Core build targets and exports
CMakeLists.txt
Add zlib-ng (SHARED) and zlib-ng-static (STATIC) targets and zlib-ng::zlib / zlib-ng::zlibstatic ALIASes; add option(ZLIB_ALIASES ON); set ZLIB_INSTALL_LIBRARIES to zlib-ng family; update EXPORT_NAME, OUTPUT_NAME, SUFFIX, VERSION/SOVERSION, DEFINE_SYMBOL, version-script/linker flags, and target_sources/alias logic to use zlib-ng naming and mirror compatibility aliases when requested.
Tests linking updates
test/CMakeLists.txt
Replace target_link_libraries references from zlib/zlibstatic to zlib-ng/zlib-ng-static for example, minigzip, minideflate, switchlevels, infcover, gtest_zlib, and related test targets (conditional on BUILD_SHARED_LIBS).
Benchmarks linking updates
test/benchmarks/CMakeLists.txt
Change benchmark targets to link zlib-ng-static instead of zlibstatic; other linkages unchanged.
Fuzz targets linking updates
test/fuzz/CMakeLists.txt
Update fuzz target link libraries from zlibstatic/zlib to zlib-ng-static/zlib-ng depending on BUILD_SHARED_LIBS.
Subproject & tools linking updates
test/add-subdirectory-project/CMakeLists.txt, test/pigz/CMakeLists.txt
Switch zlibstatic/zlib usages to zlib-ng-static/zlib-ng; add ZLIB_ALIASES option in test/pigz/CMakeLists.txt.

Sequence Diagram(s)

Possibly related PRs

Suggested labels

Build Env, enhancement, cleanup

Suggested reviewers

  • nmoinvaz
  • Dead2

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request has no description provided by the author. According to the evaluation criteria, a description fails when it does not describe any part of the changeset, and an empty description clearly meets this condition as it conveys no information whatsoever about the modifications made. While the check is designed to be lenient, the complete absence of descriptive content falls short of even minimal expectations for PR documentation.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "Rename CMake targets to avoid clashes when used as a subproject" accurately summarizes the primary objective of the changeset. The changes across CMakeLists.txt files consistently rename targets from zlib/zlibstatic to zlib-ng/zlib-ng-static variants and introduce namespaced aliases (zlib-ng::zlib, zlib-ng::zlibstatic) with an optional ZLIB_ALIASES configuration flag. The title directly captures this main intent and is specific, clear, and concise without being vague or overly broad.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 594db7a and 7673a22.

📒 Files selected for processing (6)
  • CMakeLists.txt (6 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 (4)
  • test/pigz/CMakeLists.txt
  • test/benchmarks/CMakeLists.txt
  • test/CMakeLists.txt
  • CMakeLists.txt
⏰ 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)
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Fuzzing
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Fuzzing
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Fuzzing
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Fuzzing
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Fuzzing
  • GitHub Check: macOS GCC UBSAN (ARM64)
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Fuzzing
  • GitHub Check: macOS GCC UBSAN (ARM64)
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Fuzzing
  • GitHub Check: macOS GCC UBSAN (ARM64)
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Fuzzing
  • GitHub Check: macOS GCC UBSAN (ARM64)
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Fuzzing
  • GitHub Check: macOS GCC UBSAN (ARM64)
  • GitHub Check: Windows MSVC ARM No Test
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Fuzzing
🔇 Additional comments (2)
test/add-subdirectory-project/CMakeLists.txt (1)

13-13: Correct target name update.

The change aligns with the new target naming scheme. Using the canonical zlib-ng-static target name is the correct approach for this test.

test/fuzz/CMakeLists.txt (1)

33-33: Correct target name updates in conditional branches.

Target names properly updated to zlib-ng-static and zlib-ng. The linking logic correctly selects between static and shared variants based on the build configuration.

Also applies to: 35-35


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Sep 26, 2025

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.

@nmoinvaz
Copy link
Copy Markdown
Member

This will break a lot of downstream projects that rely on the old CMake project names.

@nmoinvaz
Copy link
Copy Markdown
Member

This might be relevant:
#723

@ccawley2011 ccawley2011 force-pushed the cmake-target branch 2 times, most recently from 5ffa3c0 to 27a9803 Compare September 26, 2025 20:07
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, but zlib-ng is only created when ZLIBNG_ENABLE_SHARED (or equivalent) is on. In a static-only build (the default on several CI jobs), this statement errors out because the zlib-ng target simply doesn't exist; previously example linked to the always-available zlib target (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 existing BUILD_SHARED_LIBS guard or, preferably, by linking via the new zlib-ng::zlib/zlib-ng::zlibstatic aliases 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

📥 Commits

Reviewing files that changed from the base of the PR and between 5ffa3c0 and 27a9803.

📒 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.txt
  • test/pigz/CMakeLists.txt
  • CMakeLists.txt

@codecov
Copy link
Copy Markdown

codecov bot commented Sep 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.47%. Comparing base (7b29794) to head (7673a22).
⚠️ Report is 1 commits behind head on develop.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ccawley2011
Copy link
Copy Markdown
Contributor Author

Half of the build directories are broken due to lack of updating...

Fixed.

This will break a lot of downstream projects that rely on the old CMake project names.

I've added optional aliases for the old names - projects can now use set(ZLIB_ALIASES OFF) to avoid the clash, while existing projects should be unaffected.

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Sep 27, 2025

This will break a lot of downstream projects that rely on the old CMake project names.

I've added optional aliases for the old names - projects can now use set(ZLIB_ALIASES OFF) to avoid the clash, while existing projects should be unaffected.

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.

@nmoinvaz
Copy link
Copy Markdown
Member

What about the GH issue where the customize the entire name?

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Sep 29, 2025

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.

@nmoinvaz
Copy link
Copy Markdown
Member

In minizip-ng I do support specifying a suffix to the project name.

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Sep 30, 2025

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.

@nmoinvaz
Copy link
Copy Markdown
Member

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.

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.

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Oct 1, 2025

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.

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.

@Dead2
Copy link
Copy Markdown
Member

Dead2 commented Oct 9, 2025

  1. I do prefer that we don't keep the name zlib/zlibstatic all over CMake, those should really only be for zlib-compat mode. So in that way I agree with this PR. ✔️
  2. Having the zlib-ng::zlib style namespacing ✔️
  3. I would have also liked to have seen support for adding custom aliases like cmake request: please provide an option to give a unique library name on all platforms #723 suggests ❌

What do you think about point 3 @ccawley2011, is this something you would want to implement as well?

@Dead2
Copy link
Copy Markdown
Member

Dead2 commented Oct 22, 2025

@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.

Copy link
Copy Markdown
Member

@Dead2 Dead2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM. Perhaps someone else wants to make a PR to add CMake target aliases

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Oct 24, 2025

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.

@ccawley2011
Copy link
Copy Markdown
Contributor Author

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 zlib-ng::zlib and zlib-ng::zlibstatic as aliases, but it would be good if @joshtriplett is able to confirm if this is good enough or not.

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Oct 26, 2025

For portable builds, we need to adjust zlib-ng-config.cmake or zlib-config.cmake so it doesn't reference CMAKE_CURRENT_LIST_DIR, and sets *_INCLUDE_DIRS to both *_BINARY_DIR and *_SOURCE_DIR, where * is either zlibor zlib-ng, in that order ... Then we can export a target, like zlib-portable or zlib-ng-portable, that doesn't exist in normal build. Each target can be associated with a component that can be used with find_package to differentiate types of builds.

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 find_package finds the portable build before the regular build.

@Dead2 Dead2 merged commit a6b98e1 into zlib-ng:develop Oct 28, 2025
155 of 156 checks passed
@Dead2 Dead2 mentioned this pull request Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants