forked from hiero-ledger/hiero-sdk-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildOpenSSL.cmake
57 lines (49 loc) · 2.4 KB
/
BuildOpenSSL.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
include(ExternalProject)
set(OPENSSL_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/_deps/openssl-src) # default path by CMake
set(OPENSSL_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/openssl)
set(OPENSSL_INCLUDE_DIR ${OPENSSL_INSTALL_DIR}/include)
set(OPENSSL_CONFIGURE_COMMAND ${OPENSSL_SOURCE_DIR}/Configure no-shared)
if (WIN32)
set(OPENSSL_CONFIGURE_COMMAND perl ${OPENSSL_CONFIGURE_COMMAND})
set(OPENSSL_BUILD_COMMAND nmake /S)
set(OPENSSL_INSTALL_COMMAND nmake install_sw /S)
set(OPENSSL_LIBRARY_EXTENSION .lib)
else ()
set(OPENSSL_BUILD_COMMAND make)
set(OPENSSL_INSTALL_COMMAND make install_sw)
set(OPENSSL_LIBRARY_EXTENSION .a)
endif ()
if (LINUX)
set(OPENSSL_BYPRODUCT_DIR ${OPENSSL_INSTALL_DIR}/lib64)
else ()
set(OPENSSL_BYPRODUCT_DIR ${OPENSSL_INSTALL_DIR}/lib)
endif ()
set(OPENSSL_CRYPTO_LIB ${OPENSSL_BYPRODUCT_DIR}/libcrypto${OPENSSL_LIBRARY_EXTENSION})
set(OPENSSL_SSL_LIB ${OPENSSL_BYPRODUCT_DIR}/libssl${OPENSSL_LIBRARY_EXTENSION})
ExternalProject_Add(OpenSSL
SOURCE_DIR ${OPENSSL_SOURCE_DIR}
GIT_REPOSITORY https://github.com/openssl/openssl.git
GIT_TAG master
GIT_SHALLOW TRUE
USES_TERMINAL_DOWNLOAD TRUE
CONFIGURE_COMMAND ${OPENSSL_CONFIGURE_COMMAND} --prefix=${OPENSSL_INSTALL_DIR} --openssldir=${OPENSSL_INSTALL_DIR}
BUILD_COMMAND ${OPENSSL_BUILD_COMMAND}
TEST_COMMAND ""
INSTALL_COMMAND ${OPENSSL_INSTALL_COMMAND}
INSTALL_DIR ${OPENSSL_INSTALL_DIR}
BUILD_BYPRODUCTS ${OPENSSL_CRYPTO_LIB} ${OPENSSL_SSL_LIB}
UPDATE_COMMAND ""
)
# We cannot use find_library because ExternalProject_Add() is performed at build time.
# And to please the property INTERFACE_INCLUDE_DIRECTORIES, we make the include directory in advance.
file(MAKE_DIRECTORY ${OPENSSL_INCLUDE_DIR})
add_library(OpenSSL::Crypto STATIC IMPORTED GLOBAL)
set_property(TARGET OpenSSL::Crypto PROPERTY IMPORTED_LOCATION ${OPENSSL_CRYPTO_LIB})
set_property(TARGET OpenSSL::Crypto PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR})
add_dependencies(OpenSSL::Crypto OpenSSL)
add_library(OpenSSL::SSL STATIC IMPORTED GLOBAL)
set_property(TARGET OpenSSL::SSL PROPERTY IMPORTED_LOCATION ${OPENSSL_SSL_LIB})
set_property(TARGET OpenSSL::SSL PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR})
add_dependencies(OpenSSL::SSL OpenSSL)
install(FILES ${OPENSSL_CRYPTO_LIB} TYPE LIB)
install(FILES ${OPENSSL_SSL_LIB} TYPE LIB)