Skip to content

[opencv4] find_package(opencv ..) fails for statically built opencv4 port with minimal features #20529

@horenmar

Description

@horenmar

I wanted to build opencv4 port with minimal features to speed up from-scratch builds, and reduce its size in cache. The build passes, but calls to find_package(OpenCV ...) in the project's CMakeLists.txt then fails with error about failing to find protobuf.

Host Environment

  • OS: Confirmed on Windows and Linux, likely OS-independent
  • Compiler: Does not seem to depend on compiler version, reproduced it with both gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, and latest MSVC.

To Reproduce
To reproduce, configure the minimal project below with vcpkg's manifest mode with a triplet that builds opencv as static library (this is the default on Linux, I originally found this using a custom triplet on Windows).

Minimal reproducing project:

vcpkg.json

{
  "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
  "name": "opencv-reproducer",
  "version": "0.0.0",
  "dependencies": [
    {
      "name": "opencv4",
      "default-features": false,
      "features": []
    }
  ]
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.20)

project(opencv-user LANGUAGES CXX)

find_package(OpenCV REQUIRED COMPONENTS opencv_core CONFIG)

Failure logs

CMake Error at /mnt/c/ubuntu/vcpkg/scripts/buildsystems/vcpkg.cmake:786 (_find_package):
  Could not find a package configuration file provided by "Protobuf" with any
  of the following names:

    ProtobufConfig.cmake
    protobuf-config.cmake

  Add the installation prefix of "Protobuf" to CMAKE_PREFIX_PATH or set
  "Protobuf_DIR" to a directory containing one of the above files.  If
  "Protobuf" provides a separate development package or SDK, be sure it has
  been installed.
Call Stack (most recent call first):
  /usr/share/cmake-3.21/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  linux-build/vcpkg_installed/x64-linux/share/opencv/OpenCVModules.cmake:15 (find_dependency)
  linux-build/vcpkg_installed/x64-linux/share/opencv/OpenCVConfig.cmake:126 (include)
  /mnt/c/ubuntu/vcpkg/scripts/buildsystems/vcpkg.cmake:786 (_find_package)
  CMakeLists.txt:5 (find_package)

Additional context

I tested two workarounds, one is to enable dnn feature which marks protobuf as dependency of opencv, the other is to explicitly add protobuf dependency to my project.

Both worked, but are not ideal for obvious reasons 😃

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions