Cmake override find_package for a given target

Viewed 2656

We have a CMakeLists.txt that links (for instance) opencv to our various binaries. This is done as follow:

find_package(OpenCV REQUIRED core imgproc highgui contrib) 
target_link_library(XXX opencv_core)

We also would like to allow the person building the library to provide its own opencv library. It seems that this could be done setting -DCMAKE_PREFIX_PATH to the right path.

cmake -DCMAKE_PREFIX_PATH=".../mybuild/include;.../mybuild/lib" .  

However I would like to be sure the library used is exactly the one specified by the client (i.e. if there is nothing in /mybuild/lib the configuration fails).

How can I allow somebody building the library to override the library used ? (if nothing is specified it should fall back to find_package-s)

1 Answers
Related