FindOpenSSL: Add OpenSSL_VERSION

This deprecates the OPENSSL_VERSION result variable.

Issue: #27088
This commit is contained in:
Peter Kokot
2025-08-04 20:57:24 +02:00
parent 185a4e6c5d
commit 5503235b4d
6 changed files with 49 additions and 18 deletions

View File

@@ -31,6 +31,9 @@ Find Modules
* The :module:`FindLTTngUST` module now provides a ``LTTngUST_VERSION`` result
variable. The ``LTTNGUST_VERSION_STRING`` result variable is deprecated.
* The :module:`FindOpenSSL` module now provides an ``OpenSSL_VERSION`` result
variable. The ``OPENSSL_VERSION`` result variable is deprecated.
* The :module:`FindPNG` module now provides a ``PNG_VERSION`` result
variable. The ``PNG_VERSION_STRING`` result variable is deprecated.

View File

@@ -5,7 +5,11 @@
FindOpenSSL
-----------
Finds the installed OpenSSL encryption library and determines its version.
Finds the installed OpenSSL encryption library and determines its version:
.. code-block:: cmake
find_package(OpenSSL [<version>] [COMPONENTS <components>...] [...])
.. versionadded:: 3.20
Support for specifying version range when calling the :command:`find_package`
@@ -95,23 +99,34 @@ Result Variables
This module defines the following variables:
``OpenSSL_FOUND``
Boolean indicating whether the OpenSSL library has been found. For backward
compatibility, the ``OPENSSL_FOUND`` variable is also set to the same value.
Boolean indicating whether (the requested version of) OpenSSL library has
been found. For backward compatibility, the ``OPENSSL_FOUND`` variableđ
is also set to the same value.
``OpenSSL_VERSION``
.. versionadded:: 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_VERSION``
The OpenSSL version found. This is set to
``<major>.<minor>.<revision><patch>`` (e.g. ``0.9.8s``).
``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
@@ -142,6 +157,17 @@ This module accepts the following variables to control the search behavior:
``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_VERSION``
.. deprecated:: 4.2
Superseded by the ``OpenSSL_VERSION``.
The version of OpenSSL found.
Examples
^^^^^^^^
@@ -661,7 +687,8 @@ if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h")
string(ASCII "${OPENSSL_VERSION_PATCH_ASCII}" OPENSSL_VERSION_PATCH_STRING)
endif ()
set(OPENSSL_VERSION "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_FIX}${OPENSSL_VERSION_PATCH_STRING}")
set(OpenSSL_VERSION "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_FIX}${OPENSSL_VERSION_PATCH_STRING}")
set(OPENSSL_VERSION "${OpenSSL_VERSION}")
else ()
# Since OpenSSL 3.0.0, the new version format is MAJOR.MINOR.PATCH and
# a new OPENSSL_VERSION_STR macro contains exactly that
@@ -670,10 +697,11 @@ if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h")
string(REGEX REPLACE "^.*OPENSSL_VERSION_STR[\t ]+\"([0-9]+\\.[0-9]+\\.[0-9]+)\".*$"
"\\1" OPENSSL_VERSION_STR "${OPENSSL_VERSION_STR}")
set(OPENSSL_VERSION "${OPENSSL_VERSION_STR}")
set(OpenSSL_VERSION "${OPENSSL_VERSION_STR}")
set(OPENSSL_VERSION "${OpenSSL_VERSION}")
# Setting OPENSSL_VERSION_MAJOR OPENSSL_VERSION_MINOR and OPENSSL_VERSION_FIX
string(REGEX MATCHALL "([0-9])+" OPENSSL_VERSION_NUMBER "${OPENSSL_VERSION}")
string(REGEX MATCHALL "([0-9])+" OPENSSL_VERSION_NUMBER "${OpenSSL_VERSION}")
list(POP_FRONT OPENSSL_VERSION_NUMBER
OPENSSL_VERSION_MAJOR
OPENSSL_VERSION_MINOR
@@ -718,7 +746,7 @@ find_package_handle_standard_args(OpenSSL
OPENSSL_CRYPTO_LIBRARY
OPENSSL_INCLUDE_DIR
VERSION_VAR
OPENSSL_VERSION
OpenSSL_VERSION
HANDLE_VERSION_RANGE
HANDLE_COMPONENTS
FAIL_MESSAGE

View File

@@ -122,7 +122,7 @@ foreach(
HDF5
Jasper JPEG
LibArchive LibLZMA LIBLZMA LibXml2 LibXslt LTTngUST
OPENSCENEGRAPH
OPENSCENEGRAPH OpenSSL OPENSSL
PNG PostgreSQL Protobuf
Ruby RUBY
SDL SWIG

View File

@@ -1,13 +1,13 @@
find_package (OpenSSL REQUIRED COMPONENTS Crypto)
# Store version without a possibly trailing letter.
string (REGEX MATCH "^([0-9.]+)" version "${OPENSSL_VERSION}")
string (REGEX MATCH "^([0-9.]+)" version "${OpenSSL_VERSION}")
# clean-up OpenSSL variables
unset (OPENSSL_INCLUDE_DIR)
unset (OPENSSL_CRYPTO_LIBRARY)
unset (OPENSSL_CRYPTO_LIBRARIES)
unset (OPENSSL_LIBRARIES)
unset (OPENSSL_VERSION)
unset (OpenSSL_VERSION)
unset (OpenSSL_FOUND)

View File

@@ -1,13 +1,13 @@
find_package (OpenSSL REQUIRED COMPONENTS Crypto)
# Store version without a possibly trailing letter.
string (REGEX MATCH "^([0-9.]+)" version "${OPENSSL_VERSION}")
string (REGEX MATCH "^([0-9.]+)" version "${OpenSSL_VERSION}")
# clean-up OpenSSL variables
unset (OPENSSL_INCLUDE_DIR)
unset (OPENSSL_CRYPTO_LIBRARY)
unset (OPENSSL_CRYPTO_LIBRARIES)
unset (OPENSSL_LIBRARIES)
unset (OPENSSL_VERSION)
unset (OpenSSL_VERSION)
unset (OpenSSL_FOUND)
## Specify a range including current OpenSSL version
@@ -24,7 +24,7 @@ unset (OPENSSL_INCLUDE_DIR)
unset (OPENSSL_CRYPTO_LIBRARY)
unset (OPENSSL_CRYPTO_LIBRARIES)
unset (OPENSSL_LIBRARIES)
unset (OPENSSL_VERSION)
unset (OpenSSL_VERSION)
unset (OpenSSL_FOUND)
## Specify a range excluding current OpenSSL version

View File

@@ -1,13 +1,13 @@
find_package (OpenSSL REQUIRED COMPONENTS Crypto)
# Store version without a possibly trailing letter.
string (REGEX MATCH "^([0-9.]+)" version "${OPENSSL_VERSION}")
string (REGEX MATCH "^([0-9.]+)" version "${OpenSSL_VERSION}")
# clean-up OpenSSL variables
unset (OPENSSL_INCLUDE_DIR)
unset (OPENSSL_CRYPTO_LIBRARY)
unset (OPENSSL_CRYPTO_LIBRARIES)
unset (OPENSSL_LIBRARIES)
unset (OPENSSL_VERSION)
unset (OpenSSL_VERSION)
unset (OpenSSL_FOUND)