# 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 `crypto` library is found.

`SSL`

  Added in version 3.12.

  Ensures that the OpenSSL `ssl` library 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 `crypto` library usage requirements, available only if the `crypto` library is found.

`OpenSSL::SSL`

  Added in version 3.4.

  Target encapsulating the OpenSSL `ssl` library usage requirements, available only if the `ssl` library is found. For convenience, this target also links `OpenSSL::Crypto`, since the `ssl` library depends on the `crypto` library.

`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_SOURCES` target property. Due to how interface sources are propagated in CMake, it is recommended to link the `OpenSSL::applink` target 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 `crypto` library.

`OPENSSL_CRYPTO_LIBRARIES`

  The OpenSSL `crypto` library and its dependencies.

`OPENSSL_SSL_LIBRARY`

  The OpenSSL `ssl` library.

`OPENSSL_SSL_LIBRARIES`

  The OpenSSL `ssl` library and its dependencies.

`OPENSSL_LIBRARIES`

  All OpenSSL libraries and their dependencies.

`OPENSSL_APPLINK_SOURCE`

  The sources in the target `OpenSSL::applink` mentioned 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 `TRUE` to prefer static OpenSSL libraries over shared ones.

`OPENSSL_MSVC_STATIC_RT`

  Added in version 3.5.

  Set to `TRUE` to search for the OpenSSL libraries built with the MSVC static runtime (MT).

`ENV{PKG_CONFIG_PATH}`

  On UNIX-like systems, `pkg-config` is used to locate OpenSSL. Set the `PKG_CONFIG_PATH` environment 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)