Legends-of-Azeroth-Pandaria-5.4.8

Форк
0
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:
5
FindOpenSSL
6
-----------
7

8
Find the OpenSSL encryption library.
9

10
Optional COMPONENTS
11
^^^^^^^^^^^^^^^^^^^
12

13
This module supports two optional COMPONENTS: ``Crypto`` and ``SSL``.  Both
14
components have associated imported targets, as described below.
15

16
Imported Targets
17
^^^^^^^^^^^^^^^^
18

19
This module defines the following :prop_tgt:`IMPORTED` targets:
20

21
``OpenSSL::SSL``
22
  The OpenSSL ``ssl`` library, if found.
23
``OpenSSL::Crypto``
24
  The OpenSSL ``crypto`` library, if found.
25
``OpenSSL::applink``
26
  The OpenSSL ``applink`` components that might be need to be compiled into
27
  projects under MSVC. This target is available only if found OpenSSL version
28
  is not less than 0.9.8. By linking this target the above OpenSSL targets can
29
  be linked even if the project has different MSVC runtime configurations with
30
  the above OpenSSL targets. This target has no effect on platforms other than
31
  MSVC.
32

33
NOTE: Due to how ``INTERFACE_SOURCES`` are consumed by the consuming target,
34
unless 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
36
linked at most once for the whole dependency graph of any library or
37
executable:
38

39
.. code-block:: cmake
40

41
   target_link_libraries(myTarget PRIVATE OpenSSL::applink)
42

43
Otherwise you would probably encounter unexpected random problems when building
44
and linking, as both the ISO C and the ISO C++ standard claims almost nothing
45
about what a link process should be.
46

47
Result Variables
48
^^^^^^^^^^^^^^^^
49

50
This module will set the following variables in your project:
51

52
``OPENSSL_FOUND``
53
  System has the OpenSSL library. If no components are requested it only
54
  requires the crypto library.
55
``OPENSSL_INCLUDE_DIR``
56
  The OpenSSL include directory.
57
``OPENSSL_CRYPTO_LIBRARY``
58
  The OpenSSL crypto library.
59
``OPENSSL_CRYPTO_LIBRARIES``
60
  The OpenSSL crypto library and its dependencies.
61
``OPENSSL_SSL_LIBRARY``
62
  The OpenSSL SSL library.
63
``OPENSSL_SSL_LIBRARIES``
64
  The OpenSSL SSL library and its dependencies.
65
``OPENSSL_LIBRARIES``
66
  All OpenSSL libraries and their dependencies.
67
``OPENSSL_VERSION``
68
  This is set to ``$major.$minor.$revision$patch`` (e.g. ``0.9.8s``).
69
``OPENSSL_APPLINK_SOURCE``
70
  The sources in the target ``OpenSSL::applink`` that is mentioned above. This
71
  variable shall always be undefined if found openssl version is less than
72
  0.9.8 or if platform is not MSVC.
73

74
Hints
75
^^^^^
76

77
Set ``OPENSSL_ROOT_DIR`` to the root directory of an OpenSSL installation.
78
Set ``OPENSSL_USE_STATIC_LIBS`` to ``TRUE`` to look for static libraries.
79
Set ``OPENSSL_MSVC_STATIC_RT`` set ``TRUE`` to choose the MT version of the lib.
80
#]=======================================================================]
81

82
set(OPENSSL_EXPECTED_VERSION "1.0")
83

84
macro(_OpenSSL_test_and_find_dependencies ssl_library crypto_library)
85
  if((CMAKE_SYSTEM_NAME STREQUAL "Linux") AND
86
     (("${ssl_library}" MATCHES "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$") OR
87
      ("${crypto_library}" MATCHES "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$")))
88
    set(_OpenSSL_has_dependencies TRUE)
89
    find_package(Threads)
90
  else()
91
    set(_OpenSSL_has_dependencies FALSE)
92
  endif()
93
endmacro()
94

95
function(_OpenSSL_add_dependencies libraries_var)
96
  if(CMAKE_THREAD_LIBS_INIT)
97
    list(APPEND ${libraries_var} ${CMAKE_THREAD_LIBS_INIT})
98
  endif()
99
  list(APPEND ${libraries_var} ${CMAKE_DL_LIBS})
100
  set(${libraries_var} ${${libraries_var}} PARENT_SCOPE)
101
endfunction()
102

103
function(_OpenSSL_target_add_dependencies target)
104
  if(_OpenSSL_has_dependencies)
105
    set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES Threads::Threads )
106
    set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS} )
107
  endif()
108
endfunction()
109

110
if (UNIX)
111
  find_package(PkgConfig QUIET)
112
  pkg_check_modules(_OPENSSL QUIET openssl)
113
endif ()
114

115
# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
116
if(OPENSSL_USE_STATIC_LIBS)
117
  set(_openssl_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
118
  if(WIN32)
119
    set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
120
  else()
121
    set(CMAKE_FIND_LIBRARY_SUFFIXES .a )
122
  endif()
123
endif()
124

125
if (WIN32)
126
  # http://www.slproweb.com/products/Win32OpenSSL.html
127
  set(_OPENSSL_MSI_INSTALL_GUID "")
128
  if(PLATFORM EQUAL 64)
129
    set(_OPENSSL_MSI_INSTALL_GUID "117551DB-A110-4BBD-BB05-CFE0BCB3ED31")
130
    set(_OPENSSL_ROOT_HINTS
131
      ${OPENSSL_ROOT_DIR}
132
      ENV OPENSSL_ROOT_DIR
133
      "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (64-bit)_is1;Inno Setup: App Path]"
134
      )
135
    file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles)
136
    set(_OPENSSL_ROOT_PATHS
137
      "${_programfiles}/OpenSSL"
138
      "${_programfiles}/OpenSSL-Win64"
139
      "C:/OpenSSL/"
140
      "C:/OpenSSL-Win64/"
141
      )
142
  else()
143
    set(_OPENSSL_MSI_INSTALL_GUID "A1EEC576-43B9-4E75-9E02-03DA542D2A38")
144
    set(_OPENSSL_ROOT_HINTS
145
      ${OPENSSL_ROOT_DIR}
146
      ENV OPENSSL_ROOT_DIR
147
      "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (32-bit)_is1;Inno Setup: App Path]"
148
      )
149
    file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles)
150
    set(_OPENSSL_ROOT_PATHS
151
      "${_programfiles}/OpenSSL"
152
      "${_programfiles}/OpenSSL-Win32"
153
      "C:/OpenSSL/"
154
      "C:/OpenSSL-Win32/"
155
      )
156
  endif()
157
  unset(_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
160
  get_filename_component(_OPENSSL_MSI_INSTALL_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Inno Setup MSIs\\${_OPENSSL_MSI_INSTALL_GUID};]" DIRECTORY)
161
  if(NOT _OPENSSL_MSI_INSTALL_PATH STREQUAL "/")
162
    list(INSERT _OPENSSL_ROOT_HINTS 0 ${_OPENSSL_MSI_INSTALL_PATH})
163
  endif()
164
else ()
165
  set(_OPENSSL_ROOT_HINTS
166
    ${OPENSSL_ROOT_DIR}
167
    ENV OPENSSL_ROOT_DIR
168
    )
169
endif ()
170

171
set(_OPENSSL_ROOT_HINTS_AND_PATHS
172
    HINTS ${_OPENSSL_ROOT_HINTS}
173
    PATHS ${_OPENSSL_ROOT_PATHS}
174
    )
175

176
find_path(OPENSSL_INCLUDE_DIR
177
  NAMES
178
    openssl/ssl.h
179
  ${_OPENSSL_ROOT_HINTS_AND_PATHS}
180
  HINTS
181
    ${_OPENSSL_INCLUDEDIR}
182
    ${_OPENSSL_INCLUDE_DIRS}
183
  PATH_SUFFIXES
184
    include
185
)
186

187
if(WIN32 AND NOT CYGWIN)
188
  if(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

205
    if (OPENSSL_MSVC_STATIC_RT)
206
      set(_OPENSSL_MSVC_RT_MODE "MT")
207
    else ()
208
      set(_OPENSSL_MSVC_RT_MODE "MD")
209
    endif ()
210

211
    # Since OpenSSL 1.1, lib names are like libcrypto32MTd.lib and libssl32MTd.lib
212
    if( "${CMAKE_SIZEOF_VOID_P}" STREQUAL "8" )
213
        set(_OPENSSL_MSVC_ARCH_SUFFIX "64")
214
    else()
215
        set(_OPENSSL_MSVC_ARCH_SUFFIX "32")
216
    endif()
217

218
    if(OPENSSL_USE_STATIC_LIBS)
219
      set(_OPENSSL_STATIC_SUFFIX
220
        "_static"
221
      )
222
      set(_OPENSSL_PATH_SUFFIXES
223
        "lib/VC/static"
224
        "VC/static"
225
        "lib"
226
        )
227
    else()
228
      set(_OPENSSL_STATIC_SUFFIX
229
        ""
230
      )
231
      set(_OPENSSL_PATH_SUFFIXES
232
        "lib/VC"
233
        "VC"
234
        "lib"
235
        )
236
    endif ()
237

238
    find_library(LIB_EAY_DEBUG
239
      NAMES
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".
243
        libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d
244
        libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d
245
        libcrypto${_OPENSSL_STATIC_SUFFIX}d
246
        libeay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d
247
        libeay32${_OPENSSL_STATIC_SUFFIX}d
248
        crypto${_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".
251
        libcrypto${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d
252
        libcrypto${_OPENSSL_MSVC_RT_MODE}d
253
        libcryptod
254
        libeay32${_OPENSSL_MSVC_RT_MODE}d
255
        libeay32d
256
        cryptod
257
      NAMES_PER_DIR
258
      ${_OPENSSL_ROOT_HINTS_AND_PATHS}
259
      PATH_SUFFIXES
260
        ${_OPENSSL_PATH_SUFFIXES}
261
    )
262

263
    find_library(LIB_EAY_RELEASE
264
      NAMES
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".
268
        libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}
269
        libcrypto${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}
270
        libcrypto${_OPENSSL_STATIC_SUFFIX}
271
        libeay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}
272
        libeay32${_OPENSSL_STATIC_SUFFIX}
273
        crypto${_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".
276
        libcrypto${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}
277
        libcrypto${_OPENSSL_MSVC_RT_MODE}
278
        libcrypto
279
        libeay32${_OPENSSL_MSVC_RT_MODE}
280
        libeay32
281
        crypto
282
      NAMES_PER_DIR
283
      ${_OPENSSL_ROOT_HINTS_AND_PATHS}
284
      PATH_SUFFIXES
285
        ${_OPENSSL_PATH_SUFFIXES}
286
    )
287

288
    find_library(SSL_EAY_DEBUG
289
      NAMES
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".
293
        libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d
294
        libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d
295
        libssl${_OPENSSL_STATIC_SUFFIX}d
296
        ssleay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d
297
        ssleay32${_OPENSSL_STATIC_SUFFIX}d
298
        ssl${_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".
301
        libssl${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}d
302
        libssl${_OPENSSL_MSVC_RT_MODE}d
303
        libssld
304
        ssleay32${_OPENSSL_MSVC_RT_MODE}d
305
        ssleay32d
306
        ssld
307
      NAMES_PER_DIR
308
      ${_OPENSSL_ROOT_HINTS_AND_PATHS}
309
      PATH_SUFFIXES
310
        ${_OPENSSL_PATH_SUFFIXES}
311
    )
312

313
    find_library(SSL_EAY_RELEASE
314
      NAMES
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".
318
        libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}
319
        libssl${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}
320
        libssl${_OPENSSL_STATIC_SUFFIX}
321
        ssleay32${_OPENSSL_STATIC_SUFFIX}${_OPENSSL_MSVC_RT_MODE}
322
        ssleay32${_OPENSSL_STATIC_SUFFIX}
323
        ssl${_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".
326
        libssl${_OPENSSL_MSVC_ARCH_SUFFIX}${_OPENSSL_MSVC_RT_MODE}
327
        libssl${_OPENSSL_MSVC_RT_MODE}
328
        libssl
329
        ssleay32${_OPENSSL_MSVC_RT_MODE}
330
        ssleay32
331
        ssl
332
      NAMES_PER_DIR
333
      ${_OPENSSL_ROOT_HINTS_AND_PATHS}
334
      PATH_SUFFIXES
335
        ${_OPENSSL_PATH_SUFFIXES}
336
    )
337

338
    set(LIB_EAY_LIBRARY_DEBUG "${LIB_EAY_DEBUG}")
339
    set(LIB_EAY_LIBRARY_RELEASE "${LIB_EAY_RELEASE}")
340
    set(SSL_EAY_LIBRARY_DEBUG "${SSL_EAY_DEBUG}")
341
    set(SSL_EAY_LIBRARY_RELEASE "${SSL_EAY_RELEASE}")
342

343
    include(SelectLibraryConfigurations)
344
    select_library_configurations(LIB_EAY)
345
    select_library_configurations(SSL_EAY)
346

347
    mark_as_advanced(LIB_EAY_LIBRARY_DEBUG LIB_EAY_LIBRARY_RELEASE
348
                     SSL_EAY_LIBRARY_DEBUG SSL_EAY_LIBRARY_RELEASE)
349
    set(OPENSSL_SSL_LIBRARY ${SSL_EAY_LIBRARY} )
350
    set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY_LIBRARY} )
351
  elseif(MINGW)
352
    # same player, for MinGW
353
    set(LIB_EAY_NAMES crypto libeay32)
354
    set(SSL_EAY_NAMES ssl ssleay32)
355
    find_library(LIB_EAY
356
      NAMES
357
        ${LIB_EAY_NAMES}
358
      NAMES_PER_DIR
359
      ${_OPENSSL_ROOT_HINTS_AND_PATHS}
360
      PATH_SUFFIXES
361
        "lib/MinGW"
362
        "lib"
363
    )
364

365
    find_library(SSL_EAY
366
      NAMES
367
        ${SSL_EAY_NAMES}
368
      NAMES_PER_DIR
369
      ${_OPENSSL_ROOT_HINTS_AND_PATHS}
370
      PATH_SUFFIXES
371
        "lib/MinGW"
372
        "lib"
373
    )
374

375
    mark_as_advanced(SSL_EAY LIB_EAY)
376
    set(OPENSSL_SSL_LIBRARY ${SSL_EAY} )
377
    set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY} )
378
    unset(LIB_EAY_NAMES)
379
    unset(SSL_EAY_NAMES)
380
  else()
381
    # Not sure what to pick for -say- intel, let's use the toplevel ones and hope someone report issues:
382
    find_library(LIB_EAY
383
      NAMES
384
        libcrypto
385
        libeay32
386
      NAMES_PER_DIR
387
      ${_OPENSSL_ROOT_HINTS_AND_PATHS}
388
      HINTS
389
        ${_OPENSSL_LIBDIR}
390
      PATH_SUFFIXES
391
        lib
392
    )
393

394
    find_library(SSL_EAY
395
      NAMES
396
        libssl
397
        ssleay32
398
      NAMES_PER_DIR
399
      ${_OPENSSL_ROOT_HINTS_AND_PATHS}
400
      HINTS
401
        ${_OPENSSL_LIBDIR}
402
      PATH_SUFFIXES
403
        lib
404
    )
405

406
    mark_as_advanced(SSL_EAY LIB_EAY)
407
    set(OPENSSL_SSL_LIBRARY ${SSL_EAY} )
408
    set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY} )
409
  endif()
410
else()
411

412
  find_library(OPENSSL_SSL_LIBRARY
413
    NAMES
414
      ssl
415
      ssleay32
416
      ssleay32MD
417
    NAMES_PER_DIR
418
    ${_OPENSSL_ROOT_HINTS_AND_PATHS}
419
    HINTS
420
      ${_OPENSSL_LIBDIR}
421
      ${_OPENSSL_LIBRARY_DIRS}
422
    PATH_SUFFIXES
423
      lib
424
  )
425

426
  find_library(OPENSSL_CRYPTO_LIBRARY
427
    NAMES
428
      crypto
429
    NAMES_PER_DIR
430
    ${_OPENSSL_ROOT_HINTS_AND_PATHS}
431
    HINTS
432
      ${_OPENSSL_LIBDIR}
433
      ${_OPENSSL_LIBRARY_DIRS}
434
    PATH_SUFFIXES
435
      lib
436
  )
437

438
  mark_as_advanced(OPENSSL_CRYPTO_LIBRARY OPENSSL_SSL_LIBRARY)
439

440
endif()
441

442
set(OPENSSL_SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY})
443
set(OPENSSL_CRYPTO_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY})
444
set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARIES} )
445
_OpenSSL_test_and_find_dependencies("${OPENSSL_SSL_LIBRARY}" "${OPENSSL_CRYPTO_LIBRARY}")
446
if(_OpenSSL_has_dependencies)
447
  _OpenSSL_add_dependencies( OPENSSL_SSL_LIBRARIES )
448
  _OpenSSL_add_dependencies( OPENSSL_CRYPTO_LIBRARIES )
449
  _OpenSSL_add_dependencies( OPENSSL_LIBRARIES )
450
endif()
451

452
function(from_hex HEX DEC)
453
  string(TOUPPER "${HEX}" HEX)
454
  set(_res 0)
455
  string(LENGTH "${HEX}" _strlen)
456

457
  while (_strlen GREATER 0)
458
    math(EXPR _res "${_res} * 16")
459
    string(SUBSTRING "${HEX}" 0 1 NIBBLE)
460
    string(SUBSTRING "${HEX}" 1 -1 HEX)
461
    if (NIBBLE STREQUAL "A")
462
      math(EXPR _res "${_res} + 10")
463
    elseif (NIBBLE STREQUAL "B")
464
      math(EXPR _res "${_res} + 11")
465
    elseif (NIBBLE STREQUAL "C")
466
      math(EXPR _res "${_res} + 12")
467
    elseif (NIBBLE STREQUAL "D")
468
      math(EXPR _res "${_res} + 13")
469
    elseif (NIBBLE STREQUAL "E")
470
      math(EXPR _res "${_res} + 14")
471
    elseif (NIBBLE STREQUAL "F")
472
      math(EXPR _res "${_res} + 15")
473
    else()
474
      math(EXPR _res "${_res} + ${NIBBLE}")
475
    endif()
476

477
    string(LENGTH "${HEX}" _strlen)
478
  endwhile()
479

480
  set(${DEC} ${_res} PARENT_SCOPE)
481
endfunction()
482

483
if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h")
484
  file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" openssl_version_str
485
       REGEX "^#[\t ]*define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*")
486

487
  if(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

495
    string(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}")
497
    list(GET OPENSSL_VERSION_LIST 0 OPENSSL_VERSION_MAJOR)
498
    list(GET OPENSSL_VERSION_LIST 1 OPENSSL_VERSION_MINOR)
499
    from_hex("${OPENSSL_VERSION_MINOR}" OPENSSL_VERSION_MINOR)
500
    list(GET OPENSSL_VERSION_LIST 2 OPENSSL_VERSION_FIX)
501
    from_hex("${OPENSSL_VERSION_FIX}" OPENSSL_VERSION_FIX)
502
    list(GET OPENSSL_VERSION_LIST 3 OPENSSL_VERSION_PATCH)
503

504
    if (NOT OPENSSL_VERSION_PATCH STREQUAL "00")
505
      from_hex("${OPENSSL_VERSION_PATCH}" _tmp)
506
      # 96 is the ASCII code of 'a' minus 1
507
      math(EXPR OPENSSL_VERSION_PATCH_ASCII "${_tmp} + 96")
508
      unset(_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.
512
      string(ASCII "${OPENSSL_VERSION_PATCH_ASCII}" OPENSSL_VERSION_PATCH_STRING)
513
    endif ()
514

515
    set(OPENSSL_VERSION "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_FIX}${OPENSSL_VERSION_PATCH_STRING}")
516
  else ()
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
519
    file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" OPENSSL_VERSION_STR
520
         REGEX "^#[\t ]*define[\t ]+OPENSSL_VERSION_STR[\t ]+\"([0-9])+\\.([0-9])+\\.([0-9])+\".*")
521
    string(REGEX REPLACE "^.*OPENSSL_VERSION_STR[\t ]+\"([0-9]+\\.[0-9]+\\.[0-9]+)\".*$"
522
           "\\1" OPENSSL_VERSION_STR "${OPENSSL_VERSION_STR}")
523

524
    set(OPENSSL_VERSION "${OPENSSL_VERSION_STR}")
525

526
    unset(OPENSSL_VERSION_STR)
527
  endif ()
528
endif ()
529

530
foreach(_comp IN LISTS OpenSSL_FIND_COMPONENTS)
531
  if(_comp STREQUAL "Crypto")
532
    if(EXISTS "${OPENSSL_INCLUDE_DIR}" AND
533
        (EXISTS "${OPENSSL_CRYPTO_LIBRARY}" OR
534
        EXISTS "${LIB_EAY_LIBRARY_DEBUG}" OR
535
        EXISTS "${LIB_EAY_LIBRARY_RELEASE}")
536
    )
537
      set(OpenSSL_${_comp}_FOUND TRUE)
538
    else()
539
      set(OpenSSL_${_comp}_FOUND FALSE)
540
    endif()
541
  elseif(_comp STREQUAL "SSL")
542
    if(EXISTS "${OPENSSL_INCLUDE_DIR}" AND
543
        (EXISTS "${OPENSSL_SSL_LIBRARY}" OR
544
        EXISTS "${SSL_EAY_LIBRARY_DEBUG}" OR
545
        EXISTS "${SSL_EAY_LIBRARY_RELEASE}")
546
    )
547
      set(OpenSSL_${_comp}_FOUND TRUE)
548
    else()
549
      set(OpenSSL_${_comp}_FOUND FALSE)
550
    endif()
551
  else()
552
    message(WARNING "${_comp} is not a valid OpenSSL component")
553
    set(OpenSSL_${_comp}_FOUND FALSE)
554
  endif()
555
endforeach()
556
unset(_comp)
557

558
include(FindPackageHandleStandardArgs)
559
find_package_handle_standard_args(OpenSSL
560
  REQUIRED_VARS
561
    OPENSSL_CRYPTO_LIBRARY
562
    OPENSSL_INCLUDE_DIR
563
  VERSION_VAR
564
    OPENSSL_VERSION
565
  HANDLE_COMPONENTS
566
  FAIL_MESSAGE
567
    "Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR"
568
)
569

570
mark_as_advanced(OPENSSL_INCLUDE_DIR)
571

572
if(OPENSSL_FOUND)
573
  message(STATUS "Found OpenSSL library: ${OPENSSL_LIBRARIES}")
574
  message(STATUS "Found OpenSSL headers: ${OPENSSL_INCLUDE_DIR}")
575
  include(EnsureVersion)
576
  ENSURE_VERSION("${OPENSSL_EXPECTED_VERSION}" "${OPENSSL_VERSION}" OPENSSL_VERSION_OK)
577
  if(NOT OPENSSL_VERSION_OK)
578
      message(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")
579
  endif()
580

581
  if(NOT TARGET OpenSSL::Crypto AND
582
      (EXISTS "${OPENSSL_CRYPTO_LIBRARY}" OR
583
        EXISTS "${LIB_EAY_LIBRARY_DEBUG}" OR
584
        EXISTS "${LIB_EAY_LIBRARY_RELEASE}")
585
      )
586
    add_library(OpenSSL::Crypto UNKNOWN IMPORTED)
587
    set_target_properties(OpenSSL::Crypto PROPERTIES
588
      INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}")
589
    if(EXISTS "${OPENSSL_CRYPTO_LIBRARY}")
590
      set_target_properties(OpenSSL::Crypto PROPERTIES
591
        IMPORTED_LINK_INTERFACE_LANGUAGES "C"
592
        IMPORTED_LOCATION "${OPENSSL_CRYPTO_LIBRARY}")
593
    endif()
594
    if(EXISTS "${LIB_EAY_LIBRARY_RELEASE}")
595
      set_property(TARGET OpenSSL::Crypto APPEND PROPERTY
596
        IMPORTED_CONFIGURATIONS RELEASE)
597
      set_target_properties(OpenSSL::Crypto PROPERTIES
598
        IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
599
        IMPORTED_LOCATION_RELEASE "${LIB_EAY_LIBRARY_RELEASE}")
600
    endif()
601
    if(EXISTS "${LIB_EAY_LIBRARY_DEBUG}")
602
      set_property(TARGET OpenSSL::Crypto APPEND PROPERTY
603
        IMPORTED_CONFIGURATIONS DEBUG)
604
      set_target_properties(OpenSSL::Crypto PROPERTIES
605
        IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
606
        IMPORTED_LOCATION_DEBUG "${LIB_EAY_LIBRARY_DEBUG}")
607
    endif()
608
    _OpenSSL_target_add_dependencies(OpenSSL::Crypto)
609
  endif()
610

611
  if(NOT TARGET OpenSSL::SSL AND
612
      (EXISTS "${OPENSSL_SSL_LIBRARY}" OR
613
        EXISTS "${SSL_EAY_LIBRARY_DEBUG}" OR
614
        EXISTS "${SSL_EAY_LIBRARY_RELEASE}")
615
      )
616
    add_library(OpenSSL::SSL UNKNOWN IMPORTED)
617
    set_target_properties(OpenSSL::SSL PROPERTIES
618
      INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}")
619
    if(EXISTS "${OPENSSL_SSL_LIBRARY}")
620
      set_target_properties(OpenSSL::SSL PROPERTIES
621
        IMPORTED_LINK_INTERFACE_LANGUAGES "C"
622
        IMPORTED_LOCATION "${OPENSSL_SSL_LIBRARY}")
623
    endif()
624
    if(EXISTS "${SSL_EAY_LIBRARY_RELEASE}")
625
      set_property(TARGET OpenSSL::SSL APPEND PROPERTY
626
        IMPORTED_CONFIGURATIONS RELEASE)
627
      set_target_properties(OpenSSL::SSL PROPERTIES
628
        IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
629
        IMPORTED_LOCATION_RELEASE "${SSL_EAY_LIBRARY_RELEASE}")
630
    endif()
631
    if(EXISTS "${SSL_EAY_LIBRARY_DEBUG}")
632
      set_property(TARGET OpenSSL::SSL APPEND PROPERTY
633
        IMPORTED_CONFIGURATIONS DEBUG)
634
      set_target_properties(OpenSSL::SSL PROPERTIES
635
        IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
636
        IMPORTED_LOCATION_DEBUG "${SSL_EAY_LIBRARY_DEBUG}")
637
    endif()
638
    if(TARGET OpenSSL::Crypto)
639
      set_target_properties(OpenSSL::SSL PROPERTIES
640
        INTERFACE_LINK_LIBRARIES OpenSSL::Crypto)
641
    endif()
642
    _OpenSSL_target_add_dependencies(OpenSSL::SSL)
643
  endif()
644

645
  if("${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_FIX}" VERSION_GREATER_EQUAL "0.9.8")
646
    if(MSVC)
647
      if(EXISTS "${OPENSSL_INCLUDE_DIR}")
648
        set(_OPENSSL_applink_paths PATHS ${OPENSSL_INCLUDE_DIR})
649
      endif()
650
      find_file(OPENSSL_APPLINK_SOURCE
651
        NAMES
652
          openssl/applink.c
653
        ${_OPENSSL_applink_paths}
654
        NO_DEFAULT_PATH)
655
      if(OPENSSL_APPLINK_SOURCE)
656
        set(_OPENSSL_applink_interface_srcs ${OPENSSL_APPLINK_SOURCE})
657
      endif()
658
    endif()
659
    if(NOT TARGET OpenSSL::applink)
660
      add_library(OpenSSL::applink INTERFACE IMPORTED)
661
      set_property(TARGET OpenSSL::applink APPEND
662
        PROPERTY INTERFACE_SOURCES
663
          ${_OPENSSL_applink_interface_srcs})
664
    endif()
665
  endif()
666
endif()
667

668
# Restore the original find library ordering
669
if(OPENSSL_USE_STATIC_LIBS)
670
  set(CMAKE_FIND_LIBRARY_SUFFIXES ${_openssl_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
671
endif()
672

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.