forked from openziti/tlsuv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
141 lines (116 loc) · 3.66 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
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)
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/bio.c
src/http.c
src/tcp_src.c
src/um_debug.c
src/um_debug.h
src/websocket.c
src/http_req.c
src/tls_link.c
src/base64.c
src/tls_engine.c
src/compression.c
src/compression.h
src/p11.c
src/p11.h
)
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()
find_package(libuv CONFIG QUIET)
if (libuv_FOUND)
if (TARGET uv_a)
set(TLSUV_LIBUV_LIB uv_a)
else()
set(TLSUV_LIBUV_LIB uv)
endif()
else()
find_path(TLSUV_LIBUV_INCLUDE NAMES uv.h)
find_library(TLSUV_LIBUV_LIB uv_a NAMES uv)
endif()
find_package(llhttp CONFIG REQUIRED)
add_subdirectory(deps)
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
)
find_package(ZLIB REQUIRED)
target_link_libraries(tlsuv
PUBLIC llhttp::llhttp_static
PRIVATE ${TLSUV_LIBUV_LIB}
PUBLIC uv_link
PRIVATE ZLIB::ZLIB
)
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)
target_link_libraries(tlsuv PUBLIC crypt32)
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()