-
Notifications
You must be signed in to change notification settings - Fork 7
/
CMakeLists.txt
195 lines (161 loc) · 5 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
CMAKE_MINIMUM_REQUIRED(VERSION 3.22)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
include(cmake/version.cmake)
get_version(${CMAKE_CURRENT_LIST_DIR}/version.txt ver)
PROJECT("tlsuv"
LANGUAGES C
VERSION ${ver}
)
message("Project: ${PROJECT_NAME}@v${PROJECT_VERSION}")
include(cmake/project-is-top-level.cmake)
include(cmake/variables.cmake)
include(CMakeDependentOption)
include(GNUInstallDirs)
option(TLSUV_HTTP "enable HTTP/websocket support" ON)
set(TLSUV_TLSLIB "openssl" CACHE STRING "TLS implementation library (openssl|mbedtls)")
if(NOT (TLSUV_TLSLIB STREQUAL "openssl" OR TLSUV_TLSLIB STREQUAL "mbedtls"))
message(FATAL_ERROR "`${TLSUV_TLSLIB}' TLS library is not supported")
endif()
cmake_dependent_option(USE_OPENSSL "Use OpenSSL" ON "TLSUV_TLSLIB STREQUAL openssl; NOT USE_MBEDTLS" OFF)
cmake_dependent_option(USE_MBEDTLS "Use mbedTLS" ON "TLSUV_TLSLIB STREQUAL mbedtls" OFF)
set(tlsuv_sources
src/tlsuv.c
src/um_debug.c
src/um_debug.h
src/base64.c
src/tls_engine.c
src/p11.c
src/p11.h
src/socket.c
src/util.h
src/connector.c
src/alloc.c
src/keychain.c
)
if (APPLE)
list(APPEND tlsuv_sources
src/apple/keychain.c
)
elseif (WIN32)
list(APPEND tlsuv_sources
src/win32/win32_keychain.c
)
endif ()
if (TLSUV_HTTP)
list(APPEND tlsuv_sources
src/http.c
src/tcp_src.c
src/websocket.c
src/http_req.c
src/tls_link.c
src/compression.c
src/compression.h
)
endif (TLSUV_HTTP)
if(USE_OPENSSL)
set(tlsImpl openssl)
FILE(GLOB ssl_files src/openssl/*)
LIST(APPEND tlsuv_sources
${ssl_files}
)
endif()
if(USE_MBEDTLS)
set(tlsImpl mbedtls)
FILE(GLOB ssl_files src/mbedtls/*)
LIST(APPEND tlsuv_sources
${ssl_files}
)
endif()
include(FindPkgConfig)
find_package(PkgConfig)
find_package(libuv CONFIG QUIET)
if (libuv_FOUND)
# newer libuv versions (via VCPKG) have proper namespacing
if (TARGET libuv::uv_a)
set(TLSUV_LIBUV_LIB libuv::uv_a)
elseif (TARGET uv_a)
set(TLSUV_LIBUV_LIB uv_a)
elseif (TARGET libuv::uv)
set(TLSUV_LIBUV_LIB libuv::uv)
else()
set(TLSUV_LIBUV_LIB uv)
endif()
else()
pkg_check_modules(libuv REQUIRED IMPORTED_TARGET libuv)
set(TLSUV_LIBUV_LIB PkgConfig::libuv)
endif()
add_library(tlsuv STATIC
${tlsuv_sources}
)
set_target_properties(tlsuv PROPERTIES
POSITION_INDEPENDENT_CODE ON
C_STANDARD 99)
target_include_directories(tlsuv
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src
)
target_link_libraries(tlsuv
PRIVATE ${TLSUV_LIBUV_LIB}
)
if (TLSUV_HTTP)
add_subdirectory(deps)
target_link_libraries(tlsuv PUBLIC uv_link)
find_package(ZLIB REQUIRED)
target_link_libraries(tlsuv PRIVATE ZLIB::ZLIB)
find_package(llhttp CONFIG REQUIRED)
message(NOTICE "llhttp = ${llhttp_CONFIG}")
if (TARGET llhttp::llhttp_static)
target_link_libraries(tlsuv PUBLIC llhttp::llhttp_static)
elseif (TARGET llhttp::llhttp_shared)
target_link_libraries(tlsuv PUBLIC llhttp::llhttp_shared)
else ()
target_link_libraries(tlsuv PUBLIC llhttp::llhttp)
endif ()
endif (TLSUV_HTTP)
if (APPLE)
target_link_libraries(tlsuv PRIVATE
"-framework Security"
"-framework CoreFoundation"
)
endif (APPLE)
TARGET_COMPILE_DEFINITIONS(tlsuv PRIVATE TLSUV_VERSION=v${PROJECT_VERSION})
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
TARGET_COMPILE_DEFINITIONS(tlsuv PRIVATE _POSIX_C_SOURCE=200112 _GNU_SOURCE)
endif()
if (USE_MBEDTLS)
find_package(MbedTLS REQUIRED)
target_compile_definitions(tlsuv PRIVATE USE_MBEDTLS)
target_include_directories(tlsuv PUBLIC $<BUILD_INTERFACE:${MBEDTLS_INCLUDE_DIRS}>)
target_link_libraries(tlsuv PRIVATE ${MBEDTLS_LIBRARIES})
elseif(USE_OPENSSL)
find_package(OpenSSL REQUIRED)
target_compile_definitions(tlsuv PRIVATE USE_OPENSSL)
target_link_libraries(tlsuv PRIVATE OpenSSL::SSL)
endif()
if (WIN32)
target_compile_definitions(tlsuv
PRIVATE WIN32_LEAN_AND_MEAN
PRIVATE WINVER=0x0A00
PRIVATE _WIN32_WINNT=0x0A00
PRIVATE _CRT_SECURE_NO_WARNINGS
)
target_link_libraries(tlsuv PUBLIC crypt32 ncrypt)
endif()
install(DIRECTORY include/tlsuv DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS tlsuv
ARCHIVE DESTINATION lib)
if(PROJECT_IS_TOP_LEVEL)
option(BUILD_EXAMPLES "Build examples tree." "${tlsuv_DEVELOPER_MODE}")
if(BUILD_EXAMPLES)
add_subdirectory(sample)
endif()
endif()
if(tlsuv_DEVELOPER_MODE)
ENABLE_TESTING()
set(MEMORYCHECK_SUPPRESSIONS_FILE "${CMAKE_CURRENT_LIST_DIR}/.valgrind.suppressions")
add_subdirectory(tests)
endif()