-
Notifications
You must be signed in to change notification settings - Fork 41
/
CMakeLists.txt
216 lines (161 loc) · 6.22 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
add_library(ww STATIC
ww.c
tunnel.c
shiftbuffer.c
library_loader.c
context_queue.c
buffer_stream.c
config_file.c
buffer_pool.c
generic_pool.c
master_pool.c
http_def.c
cacert.c
sync_dns.c
idle_table.c
frand.c
pipe_line.c
utils/utils.c
managers/signal_manager.c
managers/socket_manager.c
managers/node_manager.c
managers/memory_manager.c
managers/data/iprange_mci.c
managers/data/iprange_irancell.c
managers/data/iprange_mokhaberat.c
managers/data/iprange_rightel.c
managers/data/iprange_iran.c
loggers/core_logger.c
loggers/network_logger.c
loggers/dns_logger.c
)
if(LINUX)
target_sources(ww PRIVATE devices/tun/tun_linux.c)
target_sources(ww PRIVATE devices/raw/raw_linux.c)
target_sources(ww PRIVATE devices/capture/capture_linux.c)
endif()
target_include_directories(ww PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(ww PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..)
# add dependencies
include(${CMAKE_BINARY_DIR}/cmake/CPM.cmake)
option(ASMLIB_OVERRIDE "try to link against asm lib and override standard functions" OFF)
CPMAddPackage(
NAME komihash
GIT_REPOSITORY https://github.com/avaneev/komihash.git
GIT_TAG 5.10
DOWNLOAD_ONLY True
)
if(komihash_ADDED)
target_include_directories(ww PUBLIC ${komihash_SOURCE_DIR})
endif()
CPMAddPackage(
NAME stc
GIT_REPOSITORY https://github.com/radkesvat/STC
GIT_TAG HEAD
DOWNLOAD_ONLY True
)
if(stc_ADDED)
target_include_directories(ww PUBLIC ${stc_SOURCE_DIR}/include)
# target_sources(ww PRIVATE ${stc_SOURCE_DIR}/src/libstc.c)
endif()
# add cJson
CPMAddPackage(
NAME cjson
VERSION 1.7.17
GITHUB_REPOSITORY DaveGamble/cJSON
OPTIONS "BUILD_SHARED_LIBS OFF" "BUILD_SHARED_AND_STATIC_LIBS On"
DOWNLOAD_ONLY True
)
if(cjson_ADDED)
target_include_directories(ww PUBLIC ${cjson_SOURCE_DIR})
target_sources(ww PRIVATE ${cjson_SOURCE_DIR}/cJSON.c)
endif()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/managers/mimalloc)
target_link_libraries(ww PUBLIC mimalloc-static)
# add libhv
set(WITH_OPENSSL OFF CACHE BOOL "libhv without openssl binding")
set(WITH_EVPP OFF CACHE BOOL "libhv no c++ eventpool")
set(WITH_HTTP OFF CACHE BOOL "libhv no http")
set(WITH_HTTP_SERVER OFF CACHE BOOL "ibhv no http server")
set(WITH_HTTP_CLIENT OFF CACHE BOOL "lbhv no http client")
set(BUILD_SHARED OFF CACHE BOOL "ibhv no shared lib")
set(BUILD_EXAMPLES OFF CACHE BOOL "ibhv dont build examples")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/eventloop)
# add lwip
# set(WPDPACK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lwip/WpdPack)
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lwip)
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message( FATAL_ERROR
"MSVC compiler is not supported"
"on windows you can still use GCC or CLANG to compile."
)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
target_link_options(ww PUBLIC -s)
if (WIN32)
target_link_options(ww PUBLIC -static-libgcc -static)
endif()
endif()
# target_compile_options(hv_static PRIVATE -fPIC)
# target_compile_options(ww PUBLIC -fPIC)
# message( FATAL_ERROR "OEUOUEOU: ${CMAKE_INSTALL_PREFIX}" )
# target_compile_options(ww PUBLIC -pg)
# target_link_options(ww PUBLIC -pg)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
if(ENABLE_ASAN)
target_compile_options(ww PUBLIC -fsanitize=address)
target_link_options(ww PUBLIC -fsanitize=address)
endif()
if(ENABLE_TSAN)
target_compile_options(ww PUBLIC -fsanitize=thread)
target_link_options(ww PUBLIC -fsanitize=thread)
endif()
if(ENABLE_LSAN)
target_compile_options(ww PUBLIC -fsanitize=leak)
target_link_options(ww PUBLIC -fsanitize=leak)
endif()
if(ENABLE_USAN)
target_compile_options(ww PUBLIC -fsanitize=undefined)
target_link_options(ww PUBLIC -fsanitize=undefined)
endif()
endif()
# clang-tidy dose not like this even if cc = gcc
# if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# target_compile_options(ww PUBLIC -ftrack-macro-expansion=0)
# endif()
if(LINUX AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
target_include_directories(ww PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/asmlib)
if(CMAKE_BUILD_TYPE STREQUAL "Release" AND ASMLIB_OVERRIDE)
# The override method sometimes fails to call the asmlib function because the compiler uses
# built-in inline codes for some common functions rather than calling a library. The built-in
# codes are not optimal on modern microprocessors. Use option -fno-builtin
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin-function")
set(CMAKE_EXE_LINKER_FLAGS "-L${CMAKE_CURRENT_SOURCE_DIR}/asmlib -laelf64o" CACHE INTERNAL "calculated linker flags, the order is important")
else()
target_link_directories(ww PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/asmlib)
target_link_libraries(ww PUBLIC aelf64)
endif()
endif()
target_compile_options(ww PUBLIC
-Wall
-Wextra
-Werror
-pedantic
-pedantic-errors
-Wparentheses
-Wsequence-point
-Wpointer-arith
-Wlogical-not-parentheses
-Wshadow
-Wmissing-prototypes
-Wnested-externs
-Wuninitialized
-Wwrite-strings
# -Wcast-align todo (fix code to enable this if possible...)
)
# disabled warnings: only unused functions
target_compile_options(ww PUBLIC -Wno-unused-function)
target_compile_definitions(ww PUBLIC STC_STATIC=1 WW_VERSION=0.1)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(ww PUBLIC DEBUG=1)
endif()