# Correct usage of find\_package(OpenSSL)

**URL:** https://discourse.cmake.org/t/correct-usage-of-find-package-openssl/5094
**Category:** Usage
**Created:** [February 23, 2022, 9:58am UTC](https://discourse.cmake.org/t/correct-usage-of-find-package-openssl/5094 "2022-02-23T09:58:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![peter](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://discourse.cmake.org/u/peter)
#### Post date: [February 23, 2022, 9:58am UTC](https://discourse.cmake.org/t/correct-usage-of-find-package-openssl/5094/1 "2022-02-23T09:58:45Z")

</div>

Hello,  
we have multiplatform (Win/Mac/Lin) C++ project tree for building several executable binaries and shared libraries and we use cmake. I found in our code find\_package(OpenSSL) in several CMakeLists.txt. Problem is that when more OpenSSL packages are installed then our code can mix link libraries and result build can have bad link dependencies. In our development cycle we can use as installed OpenSSL (for example in Win installed with \*.msi) as our own OpenSSL builds copied to file system.  
I tried to setup OPENSSL\_ROOT\_DIR in root CMakeLists.txt and it helps to find exactly OpenSSL package which I need but some child projects have found different package. I’d like to manage code to have only one place for find\_package() for all project tree.

My question are:  
Can I adjust our cmake code to use only one find\_package(OpenSSL) in root CMakeLists.txt ? When I try this adjustment then it seems that information about found package in parent project branch is not inherited to child projects. How to correct it ? Or what do you recommend ?

Peter

---

<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 23, 2022, 3:37pm UTC](https://discourse.cmake.org/t/correct-usage-of-find-package-openssl/5094/2 "2022-02-23T15:37:01Z")

</div>

> [@peter](#):
>
> Can I adjust our cmake code to use only one find\_package(OpenSSL) in root

Likely, yes.

> [@peter](#):
>
> When I try this adjustment then it seems that information about found package in parent project branch is not inherited to child projects. How to correct it ? Or what do you recommend ?

What do you mean? You’ll also probably need to remove the other `find_package(OpenSSL)` calls as they may overwrite the top-level one.

---

<div class="post-metadata">

### Author: ![jshanab](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jshanab/32/2555_2.png) [@jshanab](https://discourse.cmake.org/u/jshanab)
#### Post date: [January 20, 2023, 5:36pm UTC](https://discourse.cmake.org/t/correct-usage-of-find-package-openssl/5094/3 "2023-01-20T17:36:35Z")

</div>

Were you ever able to get this to work?

I am trying to install openssl libssl and libcrypto from our openssl installed into /opt.

I have to go thru contortions to get cmake to not use the os installed version as cmake findModule ignores the OPENSSL\_ROOT\_DIR and I have to use pkg\_config.  
I got the ldd output correct and everything works except the install bails saying :

CMake Error at {mydir}:  
file Could not resolve runtime dependencies:

```
libcrypto.so.1.1

```
