# FindPackage in config mode.

**URL:** <https://discourse.cmake.org/t/findpackage-in-config-mode/7766>\
**Category:** Code\
**Created:** [March 24, 2023, 2:26pm UTC](https://discourse.cmake.org/t/findpackage-in-config-mode/7766 "2023-03-24T14:26:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramesh\_Santhanam1](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/3be4f8/32.png) [@Ramesh\_Santhanam1](https://discourse.cmake.org/u/Ramesh_Santhanam1)\
**Post date:** [March 24, 2023, 2:26pm UTC](https://discourse.cmake.org/t/findpackage-in-config-mode/7766/1 "2023-03-24T14:26:39Z")

</div>

Greetings  
I would like alter the search paths when doing Find Package in config mode. Is that possible?  
Thanks  
Ramesh

---

<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:** [March 24, 2023, 2:54pm UTC](https://discourse.cmake.org/t/findpackage-in-config-mode/7766/2 "2023-03-24T14:54:49Z")

</div>

There are `HINTS` and `PATHS` arguments to `find_package` that you can pass.

---

<div class="post-metadata">

**Author:** ![Ramesh\_Santhanam1](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/3be4f8/32.png) [@Ramesh\_Santhanam1](https://discourse.cmake.org/u/Ramesh_Santhanam1)\
**Post date:** [March 24, 2023, 2:57pm UTC](https://discourse.cmake.org/t/findpackage-in-config-mode/7766/3 "2023-03-24T14:57:42Z")

</div>

Thanks for your response. It’s just that the call for find package is from a third party and if possible would not like to change it. As a user of the 3rd party’s cmakeLists.txt, can I set/unset the search paths from outside.

---

<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:** [March 24, 2023, 9:17pm UTC](https://discourse.cmake.org/t/findpackage-in-config-mode/7766/4 "2023-03-24T21:17:44Z")

</div>

Everything that affects finding these files is documented in the [`find_package`](https://cmake.org/cmake/help/latest/command/find_package.html) docs. It’s…complicated, but there have been a _lot_ of patterns used over the years 😕 .

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [March 24, 2023, 11:29pm UTC](https://discourse.cmake.org/t/findpackage-in-config-mode/7766/5 "2023-03-24T23:29:10Z")

</div>

Note you can effectively pre-empt a call to `find_package()` deep in a dependency by calling `find_package()` with your preferred set of arguments first before you pull in that dependency. As the `find_package()` docs state:

> Once one of the calls succeeds the result variable will be set and stored in the cache so that no call will search again.

If you do that, there shouldn’t be any need to try to modify the search paths within the dependency because those calls should then bypass their search.

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [March 25, 2023, 9:03am UTC](https://discourse.cmake.org/t/findpackage-in-config-mode/7766/6 "2023-03-25T09:03:32Z")

</div>

There is a caveat though:  
in my project I already find python with VERSION to argument set to 3. Later googletest also tries to find python without VERSION argument. Although the cached result should already match, it finds it again. And next cmake run, twice again…  
This could be improved a bit 😉
