forked from zhaojh329/ssl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
92 lines (77 loc) · 2.63 KB
/
CMakeLists.txt
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
cmake_minimum_required(VERSION 3.0)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
option(SSL_SUPPORT "SSL support" ON)
option(USE_OPENSSL "Force select OpenSSL" OFF)
option(USE_WOLFSSL "Force select WolfSSL(CyaSSL)" OFF)
option(USE_MBEDTLS "Force select MbedTLS(PolarSSL)" OFF)
if (NOT SSL_SUPPORT)
return()
endif()
find_package(PkgConfig QUIET)
pkg_check_modules(OPENSSL openssl)
if (NOT OPENSSL_FOUND)
find_package(OpenSSL)
endif()
find_package(WolfSSL)
find_package(MbedTLS)
find_package(ZLIB)
if(USE_OPENSSL)
if (NOT OPENSSL_FOUND)
message(FATAL_ERROR "Force select OpenSSL, but not found it")
endif()
elseif(USE_WOLFSSL)
if (NOT WOLFSSL_FOUND)
message(FATAL_ERROR "Force select WolfSSL(CyaSSL), but not found it")
endif()
elseif(USE_MBEDTLS)
if (NOT MBEDTLS_FOUND)
message(FATAL_ERROR "Force select MbedTLS(PolarSSL), but not found it")
endif()
elseif(OPENSSL_FOUND)
set(USE_OPENSSL ON)
elseif(WOLFSSL_FOUND)
set(USE_WOLFSSL ON)
elseif(MBEDTLS_FOUND)
set(USE_MBEDTLS ON)
else()
message(WARNING "No available SSL libraries found")
endif()
if(USE_OPENSSL OR USE_WOLFSSL OR USE_MBEDTLS)
set(SSL_SUPPORT ON)
if(USE_OPENSSL)
set(SSL_NAME "OpenSSL")
set(SSL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/openssl.c)
set(SSL_INC ${OPENSSL_INCLUDE_DIR})
set(SSL_LIBS ${OPENSSL_LIBRARIES})
set(SSL_DEFINE HAVE_OPENSSL)
elseif(USE_WOLFSSL)
set(SSL_NAME "WolfSSL(CyaSSL)")
set(SSL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/openssl.c)
set(SSL_INC ${WOLFSSL_INCLUDE_DIR})
set(SSL_LIBS ${WOLFSSL_LIBRARIES})
set(SSL_DEFINE HAVE_WOLFSSL)
elseif(USE_MBEDTLS)
set(SSL_NAME "MbedTLS(PolarSSL)")
set(SSL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/mbedtls.c)
set(SSL_INC ${MBEDTLS_INCLUDE_DIR})
set(SSL_LIBS ${MBEDTLS_LIBRARIES})
if(ZLIB_FOUND)
list(APPEND SSL_LIBS ${ZLIB_LIBRARIES})
endif()
set(SSL_DEFINE HAVE_MBEDTLS)
endif()
endif()
if(SSL_SUPPORT)
message(STATUS "Select ${SSL_NAME} as the SSL backend")
add_library(xssl STATIC ${SSL_SRC})
target_compile_definitions(xssl PRIVATE ${SSL_DEFINE})
target_compile_options(xssl PRIVATE -O -Wall -Werror --std=gnu99 -fPIC)
target_include_directories(xssl PRIVATE ${SSL_INC})
target_link_libraries(xssl PRIVATE ${SSL_LIBS})
set(SSL_SUPPORT ${SSL_SUPPORT} PARENT_SCOPE)
set(SSL_TARGET xssl PARENT_SCOPE)
set(SSL_SRC ${SSL_SRC} PARENT_SCOPE)
set(SSL_INC ${SSL_INC} PARENT_SCOPE)
set(SSL_LIBS ${SSL_LIBS} PARENT_SCOPE)
set(SSL_DEFINE ${SSL_DEFINE} PARENT_SCOPE)
endif()