| 1 |
# - Try to find LibCrypto include dirs and libraries |
| 2 |
# |
| 3 |
# Usage of this module as follows: |
| 4 |
# |
| 5 |
# find_package(crypto) |
| 6 |
# |
| 7 |
# Variables used by this module, they can change the default behaviour and need |
| 8 |
# to be set before calling find_package: |
| 9 |
# |
| 10 |
# Variables defined by this module: |
| 11 |
# |
| 12 |
# crypto_FOUND System has libcrypto, include and library dirs found |
| 13 |
# crypto_INCLUDE_DIR The crypto include directories. |
| 14 |
# crypto_LIBRARY The crypto library, depending on the value of BUILD_SHARED_LIBS. |
| 15 |
# crypto_SHARED_LIBRARY The path to libcrypto.so |
| 16 |
# crypto_STATIC_LIBRARY The path to libcrypto.a |
| 17 |
|
| 18 |
# the next branch exists purely for cmake compatibility with versions older than 3.15. Please do not remove it before |
| 19 |
# we baseline on a newer version. It does not like duplicate target declarations. Work around that by checking it isn't |
| 20 |
# defined first. |
| 21 |
if (TARGET crypto OR TARGET AWS::crypto) |
| 22 |
if (TARGET crypto) |
| 23 |
set(TARGET_NAME "crypto") |
| 24 |
else() |
| 25 |
set(TARGET_NAME "AWS::crypto") |
| 26 |
endif() |
| 27 |
|
| 28 |
get_target_property(crypto_INCLUDE_DIR ${TARGET_NAME} INTERFACE_INCLUDE_DIRECTORIES) |
| 29 |
message(STATUS "S2N found target: ${TARGET_NAME}") |
| 30 |
message(STATUS "crypto Include Dir: ${crypto_INCLUDE_DIR}") |
| 31 |
set(CRYPTO_FOUND true) |
| 32 |
set(crypto_FOUND true) |
| 33 |
else() |
| 34 |
find_path(crypto_INCLUDE_DIR |
| 35 |
NAMES openssl/crypto.h |
| 36 |
HINTS |
| 37 |
"${CMAKE_PREFIX_PATH}" |
| 38 |
"${CMAKE_INSTALL_PREFIX}" |
| 39 |
PATH_SUFFIXES include |
| 40 |
) |
| 41 |
|
| 42 |
find_library(crypto_SHARED_LIBRARY |
| 43 |
NAMES libcrypto.so libcrypto.dylib |
| 44 |
HINTS |
| 45 |
"${CMAKE_PREFIX_PATH}" |
| 46 |
"${CMAKE_INSTALL_PREFIX}" |
| 47 |
PATH_SUFFIXES build/crypto build lib64 lib |
| 48 |
) |
| 49 |
|
| 50 |
find_library(crypto_STATIC_LIBRARY |
| 51 |
NAMES libcrypto.a |
| 52 |
HINTS |
| 53 |
"${CMAKE_PREFIX_PATH}" |
| 54 |
"${CMAKE_INSTALL_PREFIX}" |
| 55 |
PATH_SUFFIXES build/crypto build lib64 lib |
| 56 |
) |
| 57 |
|
| 58 |
if (NOT crypto_LIBRARY) |
| 59 |
if (BUILD_SHARED_LIBS OR S2N_USE_CRYPTO_SHARED_LIBS) |
| 60 |
if (crypto_SHARED_LIBRARY) |
| 61 |
set(crypto_LIBRARY ${crypto_SHARED_LIBRARY}) |
| 62 |
else() |
| 63 |
set(crypto_LIBRARY ${crypto_STATIC_LIBRARY}) |
| 64 |
endif() |
| 65 |
else() |
| 66 |
if (crypto_STATIC_LIBRARY) |
| 67 |
set(crypto_LIBRARY ${crypto_STATIC_LIBRARY}) |
| 68 |
else() |
| 69 |
set(crypto_LIBRARY ${crypto_SHARED_LIBRARY}) |
| 70 |
endif() |
| 71 |
endif() |
| 72 |
endif() |
| 73 |
|
| 74 |
include(FindPackageHandleStandardArgs) |
| 75 |
find_package_handle_standard_args(crypto DEFAULT_MSG |
| 76 |
crypto_LIBRARY |
| 77 |
crypto_INCLUDE_DIR |
| 78 |
) |
| 79 |
|
| 80 |
mark_as_advanced( |
| 81 |
crypto_ROOT_DIR |
| 82 |
crypto_INCLUDE_DIR |
| 83 |
crypto_LIBRARY |
| 84 |
crypto_SHARED_LIBRARY |
| 85 |
crypto_STATIC_LIBRARY |
| 86 |
) |
| 87 |
|
| 88 |
# some versions of cmake have a super esoteric bug around capitalization differences between |
| 89 |
# find dependency and find package, just avoid that here by checking and |
| 90 |
# setting both. |
| 91 |
if(CRYPTO_FOUND OR crypto_FOUND) |
| 92 |
set(CRYPTO_FOUND true) |
| 93 |
set(crypto_FOUND true) |
| 94 |
|
| 95 |
message(STATUS "LibCrypto Include Dir: ${crypto_INCLUDE_DIR}") |
| 96 |
message(STATUS "LibCrypto Shared Lib: ${crypto_SHARED_LIBRARY}") |
| 97 |
message(STATUS "LibCrypto Static Lib: ${crypto_STATIC_LIBRARY}") |
| 98 |
if (NOT TARGET crypto AND |
| 99 |
(EXISTS "${crypto_LIBRARY}") |
| 100 |
) |
| 101 |
set(THREADS_PREFER_PTHREAD_FLAG ON) |
| 102 |
find_package(Threads REQUIRED) |
| 103 |
add_library(AWS::crypto UNKNOWN IMPORTED) |
| 104 |
set_target_properties(AWS::crypto PROPERTIES |
| 105 |
INTERFACE_INCLUDE_DIRECTORIES "${crypto_INCLUDE_DIR}") |
| 106 |
set_target_properties(AWS::crypto PROPERTIES |
| 107 |
IMPORTED_LINK_INTERFACE_LANGUAGES "C" |
| 108 |
IMPORTED_LOCATION "${crypto_LIBRARY}") |
| 109 |
add_dependencies(AWS::crypto Threads::Threads) |
| 110 |
endif() |
| 111 |
endif() |
| 112 |
|
| 113 |
endif() |