cmake: fix#29028 macOS dynamic framework RPATH for relocatable install #29396
### Problem
When building OpenCV as a dynamic framework on macOS (`-DAPPLE_FRAMEWORK=ON -DBUILD_SHARED_LIBS=ON`), installed binaries contain an absolute `LC_RPATH` pointing to the build tree, making the install non-relocatable. Moving the install directory or deploying to another Mac causes binaries to crash on launch.
### Root cause
`cmake/OpenCVInstallLayout.cmake` unconditionally sets `CMAKE_INSTALL_RPATH` to `${CMAKE_INSTALL_PREFIX}/${OPENCV_LIB_INSTALL_PATH}` for all platforms. Additionally, `cmake/platforms/OpenCV-Darwin.cmake` was empty and missing the `@executable_path`/`@loader_path` linker flags that the iOS toolchain already sets for the same `APPLE_FRAMEWORK AND BUILD_SHARED_LIBS` case.
### Fix
- Guard `CMAKE_INSTALL_RPATH` in `OpenCVInstallLayout.cmake` to use relocatable `@executable_path` tokens for Apple framework builds
- Add equivalent linker flags to `OpenCV-Darwin.cmake`, mirroring `platforms/ios/cmake/Modules/Platform/iOS.cmake`
Fixes#29028
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] 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
The first-class-language OpenCV CMake config (OpenCVConfig-CUDALanguage.cmake.in)
pinned the consumer's CUDA Toolkit to the exact patch version OpenCV was built
with (e.g. 12.3.107), via find_package(CUDAToolkit ... EXACT) and a full
VERSION_EQUAL check. Patch versions change frequently while the CUDA runtime API
is stable within a minor release, so this forced needless rebuilds and could
FATAL_ERROR even for a matching toolkit.
Per the core team's direction on #26966, the change lives in the installed
config template rather than the build scripts, and is controlled by a
consumer-set variable:
- Default: match major.minor only (fixes the reported patch-pinning bug).
- OPENCV_STRONG_CUDA_VERSION_CHECK: restore the exact full-version match.
The build-time detection (OpenCVDetectCUDALanguage.cmake) is left untouched, so
OpenCV_CUDA_VERSION still records the full version for diagnostics.
Fixes#26965
Fix CMake crash when CUDA arch autodetection comes up empty #28954
With CUDA 13 and a system gcc that the toolkit does not support, every NVCC probe inside ocv_filter_available_architecture fails and the result list ends up empty. The next line then calls list(GET ... -1) on that empty list, so CMake dies with the unhelpful message about list GET given empty list and the user has no obvious next step. This change replaces that path with a fatal error that points at the three real fixes, namely setting CUDA_ARCH_BIN, setting CUDA_HOST_COMPILER, or enabling OPENCV_CMAKE_CUDA_DEBUG to see what NVCC actually printed. It also forwards CMAKE_CUDA_HOST_COMPILER into CUDA_HOST_COMPILER since the issue reporter passed the standard CMake variable and it was being silently ignored.
Fixes#28952
Add ARMPL support for DFT Function #28664
- This PR introduces hal/armpl/ with implementation of 1D, 2D DFT and DCT routines using ARM Performance Libraries as a custom HAL replacement for OpenCV's DFT & DCT Function.
- ArmPL MSI package is automatically downloaded and extracted via CMake when building on Windows ARM64, with a WITH_ARMPL option that defaults to ON for that platform.
- Forward and inverse real DFT calls in dxt.cpp are routed through ArmPL when available, with scaling applied only when needed.
- Test error thresholds in test_dxt.cpp are relaxed (from 1e-5 to 2e-4 for float ) to account for numerical differences between ArmPL and OpenCV's reference DFT results.
**Performance Benchmarks :**
<img width="993" height="835" alt="image" src="https://github.com/user-attachments/assets/76def647-6d20-4bce-8bc9-7363e723669f" />
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
cmake: fix PNG status display when BUILD_PNG=ON #28995
### Description
Fixes#28657.
On macOS (and other Apple platforms), `BUILD_PNG=ON` is the default. The build system correctly clears `PNG_FOUND` in `OpenCVFindLibsGrfmt.cmake` and builds libpng from the bundled source. However, during the subsequent module processing phase, a downstream `find_package(PNG)` call — triggered transitively via `include()` in the **same scope** — overwrites not only `PNG_FOUND`, but also `PNG_INCLUDE_DIR`, `PNG_LIBRARIES`, and `PNG_VERSION_STRING`.
#### Root Cause: FindPNG.cmake Has Asymmetric Guards
Reading CMake 4.3's `FindPNG.cmake` (`/opt/homebrew/share/cmake/Modules/FindPNG.cmake`) reveals:
| Variable | Guard? | Fate |
|---|---|---|
| `PNG_LIBRARY` | `if(NOT PNG_LIBRARY)` at line 138 — **guarded** | Preserved |
| `PNG_PNG_INCLUDE_DIR` | `find_path(...)` at line 115 — **no guard** | **Overwritten** |
| `PNG_INCLUDE_DIR` | Derived from `PNG_PNG_INCLUDE_DIR` | **Chain-overwritten** |
| `PNG_LIBRARIES` | Derived from `PNG_LIBRARY` + `ZLIB_LIBRARY` | **Partly overwritten** |
| `PNG_VERSION_STRING` | Parsed from `PNG_PNG_INCLUDE_DIR/png.h` | **Overwritten** |
`PNG_LIBRARY` survives because FindPNG itself checks `if(NOT PNG_LIBRARY)`. But `find_path(PNG_PNG_INCLUDE_DIR)` runs unconditionally — re-searching and overwriting the bundled path with the system one.
#### Fix: Three Coordinated Changes
**Part A — Status guard** (`CMakeLists.txt`): When `BUILD_PNG=ON`, pass `FALSE` as the condition to always show `"build"` regardless of `PNG_FOUND`.
**Part B — Variable lock** (`cmake/OpenCVFindLibsGrfmt.cmake`): After building from bundled source, lock `PNG_PNG_INCLUDE_DIR` as `CACHE INTERNAL`. CMake's `find_path()` checks the cache first — if the variable exists with a valid path, it skips re-searching. The system path is never found.
**Part C — Cache cleanup** (`cmake/OpenCVFindLibsGrfmt.cmake`): Add `PNG_PNG_INCLUDE_DIR` to the `ocv_clear_internal_cache_vars()` call in the `else` branch. When a user switches `BUILD_PNG=OFF`, the cached variable is cleared, allowing `find_path` to search for the system libpng normally. Prevents stale cache leakage across configuration changes.
#### Verification (macOS 26, CMake 4.3, Homebrew libpng 1.6.58)
```
BEFORE downstream find_package(PNG):
PNG_LIBRARY = libpng
PNG_INCLUDE_DIR = .../3rdparty/libpng
PNG_VERSION_STRING = 1.6.37
AFTER downstream find_package(PNG) [with fix]:
PNG_LIBRARY = libpng ← preserved (FindPNG guard)
PNG_INCLUDE_DIR starts with .../3rdparty/libpng ← locked (Part B)
PNG_VERSION_STRING = 1.6.53 ← from bundled png.h
Status display: build (ver 1.6.53) ← correct (Part A)
```
The full reproduction and analysis are in the attached `bugReview/` directory.
### Checklist
- [x] There is a reference to the original bug report and related work
- [x] The test case is in `bugReview/` directory
- [x] Tested on macOS 26 (arm64) with CMake 4.3 + Homebrew libpng 1.6.58
- [x] Cache hygiene verified for BUILD_PNG ON→OFF→ON transitions
Fix Clp library detection for vcpkg on Windows #28423
## Problem
Building OpenCV with `WITH_CLP=ON` on Windows (vcpkg) fails:
LINK : fatal error LNK1181: cannot open input file 'libClp.lib'
vcpkg generates `Clp.lib` and `CoinUtils.lib`, but OpenCV expected `libClp.lib`/`libCoinUtils.lib`.
## Solution
Modernize CLP detection with a robust, platform-aware approach:
1. **CMake `find_package(Clp CONFIG)`**: detects vcpkg and uses imported targets (`Coin::Clp`, `Coin::CoinUtils`)
2. **Fallback**: pkg-config on Unix/Linux
3. **Skip** Android/iOS
## Benefits
✅ Fixes Windows build with vcpkg
✅ Uses modern CMake targets
✅ Backward compatible with Unix/Linux
✅ Safe for CI and mobile builds
✅ Graceful fallback if CLP unavailable
## Testing
- **Windows 11 + vcpkg**: build succeeds
- **No CLP installed**: configure/build succeeds
- **Linux/Unix**: existing workflows unaffected
- **Android/iOS**: properly skipped
## Changes
- Update `cmake/OpenCVFindLibsPerf.cmake`
- Replace hardcoded library names with CMake targets
- Add mobile platform guards
- Preserve backward compatibility
Fixes#26592
---
### Pull Request Readiness Checklist
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch (`4.x`)
- [x] There is a reference to the original bug report and related work (#26592)
- [x] The feature is well documented and sample code can be built with the project CMake
- [x] No additional tests required - this is a build system fix that maintains existing functionality
build: fix bundled protobuf headers being overridden by system-installed protobuf #28745
On macOS with Apple Clang 17, the compiler implicitly injects `/usr/local/include` as a high-priority user include (`-I`). The `SYSTEM` keyword in `target_include_directories` emits `-isystem` for the bundled protobuf path, which is searched after user `-I` paths, allowing a system-installed protobuf v4+ (which requires C++17 and abseil-cpp) to override the bundled headers.
Removing `SYSTEM` causes CMake to emit `-I` instead of `-isystem`, placing the bundled path before the implicit system include, restoring the intended header resolution order regardless of what protobuf version is installed on the host.
### Background
Apple Clang 17 (shipped with macOS 26 Tahoe Command Line Tools) changed the compiler driver behavior: it now unconditionally adds `-I/usr/local/include` to the search path, which is where Homebrew installs headers. Previous Apple Clang versions either omitted this path or added it as a lower-priority system include.
When Homebrew's `protobuf` is installed (v4+, e.g. `33.4_1`), its headers at `/usr/local/include/google/protobuf/` are resolved before the bundled `3rdparty/protobuf/src/` because `SYSTEM PUBLIC` in `target_include_directories` causes the bundled path to be emitted as `-isystem`, which ranks below `-I` in compiler search order. This was confirmed by inspecting the generated `flags.make`:
```
# before fix
-isystem /path/to/opencv/3rdparty/protobuf/src
# after fix
-I /path/to/opencv/3rdparty/protobuf/src (first in the include list)
```
The system protobuf v4+ headers require C++17 and abseil-cpp. Since OpenCV 4.x compiles with `-std=c++11`, every translation unit in `3rdparty/protobuf/` fails:
```
/usr/local/include/google/protobuf/port_def.inc: error: Protobuf only supports C++17 and newer.
/usr/local/include/absl/base/policy_checks.h: error: C++ versions less than C++17 are not supported.
```
Note that `include_directories(BEFORE ...)` on the line above was intended to prevent exactly this, but it was overridden by `target_include_directories(SYSTEM PUBLIC ...)` deduplicating the path into a single `-isystem` entry. This is essentially the same class of problem tracked in #13328.
### Impact
The change is a one-line diff. Removing `SYSTEM` has no effect on Linux or Windows since those toolchains do not inject `/usr/local/include` implicitly. Warning suppression for protobuf headers in dependent modules is unaffected because OpenCV already applies explicit `-Wno-*` flags for all protobuf-related warnings in `3rdparty/protobuf/CMakeLists.txt`.
### Tested on
- macOS 26.3 (Tahoe), Apple Clang 17.0.0 (`clang-1700.6.4.2`), Homebrew `protobuf 33.4_1`, full build passes with `BUILD_PROTOBUF=ON`.
Fixes#28743, related to #27886.
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] 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
On systems like OpenBSD, CBLAS functions are provided by a standalone
libcblas that is not returned by find_package(LAPACK). This caused link
failures when building libopencv_core because cblas_sgemm and friends
from hal_internal.cpp could not be resolved.
Fixes#28768
- Replace execute_process(tar) with file(ARCHIVE_EXTRACT) for native .zip support
and better Windows path handling when CMAKE_VERSION >= 3.18
- Replace execute_process copy with file(COPY) and existence check for reliable
CMakeLists.txt copying to avoid timing/path issues on Windows
- Maintains backward compatibility with older CMake versions and Linux behavior
Fixes issue #28608
Introduce option to generate Java code with finalize() or Cleaners interface #28159
Closes https://github.com/opencv/opencv/issues/22260
Replaces https://github.com/opencv/opencv/pull/23467
The PR introduce configuration option to generate Java code with Cleaner interface for Java 9+ and old-fashion finalize() method for old Java and Android. Mat class and derivatives are manually written. The PR introduce 2 base classes for it depending on the generator configuration.
Pros:
1. No need to implement complex and error prone cleaner on library side.
2. No new CMake templates, easier to modify code in IDE.
Cons:
1. More generator branches and different code for modern desktop and Android.
TODO:
- [x] Add Java version check to cmake
- [x] Use Cleaners for ANDROID API 33+
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
Enabled fp16 conversions, but disabled NEON FP16 arithmetics on Windows for ARM for now #27897
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
e.g.
contrib\modules\cudev\include\opencv2\cudev/ptr2d/warping.hpp(86): warning C4505: 'cv::cudev::affineMap': unreferenced function with internal linkage has been removed
contrib\modules\cudev\include\opencv2\cudev/ptr2d/warping.hpp(134): warning C4505: 'cv::cudev::perspectiveMap': unreferenced function with internal linkage has been removed
### Pull Request Readiness Checklist
resolves#16295
```
docker run --gpus 0 -v ~/opencv:/opencv -v ~/opencv_contrib:/opencv_contrib -it nvidia/cuda:12.8.1-cudnn-devel-ubuntu22.04
apt-get update && apt-get install -y cmake python3-dev python3-pip python3-venv &&
python3 -m venv .venv &&
source .venv/bin/activate &&
pip install -U pip &&
pip install -U numpy &&
pip install torch --index-url https://download.pytorch.org/whl/cu128 &&
cmake \
-DWITH_OPENCL=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_DOCS=OFF \
-DWITH_CUDA=ON \
-DOPENCV_DNN_CUDA=ON \
-DOPENCV_EXTRA_MODULES_PATH=/opencv_contrib/modules \
-DBUILD_LIST=ts,cudev,python3 \
-S /opencv -B /opencv_build &&
cmake --build /opencv_build -j16
export PYTHONPATH=/opencv_build/lib/python3/:$PYTHONPATH
```
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
Refactor Blackwell #27537
In CUDA 13:
- 10.0 is b100/b200 same for aarch64 (gb200)
- 10.3 is GB300
- 11.0 is Thor with new OpenRm driver (moves to SBSA)
- 12.0 is RTX/RTX PRO
- 12.1 is Spark GB10
Thor was moved from 10.1 to 11.0 and Spark is 12.1.
Related patch: https://github.com/pytorch/pytorch/pull/156176
Fix compilation problems with MSVC+Cuda 12.9 #27522
fix for #27521
Actually, when ENABLE_CUDA_FIRST_CLASS_LANGUAGE is enabled, the fix it not necessary. However, even when ENABLE_CUDA_FIRST_CLASS_LANGUAGE is enabled, I have checked that the fix is harmless So I propose to keep it simple for now and enable the fix whatever the state of ENABLE_CUDA_FIRST_CLASS_LANGUAGE
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [X] The PR is proposed to the proper branch
- [X] 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
eigen: fix to get version from eigen after v3.4.0 #27536
Close https://github.com/opencv/opencv/issues/27530
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] 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
Close https://github.com/opencv/opencv/issues/27413
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] 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
Update hash for the fastcv libs for both Linux and Android #27340
Replaces https://github.com/opencv/opencv/pull/27290
Updated libs PR: https://github.com/opencv/opencv_3rdparty/pull/95
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
Extract all HALs from 3rdparty to dedicated folder. #27252
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
build: Check supported C++ standard features and user setting #27107Close#27105
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] 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.
- [x] The feature is well documented and sample code can be built with the project CMake
cuda: Force C++17 Standard for CUDA targets when CUDA Toolkit >=12.8 #27112
Fix https://github.com/opencv/opencv/issues/27095.
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
Fixed AVIF linkage on Windows #26762Closes#26747
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] 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