Merge topic 'FindOpenSSL-imported-targets'
75e3a8e8
FindOpenSSL: Provide imported targets OpenSSL::{SSL,Crypto}79a36437
FindOpenSSL: Revise and format module documentation
This commit is contained in:
commit
a0dab7b774
|
@ -2,26 +2,40 @@
|
|||
# FindOpenSSL
|
||||
# -----------
|
||||
#
|
||||
# Try to find the OpenSSL encryption library
|
||||
# Find the OpenSSL encryption library.
|
||||
#
|
||||
# Once done this will define
|
||||
# Imported Targets
|
||||
# ^^^^^^^^^^^^^^^^
|
||||
#
|
||||
# ::
|
||||
# This module defines the following :prop_tgt:`IMPORTED` targets:
|
||||
#
|
||||
# OPENSSL_ROOT_DIR - Set this variable to the root installation of OpenSSL
|
||||
# ``OpenSSL::SSL``
|
||||
# The OpenSSL ``ssl`` library, if found.
|
||||
# ``OpenSSL::Crypto``
|
||||
# The OpenSSL ``crypto`` library, if found.
|
||||
#
|
||||
# Result Variables
|
||||
# ^^^^^^^^^^^^^^^^
|
||||
#
|
||||
# This module will set the following variables in your project:
|
||||
#
|
||||
# Read-Only variables:
|
||||
# ``OPENSSL_FOUND``
|
||||
# System has the OpenSSL library.
|
||||
# ``OPENSSL_INCLUDE_DIR``
|
||||
# The OpenSSL include directory.
|
||||
# ``OPENSSL_CRYPTO_LIBRARY``
|
||||
# The OpenSSL crypto library.
|
||||
# ``OPENSSL_SSL_LIBRARY``
|
||||
# The OpenSSL SSL library.
|
||||
# ``OPENSSL_LIBRARIES``
|
||||
# All OpenSSL libraries.
|
||||
# ``OPENSSL_VERSION``
|
||||
# This is set to ``$major.$minor.$revision$patch`` (e.g. ``0.9.8s``).
|
||||
#
|
||||
# ::
|
||||
# Hints
|
||||
# ^^^^^
|
||||
#
|
||||
# OPENSSL_FOUND - System has the OpenSSL library
|
||||
# OPENSSL_INCLUDE_DIR - The OpenSSL include directory
|
||||
# OPENSSL_CRYPTO_LIBRARY - The OpenSSL crypto library
|
||||
# OPENSSL_SSL_LIBRARY - The OpenSSL SSL library
|
||||
# OPENSSL_LIBRARIES - All OpenSSL libraries
|
||||
# OPENSSL_VERSION - This is set to $major.$minor.$revision$patch (eg. 0.9.8s)
|
||||
# Set ``OPENSSL_ROOT_DIR`` to the root directory of an OpenSSL installation.
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2006-2009 Kitware, Inc.
|
||||
|
@ -337,3 +351,66 @@ else ()
|
|||
endif ()
|
||||
|
||||
mark_as_advanced(OPENSSL_INCLUDE_DIR OPENSSL_LIBRARIES)
|
||||
|
||||
if(OPENSSL_FOUND)
|
||||
if(NOT TARGET OpenSSL::Crypto AND
|
||||
(EXISTS "${OPENSSL_CRYPTO_LIBRARY}" OR
|
||||
EXISTS "${LIB_EAY_LIBRARY_DEBUG}" OR
|
||||
EXISTS "${LIB_EAY_LIBRARY_RELEASE}")
|
||||
)
|
||||
add_library(OpenSSL::Crypto UNKNOWN IMPORTED)
|
||||
set_target_properties(OpenSSL::Crypto PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}")
|
||||
if(EXISTS "${OPENSSL_CRYPTO_LIBRARY}")
|
||||
set_target_properties(OpenSSL::Crypto PROPERTIES
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${OPENSSL_CRYPTO_LIBRARY}")
|
||||
endif()
|
||||
if(EXISTS "${LIB_EAY_LIBRARY_DEBUG}")
|
||||
set_property(TARGET OpenSSL::Crypto APPEND PROPERTY
|
||||
IMPORTED_CONFIGURATIONS DEBUG)
|
||||
set_target_properties(OpenSSL::Crypto PROPERTIES
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
|
||||
IMPORTED_LOCATION_DEBUG "${LIB_EAY_LIBRARY_DEBUG}")
|
||||
endif()
|
||||
if(EXISTS "${LIB_EAY_LIBRARY_RELEASE}")
|
||||
set_property(TARGET OpenSSL::Crypto APPEND PROPERTY
|
||||
IMPORTED_CONFIGURATIONS RELEASE)
|
||||
set_target_properties(OpenSSL::Crypto PROPERTIES
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
|
||||
IMPORTED_LOCATION_RELEASE "${LIB_EAY_LIBRARY_RELEASE}")
|
||||
endif()
|
||||
endif()
|
||||
if(NOT TARGET OpenSSL::SSL AND
|
||||
(EXISTS "${OPENSSL_SSL_LIBRARY}" OR
|
||||
EXISTS "${SSL_EAY_LIBRARY_DEBUG}" OR
|
||||
EXISTS "${SSL_EAY_LIBRARY_RELEASE}")
|
||||
)
|
||||
add_library(OpenSSL::SSL UNKNOWN IMPORTED)
|
||||
set_target_properties(OpenSSL::SSL PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}")
|
||||
if(EXISTS "${OPENSSL_SSL_LIBRARY}")
|
||||
set_target_properties(OpenSSL::SSL PROPERTIES
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${OPENSSL_SSL_LIBRARY}")
|
||||
endif()
|
||||
if(EXISTS "${SSL_EAY_LIBRARY_DEBUG}")
|
||||
set_property(TARGET OpenSSL::SSL APPEND PROPERTY
|
||||
IMPORTED_CONFIGURATIONS DEBUG)
|
||||
set_target_properties(OpenSSL::SSL PROPERTIES
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
|
||||
IMPORTED_LOCATION_DEBUG "${SSL_EAY_LIBRARY_DEBUG}")
|
||||
endif()
|
||||
if(EXISTS "${SSL_EAY_LIBRARY_RELEASE}")
|
||||
set_property(TARGET OpenSSL::SSL APPEND PROPERTY
|
||||
IMPORTED_CONFIGURATIONS RELEASE)
|
||||
set_target_properties(OpenSSL::SSL PROPERTIES
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
|
||||
IMPORTED_LOCATION_RELEASE "${SSL_EAY_LIBRARY_RELEASE}")
|
||||
endif()
|
||||
if(TARGET OpenSSL::Crypto)
|
||||
set_target_properties(OpenSSL::SSL PROPERTIES
|
||||
INTERFACE_LINK_LIBRARIES OpenSSL::Crypto)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
@ -1333,6 +1333,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
|
|||
add_subdirectory(FindJsonCpp)
|
||||
endif()
|
||||
|
||||
if(CMake_TEST_FindOpenSSL)
|
||||
add_subdirectory(FindOpenSSL)
|
||||
endif()
|
||||
|
||||
# Matlab module
|
||||
if(CMake_TEST_FindMatlab)
|
||||
ADD_TEST_MACRO(FindMatlab.basic_checks ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>)
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
add_test(NAME FindOpenSSL.rand COMMAND ${CMAKE_CTEST_COMMAND}
|
||||
--build-and-test
|
||||
"${CMake_SOURCE_DIR}/Tests/FindOpenSSL/rand"
|
||||
"${CMake_BINARY_DIR}/Tests/FindOpenSSL/rand"
|
||||
${build_generator_args}
|
||||
--build-project FindOpenSSL_rand
|
||||
--build-options ${build_options}
|
||||
--test-command ${CMAKE_CTEST_COMMAND} -V
|
||||
)
|
|
@ -0,0 +1,14 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
project(FindOpenSSL_rand CXX)
|
||||
include(CTest)
|
||||
|
||||
find_package(OpenSSL REQUIRED)
|
||||
|
||||
add_executable(tstopensslrand_tgt main.cc)
|
||||
target_link_libraries(tstopensslrand_tgt OpenSSL::SSL)
|
||||
add_test(NAME tstopensslrand_tgt COMMAND tstopensslrand_tgt)
|
||||
|
||||
add_executable(tstopensslrand_var main.cc)
|
||||
target_link_libraries(tstopensslrand_var ${OPENSSL_LIBRARIES})
|
||||
target_include_directories(tstopensslrand_var PRIVATE ${OPENSSL_INCLUDE_DIR})
|
||||
add_test(NAME tstopensslrand_var COMMAND tstopensslrand_var)
|
|
@ -0,0 +1,22 @@
|
|||
#include <openssl/rand.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
// return value
|
||||
int retval = 1;
|
||||
|
||||
// bytes buffer
|
||||
unsigned char buf[1024];
|
||||
|
||||
// random bytes
|
||||
int rezval = RAND_bytes(buf, sizeof(buf)); /* 1 succes, 0 otherwise */
|
||||
|
||||
// check result
|
||||
if(rezval == 1)
|
||||
{
|
||||
retval = 0;
|
||||
}
|
||||
|
||||
// return code
|
||||
return retval;
|
||||
}
|
Loading…
Reference in New Issue