Legends-of-Azeroth-Pandaria-5.4.8
671 строка · 23.6 Кб
1# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2# file Copyright.txt or https://cmake.org/licensing for details.
3
4#[=======================================================================[.rst:
5FindOpenSSL
6-----------
7
8Find the OpenSSL encryption library.
9
10Optional COMPONENTS
11^^^^^^^^^^^^^^^^^^^
12
13This module supports two optional COMPONENTS: ``Crypto`` and ``SSL``. Both
14components have associated imported targets, as described below.
15
16Imported Targets
17^^^^^^^^^^^^^^^^
18
19This module defines the following :prop_tgt:`IMPORTED` targets:
20
21``OpenSSL::SSL``
22The OpenSSL ``ssl`` library, if found.
23``OpenSSL::Crypto``
24The OpenSSL ``crypto`` library, if found.
25``OpenSSL::applink``
26The OpenSSL ``applink`` components that might be need to be compiled into
27projects under MSVC. This target is available only if found OpenSSL version
28is not less than 0.9.8. By linking this target the above OpenSSL targets can
29be linked even if the project has different MSVC runtime configurations with
30the above OpenSSL targets. This target has no effect on platforms other than
31MSVC.
32
33NOTE: Due to how ``INTERFACE_SOURCES`` are consumed by the consuming target,
34unless you certainly know what you are doing, it is always preferred to link
35``OpenSSL::applink`` target as ``PRIVATE`` and to make sure that this target is
36linked at most once for the whole dependency graph of any library or
37executable:
38
39.. code-block:: cmake
40
41target_link_libraries(myTarget PRIVATE OpenSSL::applink)
42
43Otherwise you would probably encounter unexpected random problems when building
44and linking, as both the ISO C and the ISO C++ standard claims almost nothing
45about what a link process should be.
46
47Result Variables
48^^^^^^^^^^^^^^^^
49
50This module will set the following variables in your project:
51
52``OPENSSL_FOUND``
53System has the OpenSSL library. If no components are requested it only
54requires the crypto library.
55``OPENSSL_INCLUDE_DIR``
56The OpenSSL include directory.
57``OPENSSL_CRYPTO_LIBRARY``
58The OpenSSL crypto library.
59``OPENSSL_CRYPTO_LIBRARIES``
60The OpenSSL crypto library and its dependencies.
61``OPENSSL_SSL_LIBRARY``
62The OpenSSL SSL library.
63``OPENSSL_SSL_LIBRARIES``
64The OpenSSL SSL library and its dependencies.
65``OPENSSL_LIBRARIES``
66All OpenSSL libraries and their dependencies.
67``OPENSSL_VERSION``
68This is set to ``$major.$minor.$revision$patch`` (e.g. ``0.9.8s``).
69``OPENSSL_APPLINK_SOURCE``
70The sources in the target ``OpenSSL::applink`` that is mentioned above. This
71variable shall always be undefined if found openssl version is less than
720.9.8 or if platform is not MSVC.
73
74Hints
75^^^^^
76
77Set ``OPENSSL_ROOT_DIR`` to the root directory of an OpenSSL installation.
78Set ``OPENSSL_USE_STATIC_LIBS`` to ``TRUE`` to look for static libraries.
79Set ``OPENSSL_MSVC_STATIC_RT`` set ``TRUE`` to choose the MT version of the lib.
80#]=======================================================================]
81
82set(OPENSSL_EXPECTED_VERSION "1.0")
83
84macro(_OpenSSL_test_and_find_dependencies ssl_library crypto_library)
85if((CMAKE_SYSTEM_NAME STREQUAL "Linux") AND
86(("${ssl_library}" MATCHES "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$") OR
87("${crypto_library}" MATCHES "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$")))
88set(_OpenSSL_has_dependencies TRUE)
89find_package(Threads)
90else()
91set(_OpenSSL_has_dependencies FALSE)
92endif()
93endmacro()
94
95function(_OpenSSL_add_dependencies libraries_var)
96if(CMAKE_THREAD_LIBS_INIT)
97list(APPEND ${libraries_var} ${CMAKE_THREAD_LIBS_INIT})
98endif()
99list(APPEND ${libraries_var} ${CMAKE_DL_LIBS})
100set(${libraries_var} ${${libraries_var}} PARENT_SCOPE)
101endfunction()
102
103function(_OpenSSL_target_add_dependencies target)
104if(_OpenSSL_has_dependencies)
105set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES Threads::Threads )
106set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS} )
107endif()
108endfunction()
109
110if (UNIX)
111find_package(PkgConfig QUIET)
112pkg_check_modules(_OPENSSL QUIET openssl)
113endif ()
114
115# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
116if(OPENSSL_USE_STATIC_LIBS)
117set(_openssl_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
118if(WIN32)
119set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
120else()
121set(CMAKE_FIND_LIBRARY_SUFFIXES .a )
122endif()
123endif()
124
125if (WIN32)
126# http://www.slproweb.com/products/Win32OpenSSL.html
127set(_OPENSSL_MSI_INSTALL_GUID "")
128if(PLATFORM EQUAL 64)
129set(_OPENSSL_MSI_INSTALL_GUID "117551DB-A110-4BBD-BB05-CFE0BCB3ED31")
130set(_OPENSSL_ROOT_HINTS
131${OPENSSL_ROOT_DIR}
132ENV OPENSSL_ROOT_DIR
133"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (64-bit)_is1;Inno Setup: App Path]"
134)
135file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles)
136set(_OPENSSL_ROOT_PATHS
137"${_programfiles}/OpenSSL"
138"${_programfiles}/OpenSSL-Win64"
139"C:/OpenSSL/"
140"C:/OpenSSL-Win64/"
141)
142else()
143set(_OPENSSL_MSI_INSTALL_GUID "A1EEC576-43B9-4E75-9E02-03DA542D2A38")
144set(_OPENSSL_ROOT_HINTS
145${OPENSSL_ROOT_DIR}
146ENV OPENSSL_ROOT_DIR
147"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (32-bit)_is1;Inno Setup: App Path]"
148)
149file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles)
150set(_OPENSSL_ROOT_PATHS
151"${_programfiles}/OpenSSL"
152"${_programfiles}/OpenSSL-Win32"
153"C:/OpenSSL/"
154"C:/OpenSSL-Win32/"
155)
156endif()
157unset(_programfiles)
158# If OpenSSL was installed using .msi package instead of .exe, Inno Setup registry values are not written to Uninstall\OpenSSL
159# but because it is only a shim around Inno Setup it does write the location of uninstaller which we can use to determine path
160get_filename_component(_OPENSSL_MSI_INSTALL_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Inno Setup MSIs\\${_OPENSSL_MSI_INSTALL_GUID};]" DIRECTORY)
161if(NOT _OPENSSL_MSI_INSTALL_PATH STREQUAL "/")
162list(INSERT _OPENSSL_ROOT_HINTS 0 ${_OPENSSL_MSI_INSTALL_PATH})
163endif()
164else ()
165set(_OPENSSL_ROOT_HINTS
166${OPENSSL_ROOT_DIR}
167ENV OPENSSL_ROOT_DIR
168)
169endif ()
170
171set(_OPENSSL_ROOT_HINTS_AND_PATHS
172HINTS ${_OPENSSL_ROOT_HINTS}
173PATHS ${_OPENSSL_ROOT_PATHS}
174)
175
176find_path(OPENSSL_INCLUDE_DIR
177NAMES
178openssl/ssl.h
179${_OPENSSL_ROOT_HINTS_AND_PATHS}
180HINTS
181${_OPENSSL_INCLUDEDIR}
182${_OPENSSL_INCLUDE_DIRS}
183PATH_SUFFIXES
184include
185)
186
187if(WIN32 AND NOT CYGWIN)
188if(MSVC)
189# /MD and /MDd are the standard values - if someone wants to use
190# others, the libnames have to change here too
191# use also ssl and ssleay32 in debug as fallback for openssl < 0.9.8b
192# enable OPENSSL_MSVC_STATIC_RT to get the libs build /MT (Multithreaded no-DLL)
193# In Visual C++ naming convention each of these four kinds of Windows libraries has it's standard suffix:
194# * MD for dynamic-release
195# * MDd for dynamic-debug
196# * MT for static-release
197# * MTd for static-debug
198
199# Implementation details:
200# We are using the libraries located in the VC subdir instead of the parent directory even though :
201# libeay32MD.lib is identical to ../libeay32.lib, and
202# ssleay32MD.lib is identical to ../ssleay32.lib
203# enable OPENSSL_USE_STATIC_LIBS to use the static libs located in lib/VC/static
204
205if (OPENSSL_MSVC_STATIC_RT)
206set(_OPENSSL_MSVC_RT_MODE "MT")
207else ()
208set(_OPENSSL_MSVC_RT_MODE "MD")
209endif ()
210
211# Since OpenSSL 1.1, lib names are like libcrypto32MTd.lib and libssl32MTd.lib
212if( "${CMAKE_SIZEOF_VOID_P}" STREQUAL "8" )
213set(_OPENSSL_MSVC_ARCH_SUFFIX "64")
214else()
215set(_OPENSSL_MSVC_ARCH_SUFFIX "32")
216endif()
217
218if(OPENSSL_USE_STATIC_LIBS)
219set(_OPENSSL_STATIC_SUFFIX
220"_static"
221)
222set(_OPENSSL_PATH_SUFFIXES
223"lib/VC/static"
224"VC/static"
225"lib"
226)
227else()
228set(_OPENSSL_STATIC_SUFFIX
229""
230)
231set(_OPENSSL_PATH_SUFFIXES
232"lib/VC"
233"VC"
234"lib"
235)
236endif ()
237
238find_library(LIB_EAY_DEBUG
239NAMES
240# When OpenSSL is built with default options, the static library name is suffixed with "_static".
241# Looking the "libcrypto_static.lib" with a higher priority than "libcrypto.lib" which is the
242# import library of "libcrypto.dll".
243libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d
244libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d
245libcrypto${_OPENSSL_STATIC_SUFFIX}d
246libeay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d
247libeay32${_OPENSSL_STATIC_SUFFIX}d
248crypto${_OPENSSL_STATIC_SUFFIX}d
249# When OpenSSL is built with the "-static" option, only the static build is produced,
250# and it is not suffixed with "_static".
251libcrypto${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d
252libcrypto${_OPENSSL_MSVC_RT_MODE}d
253libcryptod
254libeay32${_OPENSSL_MSVC_RT_MODE}d
255libeay32d
256cryptod
257NAMES_PER_DIR
258${_OPENSSL_ROOT_HINTS_AND_PATHS}
259PATH_SUFFIXES
260${_OPENSSL_PATH_SUFFIXES}
261)
262
263find_library(LIB_EAY_RELEASE
264NAMES
265# When OpenSSL is built with default options, the static library name is suffixed with "_static".
266# Looking the "libcrypto_static.lib" with a higher priority than "libcrypto.lib" which is the
267# import library of "libcrypto.dll".
268libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}
269libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}
270libcrypto${_OPENSSL_STATIC_SUFFIX}
271libeay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}
272libeay32${_OPENSSL_STATIC_SUFFIX}
273crypto${_OPENSSL_STATIC_SUFFIX}
274# When OpenSSL is built with the "-static" option, only the static build is produced,
275# and it is not suffixed with "_static".
276libcrypto${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}
277libcrypto${_OPENSSL_MSVC_RT_MODE}
278libcrypto
279libeay32${_OPENSSL_MSVC_RT_MODE}
280libeay32
281crypto
282NAMES_PER_DIR
283${_OPENSSL_ROOT_HINTS_AND_PATHS}
284PATH_SUFFIXES
285${_OPENSSL_PATH_SUFFIXES}
286)
287
288find_library(SSL_EAY_DEBUG
289NAMES
290# When OpenSSL is built with default options, the static library name is suffixed with "_static".
291# Looking the "libssl_static.lib" with a higher priority than "libssl.lib" which is the
292# import library of "libssl.dll".
293libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d
294libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d
295libssl${_OPENSSL_STATIC_SUFFIX}d
296ssleay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d
297ssleay32${_OPENSSL_STATIC_SUFFIX}d
298ssl${_OPENSSL_STATIC_SUFFIX}d
299# When OpenSSL is built with the "-static" option, only the static build is produced,
300# and it is not suffixed with "_static".
301libssl${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d
302libssl${_OPENSSL_MSVC_RT_MODE}d
303libssld
304ssleay32${_OPENSSL_MSVC_RT_MODE}d
305ssleay32d
306ssld
307NAMES_PER_DIR
308${_OPENSSL_ROOT_HINTS_AND_PATHS}
309PATH_SUFFIXES
310${_OPENSSL_PATH_SUFFIXES}
311)
312
313find_library(SSL_EAY_RELEASE
314NAMES
315# When OpenSSL is built with default options, the static library name is suffixed with "_static".
316# Looking the "libssl_static.lib" with a higher priority than "libssl.lib" which is the
317# import library of "libssl.dll".
318libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}
319libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}
320libssl${_OPENSSL_STATIC_SUFFIX}
321ssleay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}
322ssleay32${_OPENSSL_STATIC_SUFFIX}
323ssl${_OPENSSL_STATIC_SUFFIX}
324# When OpenSSL is built with the "-static" option, only the static build is produced,
325# and it is not suffixed with "_static".
326libssl${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}
327libssl${_OPENSSL_MSVC_RT_MODE}
328libssl
329ssleay32${_OPENSSL_MSVC_RT_MODE}
330ssleay32
331ssl
332NAMES_PER_DIR
333${_OPENSSL_ROOT_HINTS_AND_PATHS}
334PATH_SUFFIXES
335${_OPENSSL_PATH_SUFFIXES}
336)
337
338set(LIB_EAY_LIBRARY_DEBUG "${LIB_EAY_DEBUG}")
339set(LIB_EAY_LIBRARY_RELEASE "${LIB_EAY_RELEASE}")
340set(SSL_EAY_LIBRARY_DEBUG "${SSL_EAY_DEBUG}")
341set(SSL_EAY_LIBRARY_RELEASE "${SSL_EAY_RELEASE}")
342
343include(SelectLibraryConfigurations)
344select_library_configurations(LIB_EAY)
345select_library_configurations(SSL_EAY)
346
347mark_as_advanced(LIB_EAY_LIBRARY_DEBUG LIB_EAY_LIBRARY_RELEASE
348SSL_EAY_LIBRARY_DEBUG SSL_EAY_LIBRARY_RELEASE)
349set(OPENSSL_SSL_LIBRARY ${SSL_EAY_LIBRARY} )
350set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY_LIBRARY} )
351elseif(MINGW)
352# same player, for MinGW
353set(LIB_EAY_NAMES crypto libeay32)
354set(SSL_EAY_NAMES ssl ssleay32)
355find_library(LIB_EAY
356NAMES
357${LIB_EAY_NAMES}
358NAMES_PER_DIR
359${_OPENSSL_ROOT_HINTS_AND_PATHS}
360PATH_SUFFIXES
361"lib/MinGW"
362"lib"
363)
364
365find_library(SSL_EAY
366NAMES
367${SSL_EAY_NAMES}
368NAMES_PER_DIR
369${_OPENSSL_ROOT_HINTS_AND_PATHS}
370PATH_SUFFIXES
371"lib/MinGW"
372"lib"
373)
374
375mark_as_advanced(SSL_EAY LIB_EAY)
376set(OPENSSL_SSL_LIBRARY ${SSL_EAY} )
377set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY} )
378unset(LIB_EAY_NAMES)
379unset(SSL_EAY_NAMES)
380else()
381# Not sure what to pick for -say- intel, let's use the toplevel ones and hope someone report issues:
382find_library(LIB_EAY
383NAMES
384libcrypto
385libeay32
386NAMES_PER_DIR
387${_OPENSSL_ROOT_HINTS_AND_PATHS}
388HINTS
389${_OPENSSL_LIBDIR}
390PATH_SUFFIXES
391lib
392)
393
394find_library(SSL_EAY
395NAMES
396libssl
397ssleay32
398NAMES_PER_DIR
399${_OPENSSL_ROOT_HINTS_AND_PATHS}
400HINTS
401${_OPENSSL_LIBDIR}
402PATH_SUFFIXES
403lib
404)
405
406mark_as_advanced(SSL_EAY LIB_EAY)
407set(OPENSSL_SSL_LIBRARY ${SSL_EAY} )
408set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY} )
409endif()
410else()
411
412find_library(OPENSSL_SSL_LIBRARY
413NAMES
414ssl
415ssleay32
416ssleay32MD
417NAMES_PER_DIR
418${_OPENSSL_ROOT_HINTS_AND_PATHS}
419HINTS
420${_OPENSSL_LIBDIR}
421${_OPENSSL_LIBRARY_DIRS}
422PATH_SUFFIXES
423lib
424)
425
426find_library(OPENSSL_CRYPTO_LIBRARY
427NAMES
428crypto
429NAMES_PER_DIR
430${_OPENSSL_ROOT_HINTS_AND_PATHS}
431HINTS
432${_OPENSSL_LIBDIR}
433${_OPENSSL_LIBRARY_DIRS}
434PATH_SUFFIXES
435lib
436)
437
438mark_as_advanced(OPENSSL_CRYPTO_LIBRARY OPENSSL_SSL_LIBRARY)
439
440endif()
441
442set(OPENSSL_SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY})
443set(OPENSSL_CRYPTO_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY})
444set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARIES} )
445_OpenSSL_test_and_find_dependencies("${OPENSSL_SSL_LIBRARY}" "${OPENSSL_CRYPTO_LIBRARY}")
446if(_OpenSSL_has_dependencies)
447_OpenSSL_add_dependencies( OPENSSL_SSL_LIBRARIES )
448_OpenSSL_add_dependencies( OPENSSL_CRYPTO_LIBRARIES )
449_OpenSSL_add_dependencies( OPENSSL_LIBRARIES )
450endif()
451
452function(from_hex HEX DEC)
453string(TOUPPER "${HEX}" HEX)
454set(_res 0)
455string(LENGTH "${HEX}" _strlen)
456
457while (_strlen GREATER 0)
458math(EXPR _res "${_res} * 16")
459string(SUBSTRING "${HEX}" 0 1 NIBBLE)
460string(SUBSTRING "${HEX}" 1 -1 HEX)
461if (NIBBLE STREQUAL "A")
462math(EXPR _res "${_res} + 10")
463elseif (NIBBLE STREQUAL "B")
464math(EXPR _res "${_res} + 11")
465elseif (NIBBLE STREQUAL "C")
466math(EXPR _res "${_res} + 12")
467elseif (NIBBLE STREQUAL "D")
468math(EXPR _res "${_res} + 13")
469elseif (NIBBLE STREQUAL "E")
470math(EXPR _res "${_res} + 14")
471elseif (NIBBLE STREQUAL "F")
472math(EXPR _res "${_res} + 15")
473else()
474math(EXPR _res "${_res} + ${NIBBLE}")
475endif()
476
477string(LENGTH "${HEX}" _strlen)
478endwhile()
479
480set(${DEC} ${_res} PARENT_SCOPE)
481endfunction()
482
483if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h")
484file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" openssl_version_str
485REGEX "^#[\t ]*define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*")
486
487if(openssl_version_str)
488# The version number is encoded as 0xMNNFFPPS: major minor fix patch status
489# The status gives if this is a developer or prerelease and is ignored here.
490# Major, minor, and fix directly translate into the version numbers shown in
491# the string. The patch field translates to the single character suffix that
492# indicates the bug fix state, which 00 -> nothing, 01 -> a, 02 -> b and so
493# on.
494
495string(REGEX REPLACE "^.*OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F]).*$"
496"\\1;\\2;\\3;\\4;\\5" OPENSSL_VERSION_LIST "${openssl_version_str}")
497list(GET OPENSSL_VERSION_LIST 0 OPENSSL_VERSION_MAJOR)
498list(GET OPENSSL_VERSION_LIST 1 OPENSSL_VERSION_MINOR)
499from_hex("${OPENSSL_VERSION_MINOR}" OPENSSL_VERSION_MINOR)
500list(GET OPENSSL_VERSION_LIST 2 OPENSSL_VERSION_FIX)
501from_hex("${OPENSSL_VERSION_FIX}" OPENSSL_VERSION_FIX)
502list(GET OPENSSL_VERSION_LIST 3 OPENSSL_VERSION_PATCH)
503
504if (NOT OPENSSL_VERSION_PATCH STREQUAL "00")
505from_hex("${OPENSSL_VERSION_PATCH}" _tmp)
506# 96 is the ASCII code of 'a' minus 1
507math(EXPR OPENSSL_VERSION_PATCH_ASCII "${_tmp} + 96")
508unset(_tmp)
509# Once anyone knows how OpenSSL would call the patch versions beyond 'z'
510# this should be updated to handle that, too. This has not happened yet
511# so it is simply ignored here for now.
512string(ASCII "${OPENSSL_VERSION_PATCH_ASCII}" OPENSSL_VERSION_PATCH_STRING)
513endif ()
514
515set(OPENSSL_VERSION "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_FIX}${OPENSSL_VERSION_PATCH_STRING}")
516else ()
517# Since OpenSSL 3.0.0, the new version format is MAJOR.MINOR.PATCH and
518# a new OPENSSL_VERSION_STR macro contains exactly that
519file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" OPENSSL_VERSION_STR
520REGEX "^#[\t ]*define[\t ]+OPENSSL_VERSION_STR[\t ]+\"([0-9])+\\.([0-9])+\\.([0-9])+\".*")
521string(REGEX REPLACE "^.*OPENSSL_VERSION_STR[\t ]+\"([0-9]+\\.[0-9]+\\.[0-9]+)\".*$"
522"\\1" OPENSSL_VERSION_STR "${OPENSSL_VERSION_STR}")
523
524set(OPENSSL_VERSION "${OPENSSL_VERSION_STR}")
525
526unset(OPENSSL_VERSION_STR)
527endif ()
528endif ()
529
530foreach(_comp IN LISTS OpenSSL_FIND_COMPONENTS)
531if(_comp STREQUAL "Crypto")
532if(EXISTS "${OPENSSL_INCLUDE_DIR}" AND
533(EXISTS "${OPENSSL_CRYPTO_LIBRARY}" OR
534EXISTS "${LIB_EAY_LIBRARY_DEBUG}" OR
535EXISTS "${LIB_EAY_LIBRARY_RELEASE}")
536)
537set(OpenSSL_${_comp}_FOUND TRUE)
538else()
539set(OpenSSL_${_comp}_FOUND FALSE)
540endif()
541elseif(_comp STREQUAL "SSL")
542if(EXISTS "${OPENSSL_INCLUDE_DIR}" AND
543(EXISTS "${OPENSSL_SSL_LIBRARY}" OR
544EXISTS "${SSL_EAY_LIBRARY_DEBUG}" OR
545EXISTS "${SSL_EAY_LIBRARY_RELEASE}")
546)
547set(OpenSSL_${_comp}_FOUND TRUE)
548else()
549set(OpenSSL_${_comp}_FOUND FALSE)
550endif()
551else()
552message(WARNING "${_comp} is not a valid OpenSSL component")
553set(OpenSSL_${_comp}_FOUND FALSE)
554endif()
555endforeach()
556unset(_comp)
557
558include(FindPackageHandleStandardArgs)
559find_package_handle_standard_args(OpenSSL
560REQUIRED_VARS
561OPENSSL_CRYPTO_LIBRARY
562OPENSSL_INCLUDE_DIR
563VERSION_VAR
564OPENSSL_VERSION
565HANDLE_COMPONENTS
566FAIL_MESSAGE
567"Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR"
568)
569
570mark_as_advanced(OPENSSL_INCLUDE_DIR)
571
572if(OPENSSL_FOUND)
573message(STATUS "Found OpenSSL library: ${OPENSSL_LIBRARIES}")
574message(STATUS "Found OpenSSL headers: ${OPENSSL_INCLUDE_DIR}")
575include(EnsureVersion)
576ENSURE_VERSION("${OPENSSL_EXPECTED_VERSION}" "${OPENSSL_VERSION}" OPENSSL_VERSION_OK)
577if(NOT OPENSSL_VERSION_OK)
578message(FATAL_ERROR "TrinityCore needs OpenSSL version ${OPENSSL_EXPECTED_VERSION} but found too new version ${OPENSSL_VERSION}. TrinityCore needs OpenSSL 1.0.x or 1.1.x to work properly. If you still have problems please install OpenSSL 1.0.x if you still have problems search on forum for TCE00022")
579endif()
580
581if(NOT TARGET OpenSSL::Crypto AND
582(EXISTS "${OPENSSL_CRYPTO_LIBRARY}" OR
583EXISTS "${LIB_EAY_LIBRARY_DEBUG}" OR
584EXISTS "${LIB_EAY_LIBRARY_RELEASE}")
585)
586add_library(OpenSSL::Crypto UNKNOWN IMPORTED)
587set_target_properties(OpenSSL::Crypto PROPERTIES
588INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}")
589if(EXISTS "${OPENSSL_CRYPTO_LIBRARY}")
590set_target_properties(OpenSSL::Crypto PROPERTIES
591IMPORTED_LINK_INTERFACE_LANGUAGES "C"
592IMPORTED_LOCATION "${OPENSSL_CRYPTO_LIBRARY}")
593endif()
594if(EXISTS "${LIB_EAY_LIBRARY_RELEASE}")
595set_property(TARGET OpenSSL::Crypto APPEND PROPERTY
596IMPORTED_CONFIGURATIONS RELEASE)
597set_target_properties(OpenSSL::Crypto PROPERTIES
598IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
599IMPORTED_LOCATION_RELEASE "${LIB_EAY_LIBRARY_RELEASE}")
600endif()
601if(EXISTS "${LIB_EAY_LIBRARY_DEBUG}")
602set_property(TARGET OpenSSL::Crypto APPEND PROPERTY
603IMPORTED_CONFIGURATIONS DEBUG)
604set_target_properties(OpenSSL::Crypto PROPERTIES
605IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
606IMPORTED_LOCATION_DEBUG "${LIB_EAY_LIBRARY_DEBUG}")
607endif()
608_OpenSSL_target_add_dependencies(OpenSSL::Crypto)
609endif()
610
611if(NOT TARGET OpenSSL::SSL AND
612(EXISTS "${OPENSSL_SSL_LIBRARY}" OR
613EXISTS "${SSL_EAY_LIBRARY_DEBUG}" OR
614EXISTS "${SSL_EAY_LIBRARY_RELEASE}")
615)
616add_library(OpenSSL::SSL UNKNOWN IMPORTED)
617set_target_properties(OpenSSL::SSL PROPERTIES
618INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}")
619if(EXISTS "${OPENSSL_SSL_LIBRARY}")
620set_target_properties(OpenSSL::SSL PROPERTIES
621IMPORTED_LINK_INTERFACE_LANGUAGES "C"
622IMPORTED_LOCATION "${OPENSSL_SSL_LIBRARY}")
623endif()
624if(EXISTS "${SSL_EAY_LIBRARY_RELEASE}")
625set_property(TARGET OpenSSL::SSL APPEND PROPERTY
626IMPORTED_CONFIGURATIONS RELEASE)
627set_target_properties(OpenSSL::SSL PROPERTIES
628IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
629IMPORTED_LOCATION_RELEASE "${SSL_EAY_LIBRARY_RELEASE}")
630endif()
631if(EXISTS "${SSL_EAY_LIBRARY_DEBUG}")
632set_property(TARGET OpenSSL::SSL APPEND PROPERTY
633IMPORTED_CONFIGURATIONS DEBUG)
634set_target_properties(OpenSSL::SSL PROPERTIES
635IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
636IMPORTED_LOCATION_DEBUG "${SSL_EAY_LIBRARY_DEBUG}")
637endif()
638if(TARGET OpenSSL::Crypto)
639set_target_properties(OpenSSL::SSL PROPERTIES
640INTERFACE_LINK_LIBRARIES OpenSSL::Crypto)
641endif()
642_OpenSSL_target_add_dependencies(OpenSSL::SSL)
643endif()
644
645if("${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_FIX}" VERSION_GREATER_EQUAL "0.9.8")
646if(MSVC)
647if(EXISTS "${OPENSSL_INCLUDE_DIR}")
648set(_OPENSSL_applink_paths PATHS ${OPENSSL_INCLUDE_DIR})
649endif()
650find_file(OPENSSL_APPLINK_SOURCE
651NAMES
652openssl/applink.c
653${_OPENSSL_applink_paths}
654NO_DEFAULT_PATH)
655if(OPENSSL_APPLINK_SOURCE)
656set(_OPENSSL_applink_interface_srcs ${OPENSSL_APPLINK_SOURCE})
657endif()
658endif()
659if(NOT TARGET OpenSSL::applink)
660add_library(OpenSSL::applink INTERFACE IMPORTED)
661set_property(TARGET OpenSSL::applink APPEND
662PROPERTY INTERFACE_SOURCES
663${_OPENSSL_applink_interface_srcs})
664endif()
665endif()
666endif()
667
668# Restore the original find library ordering
669if(OPENSSL_USE_STATIC_LIBS)
670set(CMAKE_FIND_LIBRARY_SUFFIXES ${_openssl_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
671endif()
672