Debian Codegraph @

crt/aws-c-cal/cmake/modules/Findcrypto.cmake

raw
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 # crypto_STATIC_LIBRARY The path to libcrypto.a
18
19 # the next branch exists purely for cmake compatibility with versions older than 3.15. Please do not remove it before
20 # we baseline on a newer version. It does not like duplicate target declarations. Work around that by checking it isn't
21 # defined first.
22 if (TARGET crypto OR TARGET AWS::crypto)
23 if (TARGET crypto)
24 set(TARGET_NAME "crypto")
25 else()
26 set(TARGET_NAME "AWS::crypto")
27 endif()
28
29 get_target_property(crypto_INCLUDE_DIR ${TARGET_NAME} INTERFACE_INCLUDE_DIRECTORIES)
30 message(STATUS "aws-c-cal found target: ${TARGET_NAME}")
31 message(STATUS "crypto Include Dir: ${crypto_INCLUDE_DIR}")
32 set(CRYPTO_FOUND true)
33 set(crypto_FOUND true)
34 else()
35
36 find_path(crypto_INCLUDE_DIR
37 NAMES openssl/crypto.h
38 HINTS
39 ${CMAKE_PREFIX_PATH}/include
40 ${CMAKE_INSTALL_PREFIX}/include
41 )
42
43 find_library(crypto_SHARED_LIBRARY
44 NAMES libcrypto.so libcrypto.dylib crypto.dll
45 HINTS
46 ${CMAKE_PREFIX_PATH}/build/crypto
47 ${CMAKE_PREFIX_PATH}/build
48 ${CMAKE_PREFIX_PATH}
49 ${CMAKE_PREFIX_PATH}/lib64
50 ${CMAKE_PREFIX_PATH}/lib
51 ${CMAKE_INSTALL_PREFIX}/build/crypto
52 ${CMAKE_INSTALL_PREFIX}/build
53 ${CMAKE_INSTALL_PREFIX}
54 ${CMAKE_INSTALL_PREFIX}/lib64
55 ${CMAKE_INSTALL_PREFIX}/lib
56 )
57
58 find_library(crypto_STATIC_LIBRARY
59 NAMES libcrypto.a crypto.lib
60 HINTS
61 ${CMAKE_PREFIX_PATH}/build/crypto
62 ${CMAKE_PREFIX_PATH}/build
63 ${CMAKE_PREFIX_PATH}
64 ${CMAKE_PREFIX_PATH}/lib64
65 ${CMAKE_PREFIX_PATH}/lib
66 ${CMAKE_INSTALL_PREFIX}/build/crypto
67 ${CMAKE_INSTALL_PREFIX}/build
68 ${CMAKE_INSTALL_PREFIX}
69 ${CMAKE_INSTALL_PREFIX}/lib64
70 ${CMAKE_INSTALL_PREFIX}/lib
71 )
72
73 if (BUILD_SHARED_LIBS OR AWS_USE_CRYPTO_SHARED_LIBS)
74 if (crypto_SHARED_LIBRARY)
75 set(crypto_LIBRARY ${crypto_SHARED_LIBRARY})
76 else()
77 set(crypto_LIBRARY ${crypto_STATIC_LIBRARY})
78 endif()
79 else()
80 if (crypto_STATIC_LIBRARY)
81 set(crypto_LIBRARY ${crypto_STATIC_LIBRARY})
82 else()
83 set(crypto_LIBRARY ${crypto_SHARED_LIBRARY})
84 endif()
85 endif()
86
87 include(FindPackageHandleStandardArgs)
88 find_package_handle_standard_args(crypto DEFAULT_MSG
89 crypto_LIBRARY
90 crypto_INCLUDE_DIR
91 )
92
93 mark_as_advanced(
94 crypto_ROOT_DIR
95 crypto_INCLUDE_DIR
96 crypto_LIBRARY
97 crypto_SHARED_LIBRARY
98 crypto_STATIC_LIBRARY
99 )
100
101 # some versions of cmake have a super esoteric bug around capitalization differences between
102 # find dependency and find package, just avoid that here by checking and
103 # setting both.
104 if(CRYPTO_FOUND OR crypto_FOUND)
105 set(CRYPTO_FOUND true)
106 set(crypto_FOUND true)
107
108 message(STATUS "LibCrypto Include Dir: ${crypto_INCLUDE_DIR}")
109 message(STATUS "LibCrypto Shared Lib: ${crypto_SHARED_LIBRARY}")
110 message(STATUS "LibCrypto Static Lib: ${crypto_STATIC_LIBRARY}")
111 if (NOT TARGET AWS::crypto AND
112 (EXISTS "${crypto_LIBRARY}")
113 )
114 set(THREADS_PREFER_PTHREAD_FLAG ON)
115 find_package(Threads REQUIRED)
116 add_library(AWS::crypto UNKNOWN IMPORTED)
117 set_target_properties(AWS::crypto PROPERTIES
118 INTERFACE_INCLUDE_DIRECTORIES "${crypto_INCLUDE_DIR}")
119 set_target_properties(AWS::crypto PROPERTIES
120 IMPORTED_LINK_INTERFACE_LANGUAGES "C"
121 IMPORTED_LOCATION "${crypto_LIBRARY}")
122 add_dependencies(AWS::crypto Threads::Threads)
123 endif()
124 endif()
125
126 endif()