Yves
Yves

Reputation: 12371

How to set a specific package path for CMakeLists.txt

My colleague wrote a CMakeLists.txt, which contains things as below:

find_package(OpenCV 3 REQUIRED
  COMPONENTS
    opencv_core
    opencv_imgproc
    opencv_imgcodecs
  CONFIG
)

As the project needs these components of Opencv3, my colleague downloaded the whole Opencv3, of course, it works.

But the whole Opencv3 is too big, so I get only the necessary lib files: libopencv_core.so, libopencv_imgproc.so and libopencv_imgcodecs.so and try to replace the whole Opencv3. The three so files are put here: /opt/opencv3/.

I don't know how to tell the CMakeLists.txt to look for the components of Opencv3 at the specific path instead of the path by default.

I'm totally a newbie on writing CMakeLists.txt...

Upvotes: 0

Views: 4196

Answers (1)

Marco Pantaleoni
Marco Pantaleoni

Reputation: 2539

CMake find_package() finds and configure project dependencies in CMake using two modes of operation, Module and Config, as described in its documentation.

In Module mode (not your case), it looks for a Find<package>.cmake file inside CMAKE_MODULE_PATH. This file searches for header files and libraries and set the necessary CMake variables in case of success.

In your case it is using Config, as requested by the CONFIG keyword. In Config mode CMake looks for for a <name>Config.cmake file or <lowercase-name>-config.cmake. These config files describe the version of the dependency and the location of header files and library modules.

So you should look for OpenCVConfig.cmake or opencv-config.cmake in CMAKE_PREFIX_PATH or in OpenCV_DIR. Please note that you have to set(OpenCV_DIR ...) before calling find_package().

Upvotes: 1

Related Questions