Commit 6779e485 authored by gnaggnoyil's avatar gnaggnoyil
Browse files

add target OpenSSL::applink to support OpenSSL's applink feature

parent 327e79c3
Pipeline #172440 passed with stage
......@@ -22,6 +22,13 @@ This module defines the following :prop_tgt:`IMPORTED` targets:
The OpenSSL ``ssl`` library, if found.
``OpenSSL::Crypto``
The OpenSSL ``crypto`` library, if found.
``OpenSSL::applink``
The OpenSSL ``applink` components that might be need to be compiled into
projects under MSVC. This target is avaliable only if found OpenSSL version
is not less than 0.9.8. By linking this target the above OpenSSL targets can
be linked even if the project has different MSVC runtime configurations with
the above OpenSSL targets. This target has no effect on plaforms other than
MSVC.
Result Variables
^^^^^^^^^^^^^^^^
......@@ -45,6 +52,10 @@ This module will set the following variables in your project:
All OpenSSL libraries and their dependencies.
``OPENSSL_VERSION``
This is set to ``$major.$minor.$revision$patch`` (e.g. ``0.9.8s``).
``OPENSSL_APPLINK_SOURCES``
The sources in the target ``OpenSSL::applink`` that is mentioned above. This
variable shall always be underfined if found openssl version is less than
0.9.8 or if platform is not MSVC.
Hints
^^^^^
......@@ -80,6 +91,47 @@ function(_OpenSSL_target_add_dependencies target)
endif()
endfunction()
function(_OpenSSL_compare_version out_var)
set(predicates LESS EQUAL GREATER)
cmake_parse_arguments(arg "${predicates}" "" "VERSION_LEFT;VERSION_RIGHT" ${ARGN})
set(version_components FIX MINOR MAJOR)
cmake_parse_arguments(lver "" "PATCH;${version_components}" "" ${arg_VERSION_LEFT})
cmake_parse_arguments(rver "" "PATCH;${version_components}" "" ${arg_VERSION_RIGHT})
foreach(prefix lver rver)
set(${prefix}_mainstr "${${prefix}_MAJOR}.${${prefix}_MINOR}.${${prefix}_FIX}")
foreach(ver_comp ${version_components})
if(NOT DEFINED ${prefix}_${ver_comp})
message(FATAL_ERROR "${${prefix}_mainstr}${${prefix}_PATCH} is not a valid ${prefix} version string.")
return()
endif()
endforeach()
endforeach()
if(${lver_mainstr} VERSION_EQUAL ${rver_mainstr})
foreach(pred LESS EQUAL GREATER)
if(${arg_${pred}})
if("x${lver_PATCH}" STR${pred} "x${rver_PATCH}")
set(${out_var} TRUE PARENT_SCOPE)
return()
endif()
endif()
endforeach()
set(${out_var} FALSE PARENT_SCOPE)
return()
endif()
foreach(pred LESS GREATER)
if(${arg_${pred}})
if(${lver_mainstr} VERSION_${pred} ${rver_mainstr})
set(${out_var} TRUE PARENT_SCOPE)
return()
endif()
endif()
endforeach()
set(${out_var} FALSE PARENT_SCOPE)
return()
endfunction()
if (UNIX)
find_package(PkgConfig QUIET)
pkg_check_modules(_OPENSSL QUIET openssl)
......@@ -524,6 +576,34 @@ if(OPENSSL_FOUND)
endif()
_OpenSSL_target_add_dependencies(OpenSSL::SSL)
endif()
_OpenSSL_compare_version(_vercomp
VERSION_LEFT
MAJOR ${OPENSSL_VERSION_MAJOR} MINOR ${OPENSSL_VERSION_MINOR} FIX ${OPENSSL_VERSION_FIX} PATCH ${OPENSSL_VERSION_PATCH_STRING}
VERSION_RIGHT
MAJOR 0 MINOR 9 FIX 8
GREATER EQUAL)
if(${_vercomp})
if(WIN32 AND NOT CYGWIN AND MSVC)
if(EXISTS "${OPENSSL_INCLUDE_DIR}")
set(_OPENSSL_applink_paths PATHS ${OPENSSL_INCLUDE_DIR})
endif()
find_file(OPENSSL_APPLINK_SOURCES
NAMES
openssl/applink.c
${_OPENSSL_applink_paths}
NO_DEFAULT_PATH)
if(NOT "${OPENSSL_APPLINK_SOURCES}" MATCHES "-NOTFOUND$")
set(_OPENSSL_applink_interface_srcs ${OPENSSL_APPLINK_SOURCES})
endif()
endif()
if(NOT TARGET OpenSSL::applink)
add_library(OpenSSL::applink INTERFACE IMPORTED)
set_property(TARGET OpenSSL::applink APPEND
PROPERTY INTERFACE_SOURCES
${_OPENSSL_applink_interface_srcs})
endif()
endif()
endif()
# Restore the original find library ordering
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment