Skip to content

Rename cmake target files to avoid overwrite of PACKAGE_VERSION#1988

Merged
Dead2 merged 1 commit intozlib-ng:developfrom
bebuch:develop
Oct 28, 2025
Merged

Rename cmake target files to avoid overwrite of PACKAGE_VERSION#1988
Dead2 merged 1 commit intozlib-ng:developfrom
bebuch:develop

Conversation

@bebuch
Copy link
Copy Markdown
Contributor

@bebuch bebuch commented Oct 23, 2025

Originally there where these 5 CMake config files installed:

ZLIB-release.cmake
ZLIB-debug.cmake
ZLIB.cmake
zlib-config-version.cmake
zlib-config.cmake

The file zlib-config-version.cmake is executed by CMake in a private scope, so the changes it make to variables like PACKAGE_VERSION don't leak into the scope where find_package is called.

The problem was, that the CMake generated ZLIB.cmake includes all files that match the pattern ZLIB-*.cmake. That's fine on case sensitive filesystems, but on Windows this triggers the execution of zlib-config-version.cmake.

So any call of find_package(ZLIB) overwrites PACKAGE_VERSION. In case of LLVM I get lld and clang in version 1.3.1 instead of 24.1.4. The worst thing is, that LLVM compiles fine. Only after using libclang with Qt6 I got the very strange error, that clang was found in version 1.3.1.

However, renaming the target files with the common -targets postfix solves this problem.

ZLIB-targets-release.cmake
ZLIB-targets-debug.cmake
ZLIB-targets.cmake

I think that is completly backwards compatible.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 23, 2025

Walkthrough

Changed CMake install/export target names to produce separate "-targets.cmake" files and updated config template includes to reference those "-targets.cmake" files instead of the previous target scripts.

Changes

Cohort / File(s) Summary
CMake export installation
CMakeLists.txt
install(TARGETS ... EXPORT ${EXPORT_NAME})install(TARGETS ... EXPORT ${EXPORT_NAME}-targets) and install(EXPORT ${EXPORT_NAME} ...)install(EXPORT ${EXPORT_NAME}-targets FILE "${EXPORT_NAME}-targets.cmake" ...) to emit a separate -targets.cmake export file.
Config templates
zlib-config.cmake.in, zlib-ng-config.cmake.in
Updated include lines to load the new targets files: include("${CMAKE_CURRENT_LIST_DIR}/ZLIB.cmake")include("${CMAKE_CURRENT_LIST_DIR}/zlib-targets.cmake") and include("${CMAKE_CURRENT_LIST_DIR}/zlib-ng.cmake")include("${CMAKE_CURRENT_LIST_DIR}/zlib-ng-targets.cmake").

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant CM as CMake (configure/install)
  participant FS as Installed files
  participant CT as Config templates

  rect rgba(40,120,200,0.06)
    CM->>FS: install(EXPORT ${EXPORT_NAME}-targets FILE "${EXPORT_NAME}-targets.cmake" ...)
    Note right of FS: Produces\n- ${EXPORT_NAME}-config.cmake\n- ${EXPORT_NAME}-targets.cmake
  end

  rect rgba(100,180,100,0.06)
    CT->>FS: include("${CMAKE_CURRENT_LIST_DIR}/${EXPORT_NAME}-targets.cmake")
    Note right of CT: `zlib-config.cmake.in` and `zlib-ng-config.cmake.in` now include targets file
  end
Loading

Suggested reviewers

  • Dead2

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "Rename cmake target files to avoid overwrite of PACKAGE_VERSION" accurately reflects the core changes made in the changeset. The title specifically describes the main action (renaming cmake target files) and the primary motivation (avoiding PACKAGE_VERSION overwrite). The changeset modifications across CMakeLists.txt and the config files consistently implement this renaming by adding the -targets suffix to export and include directives. The title is clear, concise, and sufficiently specific for a developer scanning history to understand the primary change.
Description Check ✅ Passed The pull request description is directly related to the changeset and provides meaningful context for the modifications. It explains the problem on case-insensitive filesystems where zlib-config-version.cmake is accidentally matched and executed due to the ZLIB-*.cmake pattern, resulting in PACKAGE_VERSION being overwritten. The description clearly connects this issue to the proposed solution of renaming target files with the -targets suffix, which aligns with the actual changes in CMakeLists.txt and the config files. The description is not vague and communicates a genuine problem being solved, meeting the lenient pass criteria.
✨ 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 c05c1ef and 0df475f.

📒 Files selected for processing (3)
  • CMakeLists.txt (2 hunks)
  • zlib-config.cmake.in (1 hunks)
  • zlib-ng-config.cmake.in (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • 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). (120)
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2022 v140 Win64
  • GitHub Check: Windows MSVC ARM64 No Test
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC 2022 v143 Win64 C17
  • GitHub Check: EL10 Clang S390X DFLTCC MSAN
  • GitHub Check: Ubuntu MinGW i686
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2022 v140 Win64
  • GitHub Check: Windows MSVC ARM64 No Test
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC 2022 v143 Win64 C17
  • GitHub Check: EL10 Clang S390X DFLTCC MSAN
  • GitHub Check: Ubuntu MinGW i686
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2022 v140 Win64
  • GitHub Check: Windows MSVC ARM64 No Test
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC 2022 v143 Win64 C17
  • GitHub Check: EL10 Clang S390X DFLTCC MSAN
  • GitHub Check: Ubuntu MinGW i686
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2022 v140 Win64
  • GitHub Check: Windows MSVC ARM64 No Test
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC 2022 v143 Win64 C17
  • GitHub Check: EL10 Clang S390X DFLTCC MSAN
  • GitHub Check: Ubuntu MinGW i686
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2022 v140 Win64
  • GitHub Check: Windows MSVC ARM64 No Test
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC 2022 v143 Win64 C17
  • GitHub Check: EL10 Clang S390X DFLTCC MSAN
  • GitHub Check: Ubuntu MinGW i686
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2022 v140 Win64
  • GitHub Check: Windows MSVC ARM64 No Test
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC 2022 v143 Win64 C17
  • GitHub Check: EL10 Clang S390X DFLTCC MSAN
  • GitHub Check: Ubuntu MinGW i686
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2022 v140 Win64
  • GitHub Check: Windows MSVC ARM64 No Test
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC 2022 v143 Win64 C17
  • GitHub Check: EL10 Clang S390X DFLTCC MSAN
  • GitHub Check: Ubuntu MinGW i686
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2022 v140 Win64
  • GitHub Check: Windows MSVC ARM64 No Test
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC 2022 v143 Win64 C17
  • GitHub Check: EL10 Clang S390X DFLTCC MSAN
  • GitHub Check: Ubuntu MinGW i686
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2022 v140 Win64
  • GitHub Check: Windows MSVC ARM64 No Test
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC 2022 v143 Win64 C17
  • GitHub Check: EL10 Clang S390X DFLTCC MSAN
  • GitHub Check: Ubuntu MinGW i686
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2022 v140 Win64
  • GitHub Check: Windows MSVC ARM64 No Test
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v142 Win32
  • GitHub Check: Windows MSVC 2022 v143 Win64 C17
  • GitHub Check: EL10 Clang S390X DFLTCC MSAN
  • GitHub Check: Ubuntu MinGW i686
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
🔇 Additional comments (2)
zlib-ng-config.cmake.in (1)

8-8: LGTM! Correctly references the targets file generated by CMakeLists.txt.

The include statement properly references zlib-ng-targets.cmake, which is the export file generated by the CMakeLists.txt install(EXPORT) command. Both zlib-ng-config.cmake.in and zlib-config.cmake.in follow the same pattern consistently, using their respective export names (zlib-ng and ZLIB) to reference the generated targets files.

zlib-config.cmake.in (1)

10-10: LGTM! Include statement correctly updated to new targets file naming.

The change from ZLIB.cmake to ZLIB-targets.cmake aligns with the PR objectives to avoid wildcard pattern conflicts on case-insensitive filesystems. Verification confirms:

  • CMakeLists.txt line 1518 correctly generates ZLIB-targets.cmake via install(EXPORT ${EXPORT_NAME}-targets) when EXPORT_NAME=ZLIB (ZLIB_COMPAT mode)
  • zlib-config.cmake.in is only used when ZLIB_COMPAT=ON, where the hardcoded reference is correct
  • No stale references to the old filename remain

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.

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.14%. Comparing base (7b29794) to head (0df475f).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1988      +/-   ##
===========================================
+ Coverage    81.40%   83.14%   +1.74%     
===========================================
  Files          161      161              
  Lines        13748    12960     -788     
  Branches      3149     3149              
===========================================
- Hits         11191    10776     -415     
+ Misses        1533     1153     -380     
- Partials      1024     1031       +7     

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

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Oct 26, 2025

We are officially supporting building zlib-ng for Windows and thus also support case-insensitive file systems... This seems quite clean workaround to me, even though on updates, it does require manually deleting the old target files to work as intended.

Copy link
Copy Markdown
Collaborator

@mtl1979 mtl1979 left a comment

Choose a reason for hiding this comment

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

According to CMake documentation default of FILE parameter depends on EXPORT parameter of install() command. Documentation suggests customizing EXPORT parameter directly.

@bebuch bebuch marked this pull request as ready for review October 27, 2025 09:55
@bebuch bebuch requested a review from mtl1979 October 27, 2025 09:56
@bebuch
Copy link
Copy Markdown
Contributor Author

bebuch commented Oct 27, 2025

Ready for next review! :-)

Sorry for noise, I missunderstood your suggestion in the first shot and didn't test offline carfully, Now it should be fine ;-)

Copy link
Copy Markdown
Collaborator

@mtl1979 mtl1979 left a comment

Choose a reason for hiding this comment

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

LGTM.

@Dead2 Dead2 merged commit 33f4dc4 into zlib-ng:develop Oct 28, 2025
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants