-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
117 lines (99 loc) · 3.15 KB
/
CMakeLists.txt
File metadata and controls
117 lines (99 loc) · 3.15 KB
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
cmake_minimum_required(VERSION 3.16)
project(asyncweb C)
set(CMAKE_C_STANDARD 11)
# Option
option(ASYNCWEB_STANDALONE "Build asyncweb standalone" OFF)
set(ASYNCWEB_OS_BACKEND "" CACHE STRING "Choose OS backend: posix, win")
set_property(CACHE ASYNCWEB_OS_BACKEND PROPERTY STRINGS posix win)
set(ASYNCWEB_SSL_BACKEND "" CACHE STRING "Choose SSL backend: openssl")
set_property(CACHE ASYNCWEB_OS_BACKEND PROPERTY STRINGS openssl)
set(ASYNCWEB_WS "" CACHE STRING "Choose websocket: on/off")
set_property(CACHE ASYNCWEB_WS PROPERTY STRINGS on off)
if(ASYNCWEB_STANDALONE)
# Libraries
include(FetchContent)
FetchContent_Declare(
libcoro
GIT_REPOSITORY https://github.com/StealthIM/libcoro.git
GIT_TAG master
)
if(NOT DEFINED LIBCORO_OS_BACKEND)
if(WIN32)
set(LIBCORO_OS_BACKEND "win")
elseif(UNIX)
message(WARNING "Use default epoll backend. You can switch to select backend if needed.")
set(LIBCORO_OS_BACKEND "epoll")
else()
message(FATAL_ERROR "No valid OS backend. Please choose one of them.")
endif()
endif()
FetchContent_MakeAvailable(libcoro)
endif()
add_library(asyncweb)
list(APPEND SRC_FILES
src/common.c
src/tools.c
src/http.c
src/ws.c
src/sock/future_socket.c
src/sock/stream.c
)
if(ASYNCWEB_OS_BACKEND STREQUAL "posix")
list(APPEND SRC_FILES
src/sock/pal_socket/posix.c
)
elseif(ASYNCWEB_OS_BACKEND STREQUAL "win")
list(APPEND SRC_FILES
src/sock/pal_socket/win.c
)
target_link_libraries(asyncweb PRIVATE ws2_32 crypt32)
else()
message(FATAL_ERROR "No valid OS backend selected.")
endif()
if(ASYNCWEB_WS STREQUAL "off")
list(APPEND SRC_FILES
src/sync/websocket/none.c
)
endif()
if(ASYNCWEB_SSL_BACKEND STREQUAL "openssl")
list(APPEND SRC_FILES
src/tls/openssl.c
)
find_package(OpenSSL CONFIG REQUIRED)
target_link_libraries(asyncweb
PUBLIC
OpenSSL::SSL
OpenSSL::Crypto
)
else()
message(FATAL_ERROR "No valid SSL backend selected.")
endif()
target_sources(asyncweb PRIVATE ${SRC_FILES})
target_include_directories(asyncweb
PUBLIC
include/public
PRIVATE
include/private
)
target_link_libraries(asyncweb PUBLIC libcoro)
if(ASYNCWEB_STANDALONE)
function(add_test_with_dir test_name executable arg)
add_test(NAME ${test_name} COMMAND ${executable} ${arg})
set_tests_properties(${test_name} PROPERTIES
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endfunction()
enable_testing()
add_executable(test_asyncweb
tests/main.c
tests/test_sync_http.c
tests/test_async_http.c
tests/test_sync_ws.c
tests/test_async_ws.c
)
target_link_libraries(test_asyncweb PRIVATE asyncweb)
add_test_with_dir(test_sync_http test_asyncweb sync_http)
add_test_with_dir(test_async_http test_asyncweb async_http)
add_test_with_dir(test_sync_ws test_asyncweb sync_ws)
add_test_with_dir(test_async_ws test_asyncweb async_ws)
endif()