Skip to content

Commit

Permalink
Add workaround for the wrong detected include path and linkage proble…
Browse files Browse the repository at this point in the history
…ms with vcpkg
  • Loading branch information
twistedfall committed Jan 10, 2025
1 parent 50a6fdd commit aae4971
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/opencv-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- windows-2022
- macos-14
vcpkg-version:
- 2024.10.21
- 2024.12.16
runs-on: ${{ matrix.os-image }}
env:
VCPKG_VERSION: ${{ matrix.vcpkg-version }}
Expand Down
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Installing OpenCV is easy through the following sources:
* from [vcpkg](https://docs.microsoft.com/en-us/cpp/build/vcpkg), also install `llvm` package,
necessary for building:
```shell script
vcpkg install llvm opencv4[contrib,nonfree]
vcpkg install llvm opencv4[contrib,nonfree,opencl]
```
You most probably want to set environment variable `VCPKGRS_DYNAMIC` to "1" unless you're specifically
targeting a static build.
Expand Down
15 changes: 13 additions & 2 deletions build/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,20 @@ impl Library {
}
let opencv = opencv.ok_or_else(|| errors.join(", "))?;

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

let include_paths = Self::process_env_var_list(include_paths, opencv.include_paths);
let version = Self::version_from_include_paths(&opencv_include_paths);

let include_paths = Self::process_env_var_list(include_paths, opencv_include_paths);

let mut cargo_metadata = opencv.cargo_metadata;

Expand Down
2 changes: 1 addition & 1 deletion ci/install-macos-vcpkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export VCPKG_DEFAULT_TRIPLET=arm64-osx
set +e
which cmake
cmake --version
if ! ./vcpkg install --clean-after-build --recurse "opencv[contrib,nonfree,ade]"; then
if ! ./vcpkg install --clean-after-build --recurse "opencv[contrib,nonfree,ade,opencl]"; then
for log in "$VCPKG_ROOT/buildtrees"/**/*out.log; do
echo "=== $log"
cat "$log"
Expand Down
2 changes: 1 addition & 1 deletion ci/install-ubuntu-vcpkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export VCPKG_DEFAULT_TRIPLET=x64-linux
set +e
which cmake
cmake --version
if ! ./vcpkg install --clean-after-build --recurse "opencv[contrib,nonfree,ade]"; then
if ! ./vcpkg install --clean-after-build --recurse "opencv[contrib,nonfree,ade,opencl]"; then
for log in "$VCPKG_ROOT/buildtrees"/**/*out.log; do
echo "=== $log"
cat "$log"
Expand Down
2 changes: 1 addition & 1 deletion ci/install-windows-vcpkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export VCPKG_DEFAULT_TRIPLET=x64-windows
set +e
which cmake
cmake --version
if ! ./vcpkg install --clean-after-build --recurse "opencv[contrib,nonfree,ade]"; then
if ! ./vcpkg install --clean-after-build --recurse "opencv[contrib,nonfree,ade,opencl]"; then
for log in "$VCPKG_ROOT/buildtrees"/**/*out.log; do
echo "=== $log"
cat "$log"
Expand Down

0 comments on commit aae4971

Please sign in to comment.