Skip to content

Commit aae4971

Browse files
committed
Add workaround for the wrong detected include path and linkage problems with vcpkg
1 parent 50a6fdd commit aae4971

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

.github/workflows/opencv-rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
- windows-2022
6969
- macos-14
7070
vcpkg-version:
71-
- 2024.10.21
71+
- 2024.12.16
7272
runs-on: ${{ matrix.os-image }}
7373
env:
7474
VCPKG_VERSION: ${{ matrix.vcpkg-version }}

INSTALL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Installing OpenCV is easy through the following sources:
5656
* from [vcpkg](https://docs.microsoft.com/en-us/cpp/build/vcpkg), also install `llvm` package,
5757
necessary for building:
5858
```shell script
59-
vcpkg install llvm opencv4[contrib,nonfree]
59+
vcpkg install llvm opencv4[contrib,nonfree,opencl]
6060
```
6161
You most probably want to set environment variable `VCPKGRS_DYNAMIC` to "1" unless you're specifically
6262
targeting a static build.

build/library.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,20 @@ impl Library {
387387
}
388388
let opencv = opencv.ok_or_else(|| errors.join(", "))?;
389389

390-
let version = Self::version_from_include_paths(&opencv.include_paths);
390+
let mut opencv_include_paths = opencv.include_paths;
391+
// workaround for the wrong detected include path for vcpkg 2024.11.16+: https://github.com/twistedfall/opencv-rust/issues/640
392+
for include_path in &mut opencv_include_paths {
393+
if include_path.ends_with("include") {
394+
let fixed_include_path = include_path.join("opencv4");
395+
if fixed_include_path.exists() {
396+
*include_path = fixed_include_path;
397+
}
398+
}
399+
}
391400

392-
let include_paths = Self::process_env_var_list(include_paths, opencv.include_paths);
401+
let version = Self::version_from_include_paths(&opencv_include_paths);
402+
403+
let include_paths = Self::process_env_var_list(include_paths, opencv_include_paths);
393404

394405
let mut cargo_metadata = opencv.cargo_metadata;
395406

ci/install-macos-vcpkg.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export VCPKG_DEFAULT_TRIPLET=arm64-osx
2828
set +e
2929
which cmake
3030
cmake --version
31-
if ! ./vcpkg install --clean-after-build --recurse "opencv[contrib,nonfree,ade]"; then
31+
if ! ./vcpkg install --clean-after-build --recurse "opencv[contrib,nonfree,ade,opencl]"; then
3232
for log in "$VCPKG_ROOT/buildtrees"/**/*out.log; do
3333
echo "=== $log"
3434
cat "$log"

ci/install-ubuntu-vcpkg.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export VCPKG_DEFAULT_TRIPLET=x64-linux
3737
set +e
3838
which cmake
3939
cmake --version
40-
if ! ./vcpkg install --clean-after-build --recurse "opencv[contrib,nonfree,ade]"; then
40+
if ! ./vcpkg install --clean-after-build --recurse "opencv[contrib,nonfree,ade,opencl]"; then
4141
for log in "$VCPKG_ROOT/buildtrees"/**/*out.log; do
4242
echo "=== $log"
4343
cat "$log"

ci/install-windows-vcpkg.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export VCPKG_DEFAULT_TRIPLET=x64-windows
3333
set +e
3434
which cmake
3535
cmake --version
36-
if ! ./vcpkg install --clean-after-build --recurse "opencv[contrib,nonfree,ade]"; then
36+
if ! ./vcpkg install --clean-after-build --recurse "opencv[contrib,nonfree,ade,opencl]"; then
3737
for log in "$VCPKG_ROOT/buildtrees"/**/*out.log; do
3838
echo "=== $log"
3939
cat "$log"

0 commit comments

Comments
 (0)