Skip to content

build: fail early when OpenCV is older than dartcv requires - #451

Merged
rainyl merged 2 commits into
rainyl:mainfrom
diegolopezrm:fix-opencv-min-version-check
Sep 4, 2026
Merged

rainyl merged 2 commits into
rainyl:mainfrom
diegolopezrm:fix-opencv-min-version-check

Conversation

@diegolopezrm

Copy link
Copy Markdown
Contributor

Summary

When DARTCV_DISABLE_DOWNLOAD_OPENCV is set and the build is pointed at an existing OpenCV through OpenCV_DIR, find_package(OpenCV REQUIRED) accepts whatever version it finds. dartcv calls a handful of APIs added in 4.12, so an older OpenCV configures cleanly and then fails well into the build, with errors that never mention the version as the cause.

This adds a version check right after find_package, so the configure step stops with a message that names the version and the path.

How the minimum was determined

I built dartcv against several OpenCV releases, each compiled from source with core,imgproc,imgcodecs,calib3d,features2d,flann,ximgproc and contrib:

OpenCV result
4.8.1 31 errors
4.10.0 11 errors
4.11.0 8 errors
4.12.0 builds

The APIs that set the floor:

API missing below
cv::Mat::reinterpret 4.12
cv::thresholdWithMask 4.12
cv::getClosestEllipsePoints 4.12
cv::fisheye::solvePnPRansac 4.12
cv::utils::logging::internal::replaceWriteLogMessage, ...Ex 4.12
cv::approxPolyN 4.11
cv::hfloat 4.10
cv::AKAZE::getMaxPoints / setMaxPoints 4.10

So 4.12 is the constant here. The download and build-from-source paths already satisfy it — DARTCV_OPENCV_VERSION defaults to 4.12.0.0 — so nothing changes for them; this only affects builds that supply their own OpenCV.

Before and after

Building against OpenCV 4.11.0 previously produced 8 errors like:

dartcv/core/mat.cpp:553:39: error: no member named 'reinterpret' in 'cv::Mat'
dartcv/imgproc/imgproc.cpp:1061:17: error: no member named 'thresholdWithMask' in namespace 'cv'

and against 4.8.1, 31 of them, starting with a missing cv::hfloat in core/lut.hpp. Neither points at the real problem.

Now:

CMake Error at cmake/download_setup_opencv.cmake:144 (message):
  dartcv requires OpenCV 4.12 or newer, but found 4.11.0 in
  /path/to/inst-4.11.0/lib/cmake/opencv4.

Verification

  • OpenCV 4.8.1 and 4.11.0 → configure stops with the message above.
  • OpenCV 4.12.0 → configures and builds exactly as before; libdartcv.dylib (12 MB) with ximgproc and calib3d linked in.

Tested on macOS arm64 with each OpenCV built from source. Happy to phrase the message differently, or to move the check into CMakeLists.txt if you would rather keep download_setup_opencv.cmake to download logic only.

A build pointed at an existing OpenCV through OpenCV_DIR accepts whatever
version it finds. dartcv calls APIs introduced in 4.12 — Mat::reinterpret,
cv::thresholdWithMask, cv::getClosestEllipsePoints, fisheye::solvePnPRansac
and replaceWriteLogMessage — so an older one configures cleanly and then
fails deep into the build with errors that never mention the version.

Measured by building dartcv against each release:

  4.8.1   31 errors
  4.10.0  11 errors
  4.11.0   8 errors
  4.12.0  builds

The configure step now stops with the version and the path it found,
instead of leaving the reader to infer it from a missing 'cv::hfloat'.
The floor applies however OpenCV arrives. Building an older release from
source configures and compiles OpenCV happily, and only fails once dartcv
itself is compiled against it, which is the same late and unexplained
failure the previous commit removed for the bring-your-own path.
@rainyl

rainyl commented Sep 4, 2026

Copy link
Copy Markdown
Owner

@diegolopezrm Hi

Thanks for the suggestions.

I never anticipated that users would use their own compiled OpenCV, but this defensive strategy sounds okay. will merge it without changes.

Thanks again~

@rainyl rainyl self-assigned this Sep 4, 2026
@rainyl
rainyl merged commit 004baed into rainyl:main Sep 4, 2026
5 checks passed
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.24%. Comparing base (eb1f4ce) to head (600d6a7).
⚠️ Report is 1 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #451   +/-   ##
=======================================
  Coverage   92.24%   92.24%           
=======================================
  Files          60       60           
  Lines       11869    11869           
=======================================
  Hits        10948    10948           
  Misses        921      921           
Flag Coverage Δ
unittests 92.24% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants