FindOpenSSL
Finds the installed OpenSSL encryption library and determines its version:
find_package(OpenSSL [<version>] [COMPONENTS <components>...] [...])
Added in version 3.20: Support for specifying version range when calling the find_package() command. When a version is requested, it can be specified as a single value as before, and now also a version range can be used. For a detailed description of version range usage and capabilities, refer to the find_package() command.
Added in version 3.18: Support for OpenSSL 3.0.
Components
This module supports the following optional components:
-
Crypto -
Added in version 3.12.
Ensures that the OpenSSL
cryptolibrary is found. -
SSL -
Added in version 3.12.
Ensures that the OpenSSL
ssllibrary is found.
Components can be optionally specified using a standard syntax:
find_package(OpenSSL [COMPONENTS <components>...])
If no components are requested, module by default searches for the Crypto as required and SSL as optional component.
Imported Targets
This module provides the following Imported Targets:
-
OpenSSL::Crypto -
Added in version 3.4.
Target encapsulating the OpenSSL
cryptolibrary usage requirements, available only if thecryptolibrary is found. -
OpenSSL::SSL -
Added in version 3.4.
Target encapsulating the OpenSSL
ssllibrary usage requirements, available only if thessllibrary is found. For convenience, this target also linksOpenSSL::Crypto, since thessllibrary depends on thecryptolibrary. -
OpenSSL::applink -
Added in version 3.18.
Target encapsulating the OpenSSL application-side interface (
openssl/applink.c) usage requirements, available only if OpenSSL is found and its version is at least 0.9.8.This interface provides a glue between OpenSSL BIO layer and the Windows compiler runtime environment and may need to be compiled into projects when using MSVC. By linking this target, the other OpenSSL imported targets can be linked even if the project uses different MSVC runtime configuration. Linking this target on platforms other than MSVC has no effect.
Note
The interface file is added using the
INTERFACE_SOURCEStarget property. Due to how interface sources are propagated in CMake, it is recommended to link theOpenSSL::applinktarget as PRIVATE to ensure that it is linked only once in the entire dependency graph of any library or executable:target_link_libraries(project_target PRIVATE OpenSSL::applink)
Using other scopes for this target specifically can lead to unexpected issues during the build or link process, as both the ISO C and ISO C++ standards place very few requirements on how linking should behave.
Result Variables
This module defines the following variables:
-
OpenSSL_FOUND -
Added in version 3.3.
Boolean indicating whether the (requested version of) OpenSSL library was found.
-
OpenSSL_VERSION -
Added in version 4.2.
The OpenSSL version found. This is set to
<major>.<minor>.<revision><patch>(e.g.,0.9.8s). -
OPENSSL_INCLUDE_DIR -
The OpenSSL include directory.
-
OPENSSL_CRYPTO_LIBRARY -
The OpenSSL
cryptolibrary. -
OPENSSL_CRYPTO_LIBRARIES -
The OpenSSL
cryptolibrary and its dependencies. -
OPENSSL_SSL_LIBRARY -
The OpenSSL
ssllibrary. -
OPENSSL_SSL_LIBRARIES -
The OpenSSL
ssllibrary and its dependencies. -
OPENSSL_LIBRARIES -
All OpenSSL libraries and their dependencies.
-
OPENSSL_APPLINK_SOURCE -
The sources in the target
OpenSSL::applinkmentioned above. This variable is only defined if found OpenSSL version is at least 0.9.8 and the platform is MSVC.
Hints
This module accepts the following variables to control the search behavior:
-
OPENSSL_ROOT_DIR -
Set to the root directory of an OpenSSL installation to search for the OpenSSL libraries in custom locations.
-
OPENSSL_USE_STATIC_LIBS -
Added in version 3.4.
Set to
TRUEto prefer static OpenSSL libraries over shared ones. -
OPENSSL_MSVC_STATIC_RT -
Added in version 3.5.
Set to
TRUEto search for the OpenSSL libraries built with the MSVC static runtime (MT). -
ENV{PKG_CONFIG_PATH} -
On UNIX-like systems,
pkg-configis used to locate OpenSSL. Set thePKG_CONFIG_PATHenvironment variable to specify alternate locations, which is useful on systems with multiple library installations.
Deprecated Variables
The following variables are provided for backward compatibility:
-
OPENSSL_FOUND -
Deprecated since version 4.2: Use
OpenSSL_FOUND, which has the same value.Boolean indicating whether the (requested version of) OpenSSL library was found.
-
OPENSSL_VERSION -
Deprecated since version 4.2: Superseded by the
OpenSSL_VERSION.The version of OpenSSL found.
Examples
Finding the OpenSSL crypto library and linking it to a project target:
find_package(OpenSSL) target_link_libraries(project_target PRIVATE OpenSSL::Crypto)
The following example shows how to find the OpenSSL crypto and ssl libraries and link them to a project target. The SSL component is explicitly specified to ensure that the find module reports an error if the ssl library is not found:
find_package(OpenSSL COMPONENTS SSL) target_link_libraries(project_target PRIVATE OpenSSL::SSL)
© 2000–2026 Kitware, Inc. and Contributors
Licensed under the BSD 3-clause License.
https://cmake.org/cmake/help/latest/module/FindOpenSSL.html