Skip to content

Address deprecated cmake version warning.#1812

Merged
Dead2 merged 1 commit intozlib-ng:developfrom
blowekamp:fix_cmake_version_warning
Dec 7, 2024
Merged

Address deprecated cmake version warning.#1812
Dead2 merged 1 commit intozlib-ng:developfrom
blowekamp:fix_cmake_version_warning

Conversation

@blowekamp
Copy link
Copy Markdown
Contributor

@blowekamp blowekamp commented Nov 26, 2024

Use cmake_minimum_required(VERSION ...<policy_max>) syntax to set the policy at the same time as the compatibile CMake version.

The CMake documentation for this call is here:
https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html

Of note is the following:

The optional <policy_max> version, if specified, must be at least the <min> version and affects policy settings as described in [Policy Settings](https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html#policy-settings). If the running version of CMake is older than 3.12, the extra ... dots will be seen as version component separators, resulting in the ...<max> part being ignored and preserving the pre-3.12 behavior of basing policies on <min>.

Summary by CodeRabbit

  • New Features

    • Enhanced configurability with new options for building features such as gzFile support, zlib compatibility, and CPU architecture detection.
    • Introduced a feature summary section for better visibility of enabled features during configuration.
  • Bug Fixes

    • Updated minimum CMake version for broader compatibility with newer features.
  • Documentation

    • Improved clarity on project configurations and options available for users during the build process.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 26, 2024

Walkthrough

The changes involve updates to multiple CMakeLists.txt files across the project, primarily focusing on the minimum required CMake version, which has been expanded from 3.5.1 to a range of 3.5.1...3.29.0. Additional configuration options have been introduced to enhance feature toggling and architecture-specific handling. The default C standard is now explicitly set to C11, and various checks for architecture-specific features have been added. The installation section has also been refined to ensure proper handling of headers and libraries based on the defined options.

Changes

File Change Summary
CMakeLists.txt - Updated minimum required CMake version to 3.5.1...3.29.0.
- Set default C standard to C11.
- Introduced new options: WITH_GZFILEOP, ZLIB_COMPAT, ZLIB_ENABLE_TESTS, WITH_BENCHMARKS, WITH_BENCHMARK_APPS, WITH_OPTIM, WITH_RUNTIME_CPU_DETECTION, WITH_MAINTAINER_WARNINGS, WITH_CODE_COVERAGE, WITH_INFLATE_STRICT, WITH_INFLATE_ALLOW_INVALID_DIST.
- Enhanced architecture-specific handling and installation section.
test/add-subdirectory-project/CMakeLists.txt - Updated minimum required CMake version to 3.5.1...3.29.0.
- Retained project name and settings for BUILD_SHARED_LIBS and ZLIB_ENABLE_TESTS.
test/fuzz/CMakeLists.txt - Updated minimum required CMake version to 3.5.1...3.29.0.
- Logic for FUZZING_ENGINE and handling of fuzzers remains unchanged.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CMake
    participant BuildSystem

    User->>CMake: Configure project
    CMake->>BuildSystem: Set minimum version (3.5.1...3.29.0)
    CMake->>BuildSystem: Set C standard (C11)
    CMake->>BuildSystem: Add options (WITH_GZFILEOP, ZLIB_COMPAT, ...)
    CMake->>BuildSystem: Check architecture-specific features
    CMake->>BuildSystem: Install headers and libraries
    BuildSystem-->>User: Build complete
Loading

Possibly related PRs

Suggested reviewers

  • Dead2

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d9e5714 and 53ce99e.

📒 Files selected for processing (3)
  • CMakeLists.txt (1 hunks)
  • test/add-subdirectory-project/CMakeLists.txt (1 hunks)
  • test/fuzz/CMakeLists.txt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • test/add-subdirectory-project/CMakeLists.txt
  • test/fuzz/CMakeLists.txt
  • CMakeLists.txt

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 0

🧹 Outside diff range and nitpick comments (3)
test/fuzz/CMakeLists.txt (1)

Line range hint 42-49: Consider modern CMake practices for test configuration

While the test configuration works, consider these improvements for better maintainability:

  1. Replace file(GLOB) with explicit test file lists to ensure deterministic builds
  2. Consider using add_test(NAME ... COMMAND ... WORKING_DIRECTORY ...) for better test isolation

Here's a suggested improvement:

-        file(GLOB FUZZER_TEST_FILES ${PROJECT_SOURCE_DIR}/*)
-        set(FUZZER_COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:${FUZZER}> ${FUZZER_TEST_FILES})
-        add_test(NAME ${FUZZER} COMMAND ${FUZZER_COMMAND})
+        # Define test files explicitly
+        set(FUZZER_TEST_FILES
+            ${PROJECT_SOURCE_DIR}/test1.txt
+            ${PROJECT_SOURCE_DIR}/test2.txt
+        )
+        add_test(NAME ${FUZZER}
+                 COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:${FUZZER}> ${FUZZER_TEST_FILES}
+                 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
CMakeLists.txt (2)

Line range hint 11-24: Consider improving error message formatting

The C standard configuration is well-implemented, but the error message formatting could be improved for better readability.

-    MESSAGE(FATAL_ERROR "CMAKE_C_STANDARD:STRING=${CMAKE_C_STANDARD} not in known standards list\n ${VALID_C_STANDARDS}")
+    message(FATAL_ERROR "CMAKE_C_STANDARD:STRING=${CMAKE_C_STANDARD} not in known standards list:\n    ${VALID_C_STANDARDS}")

Line range hint 26-35: Enhance version parsing robustness

The version parsing could benefit from error handling to catch cases where the regex patterns don't match.

 file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h.in _zlib_h_contents)
 string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([0-9]+.[0-9]+.[0-9]+).*\".*"
         "\\1" ZLIB_HEADER_VERSION ${_zlib_h_contents})
+if(NOT ZLIB_HEADER_VERSION)
+    message(FATAL_ERROR "Failed to extract ZLIB_VERSION from zlib.h.in")
+endif()
 string(REGEX REPLACE ".*#define[ \t]+ZLIBNG_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*"
         "\\1" ZLIBNG_HEADER_VERSION ${_zlib_h_contents})
+if(NOT ZLIBNG_HEADER_VERSION)
+    message(FATAL_ERROR "Failed to extract ZLIBNG_VERSION from zlib.h.in")
+endif()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0ed5ac8 and d9e5714.

📒 Files selected for processing (3)
  • CMakeLists.txt (1 hunks)
  • test/add-subdirectory-project/CMakeLists.txt (1 hunks)
  • test/fuzz/CMakeLists.txt (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • test/add-subdirectory-project/CMakeLists.txt
🔇 Additional comments (4)
test/fuzz/CMakeLists.txt (2)

Line range hint 3-41: Verify fuzzing configuration with newer CMake versions

While the fuzzing configuration looks solid, since we're now explicitly supporting CMake versions up to 3.29.0, we should verify that:

  1. The find_library behavior remains consistent across versions
  2. The target_link_libraries usage is optimal for modern CMake

Let's check for any potential improvements available in newer CMake versions:

✅ Verification successful

Based on the search results, I can now generate the final response:

Fuzzing configuration is compatible with modern CMake versions

The current fuzzing configuration follows modern CMake practices and is compatible with the supported CMake version range:

  • The find_library usage for FuzzingEngine is appropriate as it's an external dependency
  • The codebase consistently uses modern CMake target-based commands
  • Target visibility specifiers (PRIVATE/PUBLIC) are properly used throughout the codebase where needed
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for modern CMake practices in fuzzing configuration
# Expected: Identify if we can leverage newer CMake features

# Check for any find_library usage patterns that could be improved
rg "find_library\(" --type cmake

# Look for target_link_libraries patterns
rg "target_link_libraries\(" --type cmake -A 2

# Check for any existing INTERFACE, PUBLIC, or PRIVATE visibility specifiers
rg "(INTERFACE|PUBLIC|PRIVATE)" --type cmake

Length of output: 7087


1-1: LGTM: CMake version range update looks correct.

The update to use the version range syntax 3.5.1...3.29.0 aligns with the PR objective and follows CMake's recommended practice. This change:

  • Maintains backward compatibility with CMake 3.5.1
  • Sets policies up to CMake 3.29.0
  • Addresses the deprecated version warning

Let's verify the CMake policy behavior:

CMakeLists.txt (2)

1-4: Well-implemented CMake version range!

The change from a single version to a version range 3.5.1...3.29.0 effectively addresses the deprecated CMake version warnings while maintaining backward compatibility. The fallback for CMake versions below 3.12 is handled correctly.


Line range hint 6-9: Good policy management!

The conditional setting of CMP0169 to OLD is well-implemented, ensuring backward compatibility while safely handling cases where the policy doesn't exist in older CMake versions.

Comment thread CMakeLists.txt
cmake_minimum_required(VERSION 3.5.1)
cmake_minimum_required(VERSION 3.5.1...3.29.0)
if(CMAKE_VERSION VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_VERSION})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is not necessary with minimum version specified in x...y format.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From: https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html

"If the running version of CMake is older than 3.12, the extra ... dots will be seen as version component separators, resulting in the ... part being ignored and preserving the pre-3.12 behavior of basing policies on ."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, it might make sense to start requiring CMake 3.12 as a minimum? Up to maintainers here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We test zlib-ng on wide range of Linux versions and some of them don't have cmake 3.12... We avoid adding unnecessary binary packages or recompiling from sources as the current CI workflows are already pushing limits of the runners and any unnecessary additions would cause unnecessary failure. People say building newer cmake works if glibc is at least some version without actually checking what glibc version is used on each distribution and release... I've seen more than once that the bundled version is one less than what people assume it would be.

It is out of scope of each PR to repeat all the unfixed bugs in new releases when we have already downgraded CI instances to use older releases that actually can build zlib-ng successfully.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This change is compatible with versions of cmake before 3.12. Jus to be clear.

@Dead2
Copy link
Copy Markdown
Member

Dead2 commented Nov 29, 2024

A few questions;
First off, why not set the "max" version to 3.31.0? Any particular reason?
Also, what about test/pigz/CMakeLists.txt? Perhaps add cmake_policy(VERSION 3.11.0...3.29.0) to it?

To be clear, I ask out of ignorance, not because I think anything is actually wrong.

I think that this PR would be better for backwards compatibility, so unless someone has objections I will probably be merging this one instead of #1810.

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.75%. Comparing base (785444d) to head (53ce99e).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #1812       +/-   ##
============================================
+ Coverage    32.15%   77.75%   +45.60%     
============================================
  Files           67      133       +66     
  Lines         5754    10253     +4499     
  Branches      1239     2660     +1421     
============================================
+ Hits          1850     7972     +6122     
+ Misses        3644     1278     -2366     
- Partials       260     1003      +743     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@blowekamp
Copy link
Copy Markdown
Contributor Author

A few questions; First off, why not set the "max" version to 3.31.0? Any particular reason?

The intention of this patch was to address the warning and not change behavior. CMake version >3.29 will still work with the CMake code but the new changes in behavior or policies of CMake will not be in effect. This preserved the current behavior of CMake and makiesthis PR a bug fix and not change in behavior.

Also, what about test/pigz/CMakeLists.txt? Perhaps add cmake_policy(VERSION 3.11.0...3.29.0) to it?

This CMake file had not policies applied. I did not investigate further to determine what would be correct behavior of the file.

To be clear, I ask out of ignorance, not because I think anything is actually wrong.

I think that this PR would be better for backwards compatibility, so unless someone has objections I will probably be merging this one instead of #1810.

@blowekamp
Copy link
Copy Markdown
Contributor Author

Are the failing builds chronic? Does the PR need to be rebased onto master?

@Dead2
Copy link
Copy Markdown
Member

Dead2 commented Dec 3, 2024

Are the failing builds chronic? Does the PR need to be rebased onto master?

The S390X builds are down and requires some manual work to get it work again after a long pause where a working github actions runner was unavailable on S390X.

The rest would hopefully be fixed with a rebase.

Use cmake_minimum_required(VERSION <min>...<policy_max>) syntax to set
the policy at the same time as the compatibile CMake version.
@blowekamp blowekamp force-pushed the fix_cmake_version_warning branch from d9e5714 to 53ce99e Compare December 3, 2024 13:35
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.

5 participants