Skip to content

Fix zlib version parse#24741

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
FantasqueX:fix-zlib-version-parse
Dec 22, 2023
Merged

Fix zlib version parse#24741
asmorkalov merged 1 commit intoopencv:4.xfrom
FantasqueX:fix-zlib-version-parse

Conversation

@FantasqueX
Copy link
Copy Markdown
Contributor

Currently cmake scripttry to use regex to parse VER_MAJOR, VER_MINOR, VER_REVISION from ZLIB_VERSION. However, ZLIB_VERSION is "1.3" which means that there is no VER_REVISION.
You ca reproduce using "-DBUILD_ZLIB=ON"

--     ZLib:                        zlib (ver 1.3.#define ZLIB_VERSION "1.3")

I think it is OK to extract version information from VARNAME.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

${LIBNAME}_VERSION_PATCH
${LIBNAME}_VERSION_TWEAK
${LIBNAME}_VERSION_STRING)
ocv_clear_vars(${LIBNAME}_VERSION_STRING)
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.

Keep compatibility!
This macro is used not for ZLIB only.

Create a new one instead, e.g. ocv_parse_header_version and use it.

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.

Hi, thanks for the review. I add a new macro ocv_parse_header_version . However, I don't think there is compatiblity problem. There are only two libraries zlib and japser using ocv_parse_header2. Zlib and japser only use ${LIBNAME}_VERSION_STRING not ${LIBNAME}_VERSION_MAJOR etc. I think it's safe to delete ocv_parse_header2.

@FantasqueX FantasqueX force-pushed the fix-zlib-version-parse branch from 0693eb8 to 6548dfe Compare December 22, 2023 03:41
set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})

ocv_parse_header2(ZLIB "${${ZLIB_LIBRARY}_SOURCE_DIR}/zlib.h" ZLIB_VERSION)
ocv_parse_header_version(ZLIB "${${ZLIB_LIBRARY}_SOURCE_DIR}/zlib.h" ZLIB_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.

macro has 2 parameters.

Where is specified ZLIB_VERSION?

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.

Fixed

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.

We still missing ZLIB_VERSION.

CMake is switching to _VERSION variables. Others are mostly deprecated.
Perhaps we should do the same.

$ grep -R ZLIB_VERSION /usr/share/cmake/
/usr/share/cmake/Modules/FindZLIB.cmake:``ZLIB_VERSION``
/usr/share/cmake/Modules/FindZLIB.cmake:  See also legacy variable ``ZLIB_VERSION_STRING``.
/usr/share/cmake/Modules/FindZLIB.cmake:``ZLIB_VERSION_MAJOR``
/usr/share/cmake/Modules/FindZLIB.cmake:    Superseded by ``ZLIB_VERSION``.
/usr/share/cmake/Modules/FindZLIB.cmake:``ZLIB_VERSION_MINOR``
/usr/share/cmake/Modules/FindZLIB.cmake:    Superseded by ``ZLIB_VERSION``.
/usr/share/cmake/Modules/FindZLIB.cmake:``ZLIB_VERSION_PATCH``
/usr/share/cmake/Modules/FindZLIB.cmake:    Superseded by ``ZLIB_VERSION``.
/usr/share/cmake/Modules/FindZLIB.cmake:``ZLIB_VERSION_TWEAK``
/usr/share/cmake/Modules/FindZLIB.cmake:    Superseded by ``ZLIB_VERSION``.
/usr/share/cmake/Modules/FindZLIB.cmake:``ZLIB_VERSION_STRING``
/usr/share/cmake/Modules/FindZLIB.cmake:    Superseded by ``ZLIB_VERSION``.
/usr/share/cmake/Modules/FindZLIB.cmake:  The major version of zlib.  Superseded by ``ZLIB_VERSION_MAJOR``.
/usr/share/cmake/Modules/FindZLIB.cmake:  The minor version of zlib.  Superseded by ``ZLIB_VERSION_MINOR``.
/usr/share/cmake/Modules/FindZLIB.cmake:  The patch version of zlib.  Superseded by ``ZLIB_VERSION_PATCH``.
/usr/share/cmake/Modules/FindZLIB.cmake:  file(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$")
/usr/share/cmake/Modules/FindZLIB.cmake:  if(ZLIB_H MATCHES "ZLIB_VERSION \"(([0-9]+)\\.([0-9]+)(\\.([0-9]+)(\\.([0-9]+))?)?)")
/usr/share/cmake/Modules/FindZLIB.cmake:    set(ZLIB_VERSION_STRING "${CMAKE_MATCH_1}")
/usr/share/cmake/Modules/FindZLIB.cmake:    set(ZLIB_VERSION_MAJOR "${CMAKE_MATCH_2}")
/usr/share/cmake/Modules/FindZLIB.cmake:    set(ZLIB_VERSION_MINOR "${CMAKE_MATCH_3}")
/usr/share/cmake/Modules/FindZLIB.cmake:    set(ZLIB_VERSION_PATCH "${CMAKE_MATCH_5}")
/usr/share/cmake/Modules/FindZLIB.cmake:    set(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_7}")
/usr/share/cmake/Modules/FindZLIB.cmake:    set(ZLIB_VERSION_STRING "")
/usr/share/cmake/Modules/FindZLIB.cmake:    set(ZLIB_VERSION_MAJOR "")
/usr/share/cmake/Modules/FindZLIB.cmake:    set(ZLIB_VERSION_MINOR "")
/usr/share/cmake/Modules/FindZLIB.cmake:    set(ZLIB_VERSION_PATCH "")
/usr/share/cmake/Modules/FindZLIB.cmake:    set(ZLIB_VERSION_TWEAK "")
/usr/share/cmake/Modules/FindZLIB.cmake:  set(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}")
/usr/share/cmake/Modules/FindZLIB.cmake:  set(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}")
/usr/share/cmake/Modules/FindZLIB.cmake:  set(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}")
/usr/share/cmake/Modules/FindZLIB.cmake:  set(ZLIB_VERSION "${ZLIB_VERSION_STRING}")
/usr/share/cmake/Modules/FindZLIB.cmake:                                       VERSION_VAR ZLIB_VERSION

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.

Set both ZLIB_VERSION and ZLIB_VERSION_STRING? ZLIB_VERSION is introduced in cmake 3.26 which is quite modern. I'm not sure how much compatibility we should keep. Should we set other variables like ZLIB_MAJOR_VERSION? CMake(master branch)'s FindPNG module doesn't use these version string.

Currently cmake scripttry to use regex to parse VER_MAJOR, VER_MINOR,
VER_REVISION from ZLIB_VERSION. However, ZLIB_VERSION is "1.3" which
means that there is no VER_REVISION.
You can reproduce using "-DBUILD_ZLIB=ON"
```
--     ZLib:                        zlib (ver 1.3.#define ZLIB_VERSION "1.3")
```

This patch add a new macro ocv_parse_header_version to extract version
information.
@FantasqueX FantasqueX force-pushed the fix-zlib-version-parse branch from 6548dfe to 3a600db Compare December 22, 2023 05:49
Copy link
Copy Markdown
Contributor

@opencv-alalek opencv-alalek left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@asmorkalov asmorkalov merged commit a050285 into opencv:4.x Dec 22, 2023
@asmorkalov asmorkalov mentioned this pull request Jan 19, 2024
@FantasqueX FantasqueX deleted the fix-zlib-version-parse branch June 28, 2024 13:08
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