Paul Jurczak
Paul Jurczak

Reputation: 8127

cmake could not find a package configuration file provided by "OPENCV"

I've built OpenCV v4.2 from source and installed it to /usr/local. OPENCVConfig.cmake file is in /usr/local/lib/cmake/opencv4 directory:

paul@paul-desktop:/usr/local/lib/cmake/opencv4$ dir
OpenCVConfig.cmake  OpenCVConfig-version.cmake  OpenCVModules.cmake  OpenCVModules-release.cmake

Here is my CMakeLists.txt file with desperate attempts to satisfy find_package:

cmake_minimum_required(VERSION 3.16.2)
project(af VERSION 0.1.0 LANGUAGES CXX)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_BUILD_PARALLEL_LEVEL 4)
set(CMAKE_PREFIX_PATH /usr/local/lib/cmake/opencv4)
set(ENV{OPENCV_DIR} /usr/local/lib/cmake/opencv4)
set(OPENCV_DIR /usr/local/lib/cmake/opencv4)

find_package(OPENCV REQUIRED)

add_executable(af main.cpp)

which produces this error:

[build] CMake Error at CMakeLists.txt:12 (find_package):
[build]   By not providing "FindOPENCV.cmake" in CMAKE_MODULE_PATH this project has
[build]   asked CMake to find a package configuration file provided by "OPENCV", but
[build]   CMake did not find one.
[build] 
[build]   Could not find a package configuration file provided by "OPENCV" with any
[build]   of the following names:
[build] 
[build]     OPENCVConfig.cmake
[build]     opencv-config.cmake
[build] 
[build]   Add the installation prefix of "OPENCV" to CMAKE_PREFIX_PATH or set
[build]   "OPENCV_DIR" to a directory containing one of the above files.  If "OPENCV"
[build]   provides a separate development package or SDK, be sure it has been
[build]   installed.

When I open CMakeCache.txt with cmake-gui and manually set OPENCV_DIR to /usr/local/lib/cmake/opencv4, I'm getting the same error and OPENCV_DIR becomes OPENCV_DIR-NOTFOUND.

What is happening here? It seems to me that I'm fulfilling the requirements listed in error message and any good advice I could find in answers to similar problems.

I'm not sure if it matters, but there /usr/share/OpenCV/OpenCVConfig.cmake belonging to a different version of OpenCV.

Upvotes: 1

Views: 6936

Answers (1)

Tsyvarev
Tsyvarev

Reputation: 65870

Package names are case-sensitive. And proper name of the OpenCV package for use in find_package is OpenCV, not OPENCV.


Actually, the only thing in CMake which case-insensitive is a macro/function name. Everything else is case-sensitive.

Some variables and files use uppercase or lowercase transformation of names. E.g. OPENCV_DIR variable uses a package name in uppercase and opencv-config.cmake file uses a package name in lowercase. But this doesn't deny case-sensitive aspects.

Upvotes: 2

Related Questions