# Precedence of \<PackageName\>\_ROOT in package search

**URL:** https://discourse.cmake.org/t/precedence-of-packagename-root-in-package-search/7993
**Category:** Usage
**Created:** [April 26, 2023, 9:18pm UTC](https://discourse.cmake.org/t/precedence-of-packagename-root-in-package-search/7993 "2023-04-26T21:18:58Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![xmk253](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/x/b2d939/32.png) [@xmk253](https://discourse.cmake.org/u/xmk253)
#### Post date: [April 26, 2023, 9:18pm UTC](https://discourse.cmake.org/t/precedence-of-packagename-root-in-package-search/7993/1 "2023-04-26T21:18:58Z")

</div>

I have a cmake file that searches for OpenSSL using `find_package(OpenSSL REQUIRED)`, I noticed that paths that appear in `CMAKE_PREFIX_PATH` have precedence over the `OPENSSL_ROOT_DIR` i.e.

```auto
CMAKE_PREFIX_PATH="" CMAKE_LIBRARY_PATH="" cmake "-DOPENSSL_ROOT_DIR=/XXX/boringssl-build" ..

```

finds the SSL library in the `OPENSSL_ROOT_DIR` as expected:

```auto
-- Found OpenSSL: /XXX/boringssl-build/lib/libcrypto.a (found version "3.0.8")

```

but

```auto
CMAKE_PREFIX_PATH="/YYY-openssl-3.0.8" CMAKE_LIBRARY_PATH="" cmake "-DOPENSSL_ROOT_DIR=/XXX/boringssl-build" ..

```

finds the SSL library in the `CMAKE_PREFIX_PATH`:

```auto
-- Found OpenSSL: /YYY-openssl-3.0.8/lib/libcrypto.so (found version "3.0.8")

```

Is this a bug or expected behavior? I would expect `OPENSSL_ROOT_DIR` to take precedence since it’s a more specific configuration.

---

<div class="post-metadata">

### Author: ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)
#### Post date: [April 26, 2023, 9:46pm UTC](https://discourse.cmake.org/t/precedence-of-packagename-root-in-package-search/7993/2 "2023-04-26T21:46:19Z")

</div>

That is expected behavior, the `OPENSSL_ROOT_DIR` is documented as being a HINT which would mean it is used after `CMAKE_PREFIX_PATH`. What you want is `OpenSSL_ROOT` which is searched first.

See the bottom [https://cmake.org/cmake/help/latest/command/find\_library.html](https://cmake.org/cmake/help/latest/command/find_library.html) ( or any of the find calls ) to see the search priority rules.
