# Does \`find\_package\` find in \`CMAKE\_INSTALL\_PREFIX\`?

**URL:** https://discourse.cmake.org/t/does-find-package-find-in-cmake-install-prefix/4063
**Category:** Usage
**Created:** [September 10, 2021, 5:16am UTC](https://discourse.cmake.org/t/does-find-package-find-in-cmake-install-prefix/4063 "2021-09-10T05:16:19Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Ronald](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@Ronald](https://discourse.cmake.org/u/Ronald)
#### Post date: [September 10, 2021, 5:16am UTC](https://discourse.cmake.org/t/does-find-package-find-in-cmake-install-prefix/4063/1 "2021-09-10T05:16:19Z")

</div>

## Env

- OS: Windows
- cmake: 3.21.2

## Case

`wxWidgets` installed in a custom folder like `C:\Users\abc\AppData\Local\Programs\installed_libs`.  
`CMAKE_PREFIX_PATH` not set  
only `-DCMAKE_INSTALL_PREFIX=C:\Users\abc\AppData\Local\Programs\installed_libs`  
As a result, wxWidgets is found, `C:\Users\abc\AppData\Local\Programs\installed_libs` has not been referenced anywhere else

## Question

Does `find_package` find in `CMAKE_INSTALL_PREFIX`?

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [September 10, 2021, 7:52am UTC](https://discourse.cmake.org/t/does-find-package-find-in-cmake-install-prefix/4063/2 "2021-09-10T07:52:14Z")

</div>

Short answer: no.  
Long answer: [https://cmake.org/cmake/help/latest/command/find\_package.html#search-procedure](https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure)  
There are a lot of paths searched, so maybe your path IS accidentally mentioned somewhere or somehow already cached.

---

<div class="post-metadata">

### Author: ![Ronald](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@Ronald](https://discourse.cmake.org/u/Ronald)
#### Post date: [September 10, 2021, 9:47am UTC](https://discourse.cmake.org/t/does-find-package-find-in-cmake-install-prefix/4063/3 "2021-09-10T09:47:23Z")

</div>

> [@fenrir](#):
>
> maybe your path IS accidentally mentioned somewhere or somehow already cached.

If  
`-DCMAKE_INSTALL_PREFIX=C:\Users\abc\AppData\Local\Programs\installed_libs`  
changes to  
`-DCMAKE_INSTALL_PREFIX=C:\Users\abc\AppData\Local\Programs\installed_libs111`,  
it fails to find `wxWidgets`, so `find_package` finds in `CMAKE_INSTALL_PREFIX` definitely, but not documented.

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [September 10, 2021, 9:56am UTC](https://discourse.cmake.org/t/does-find-package-find-in-cmake-install-prefix/4063/4 "2021-09-10T09:56:00Z")

</div>

You’ve forced me to dig deeper, aaaand…  
[https://cmake.org/cmake/help/latest/variable/CMAKE\_INSTALL\_PREFIX.html](https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html)

> The installation prefix is also added to [`CMAKE_SYSTEM_PREFIX_PATH`](https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_PREFIX_PATH.html#variable:CMAKE_SYSTEM_PREFIX_PATH) so that [`find_package()`](https://cmake.org/cmake/help/latest/command/find_package.html#command:find_package), [`find_program()`](https://cmake.org/cmake/help/latest/command/find_program.html#command:find_program), [`find_library()`](https://cmake.org/cmake/help/latest/command/find_library.html#command:find_library), [`find_path()`](https://cmake.org/cmake/help/latest/command/find_path.html#command:find_path), and [`find_file()`](https://cmake.org/cmake/help/latest/command/find_file.html#command:find_file) will search the prefix for other software.

So it IS documented but not where I expected it to be (and yeah, I was wrong about how it works).

---

<div class="post-metadata">

### Author: ![Bret\_Brown](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bret_brown/32/668_2.png) [@Bret\_Brown](https://discourse.cmake.org/u/Bret_Brown)
#### Post date: [September 12, 2021, 2:08am UTC](https://discourse.cmake.org/t/does-find-package-find-in-cmake-install-prefix/4063/5 "2021-09-12T02:08:48Z")

</div>

The `--prefix` argument to `cmake --install` is generally the best way to set an installation prefix because it lets you decouple install-time requirements from your configuration logic.

I think the fact that `CMAKE_INSTALL_PREFIX` affects configure-time logic just reinforces that position.

**Usually** you (or at least consumers of your project!) really want to directly manipulate `CMAKE_PREFIX_PATH` or `CMAKE_SYSTEM_PREFIX_PATH` to alter configure-time logic. Ideally in a mechanism like [a CMake toolchain file](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html) of maybe a [CMake preset](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html) to keep your logic consistent, reusable, and tidy. As an aside, pretty much every time `CMakeLists.txt` or reusable CMake modules start manipulating these variables, they lose portability, gain complexity, or both.

Anyway, `CMAKE_INSTALL_PREFIX` seems to mostly work a lot of the time, but I’m currently convinced that it has been sufficiently surpassed by other mechanisms at this point to just stop using it full-stop. I’d be curious if there are edge cases that challenge that advice.

---

<div class="post-metadata">

### Author: ![Ronald](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@Ronald](https://discourse.cmake.org/u/Ronald)
#### Post date: [September 12, 2021, 5:36am UTC](https://discourse.cmake.org/t/does-find-package-find-in-cmake-install-prefix/4063/6 "2021-09-12T05:36:29Z")

</div>

Thanks for your advice, it helps.
