opencv / opencv

Open Source Computer Vision Library
https://opencv.org
Apache License 2.0
75.95k stars 55.62k forks source link

Modernize CMake to CMake3 #25005

Open Ryanf55 opened 3 months ago

Ryanf55 commented 3 months ago

Purpose

Create an example of moving some CMake support to the latest supported features, including exported namespace targets.

In CMake 5, I propose removing the CMake 2 support because pretty much every OS now includes CMake 3. There is a lot of edge-case code to handle old versions of CMake. How much of this can be removed for OpenCV 5? Note that different versions of CMake can be required to either build or consume CMake. I've typically seen the build requirement version as usually newer version than the consume version requirement. Please help me identify what OpenCV 5 will require for building, and require for consuming. For example, build could be set at CMake 3.16 in line with the most current LTS release of Ubuntu of CMake. To consume, the generated scripts usually imply 2.8 to consume.

This is a draft, the intent is to gather feedback on what OpenCV 5 should do for the next release to make it easier/more robust to use in CMake. and easier to maintain the internal implementation.

Other improvements

The other main improvements are

Related Issue

Pull Request Readiness Checklist

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

opencv-alalek commented 3 months ago

if we respect OpenCV users then there should a timeframe for transition to avoid unwanted breaking of user code on OpenCV version upgrades.

Ryanf55 commented 3 months ago

if we respect OpenCV users then there should a timeframe for transition to avoid unwanted breaking of user code on OpenCV version upgrades.

  • 4.x: without regressions in default builds provide cmake3 features (if some conflicts provide them under some flag - disabled by default). This would allow testing and migration on new features on user side.
  • provide transition guidelines
  • deprecate old features and emit warning with the link on transition guidelines
  • in 5.0 switch flags of new features to ON, but keep old functionality if user specify these features OFF.
  • in 5.x/6.0 remove old functionality

I agree with all of these. The defaults for this PR scan be adjusted if we want to backport anything to 4.x. My impression was that an upgrade of the minimum required version of CMake to build on 4.x would not be allowed. If that's true, not much can change on 4.x. Much of this PR is centered on capabilities that are only available in CMake 3.5.

Ryanf55 commented 2 weeks ago

Is there any more feedback from the OpenCV team? Is there any desire to improve the CMake user experience for OpenCV5?

FantasqueX commented 3 days ago

Great work! Just a notice, if we bump cmake_minimum_required, we can use several new policy like CMP0148 and CMP0146.