# find\_package config search order

**URL:** https://discourse.cmake.org/t/find-package-config-search-order/5015
**Category:** Usage
**Created:** [February 15, 2022, 3:45pm UTC](https://discourse.cmake.org/t/find-package-config-search-order/5015 "2022-02-15T15:45:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [February 15, 2022, 3:45pm UTC](https://discourse.cmake.org/t/find-package-config-search-order/5015/1 "2022-02-15T15:45:03Z")

</div>

CMake 3.10/Ubuntu 18.04  
I’m looking for a custom OpenCV installation  
I set OpenCV\_DIR environment variable to the path to the OpenCV.cmake directory  
find\_package finds the default installed version (in /usr/something…).

Looking more precisely at the documentation I misunderstand 2 points:

- what is the actual function of the \_DIR variable;
- what is the \<prefix\> mentioned [here](https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure)?

What is the best way to give a client specific-path to locate a package (here, I’d prefer not to use PATH option and that the client sets some env variable that CMAKE can use to locate the desired installation of the package, when different installations exists)?

Thanks,  
A.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 15, 2022, 7:28pm UTC](https://discourse.cmake.org/t/find-package-config-search-order/5015/2 "2022-02-15T19:28:24Z")

</div>

> [@adaldev](#):
>
> I set OpenCV\_DIR environment variable to the path to the OpenCV.cmake directory

`OpenCV_DIR` should be set to the directory of the `opencv-config.cmake` file; `OpenCV.cmake` doesn’t mean anything to `find_package`. You can use `cmake --debug-find` to debug the `find_` command routines.

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [February 16, 2022, 8:06am UTC](https://discourse.cmake.org/t/find-package-config-search-order/5015/3 "2022-02-16T08:06:57Z")

</div>

Hi,

Yes, I was speaking about opencv-config.cmake.  
On CMake 3.10, I can’t find --debug-find command or an equivalent. Is there another way to debug? (It is indeed useful, I tested it on more recent version).

But actually setting the environment variable OpenCV\_DIR works after cleaning cmake cache.

I suppose that there was already a local OpenCV\_DIR variable in the cache, thus find\_package was not looking into the environment variable version.

Regards

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 16, 2022, 2:49pm UTC](https://discourse.cmake.org/t/find-package-config-search-order/5015/4 "2022-02-16T14:49:35Z")

</div>

> [@adaldev](#):
>
> I suppose that there was already a local OpenCV\_DIR variable in the cache, thus find\_package was not looking into the environment variable version.

That could certainly do it.
