-
-
Notifications
You must be signed in to change notification settings - Fork 55.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use zlib target instead of ZLIB_INCLUDE_DIRS and ZLIB_LIBRARIES #25569
base: 4.x
Are you sure you want to change the base?
Conversation
0b785fc
to
bb70678
Compare
bb70678
to
a5d85bd
Compare
|
@asmorkalov Hi, thanks for your review. Could you provide your CMake command and some information about your environment? So, I could try to reproduce the error :) |
It happens with all Linux environments in CI. Pipelines: https://github.com/opencv/ci-gha-workflow/tree/main/.github/workflows, Dockerfiles: https://github.com/opencv-infrastructure/opencv-gha-dockerfile. Also you can extract all commands and env settings from CI raw log. |
I found the problem which only occurs when CMake < 3.18. https://cmake.org/cmake/help/latest/command/add_library.html
|
The configure issue on Android seems to be resolved on my machine. However, I don't fully understand. Any suggestion is welcome :) |
@asmorkalov Hi, could you please approve the workflow and review this PR :) |
I think I should give up. I'm unable to fix those failing checks. |
@FantasqueX let me try to help. |
see sturkmen72@853f838 i tested it on Windows. |
@asmorkalov Hi, thanks to @sturkmen72 we fix a bug in this PR. Could you please approve the workflow again?😊 |
iOS:
|
I pushed a commit to fix iOS build according to https://stackoverflow.com/questions/25676277/cmake-target-include-directories-prints-an-error-when-i-try-to-add-the-source |
@asmorkalov Hi, could you please approve the workflow? |
@asmorkalov Hi, could you please approve the workflow again? I fixed the test locally. |
1 similar comment
@asmorkalov Hi, could you please approve the workflow again? I fixed the test locally. |
3rdparty/zlib-ng/CMakeLists.txt
Outdated
if(NOT BUILD_SHARED_LIBS) | ||
ocv_install_target(${ZLIB_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should break static linkage, if OpenCV is build against own zlib-ng, but not system-wide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for late reply. This ocv_install_target
statement isn't removed. It is moved to outer space because both static linkage and dynamic linkage need this statement in Android build. So, this will only affect dynamic linkage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not redistribute system or sysroot libraries even for static OpenCV builds. Only own 3rdparty built binaries are redistributed.
Which builder configuration does check of your modification?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/opencv/ci-gha-workflow/blob/main/.github/workflows/OCV-PR-4.x-Android-Test.yaml
However, I cannot find previous build failure log.
@@ -75,7 +75,7 @@ if(MSVC) | |||
endif(MSVC) | |||
|
|||
add_library(${PNG_LIBRARY} STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${lib_srcs} ${lib_hdrs}) | |||
target_link_libraries(${PNG_LIBRARY} ${ZLIB_LIBRARIES}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_LIBRARY
is not used in documentation. Only _LIBRARIES
is there:
https://cmake.org/cmake/help/book/mastering-cmake/chapter/Finding%20Packages.html
The same is related to FindZLIB: https://cmake.org/cmake/help/latest/module/FindZLIB.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Previously OpenCV used this variable. So, I used it. Essentially, we just need a name for interface library if we link system zlib and target library if we build zlib manually.
3rdparty/zlib-ng/CMakeLists.txt
Outdated
if(NOT BUILD_SHARED_LIBS) | ||
ocv_install_target(${ZLIB_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not redistribute system or sysroot libraries even for static OpenCV builds. Only own 3rdparty built binaries are redistributed.
Which builder configuration does check of your modification?
@FantasqueX please rebase the patch and fix conflicts. |
I think I can rebase the patch this weekend :) |
Currently, when one target needs zlib as a dependency, it needs to use both ocv_include_directories and target_link_libraries. However in modern CMake, only target_link_libraries is needed if zlib has a target_include_directories. In this patch, if zlib is found by find_package, an ALIAS target zlib will be created. CMake >= 3.1 ensures a target ZLIB::ZLIB. https://cmake.org/cmake/help/latest/module/FindZLIB.html If zlib is built, an library target zlib will be created.
7bbc378
to
fce4fa0
Compare
@asmorkalov Could you please elaborate why those changes cause breakage? I still hope this patch will be merged. |
Currently, when one target needs zlib as a dependency, it needs to use both ocv_include_directories and target_link_libraries. However in modern CMake, only target_link_libraries is needed if zlib has a target_include_directories. In this patch, if zlib is found by find_package, an ALIAS target zlib will be created. CMake >= 3.1 ensures a target ZLIB::ZLIB.
https://cmake.org/cmake/help/latest/module/FindZLIB.html
If zlib is built, an library target zlib will be created.
Tested zlib (built or found) and zlib-ng each with libpng, libtiff and openexr on Windows and ArchLinux.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.