-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCMakeLists.txt
242 lines (219 loc) · 7.54 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
# CMAKE_ANDROID_STANDALONE_TOOLCHAIN (and likely other cross compilation
# android variables) was only introduced in v3.7
cmake_minimum_required (VERSION 3.7)
else()
cmake_minimum_required (VERSION 3.5)
endif()
################################################################################
# Configurable options
option(WITH_INJECTOR "Compile injector" ON)
# NOTE: Need to disable ASan until Boost.Asio switches to Boost.Coroutine2
# because trowing (and catching) exceptions inside a coroutine confuses
# ASan. More info:
# https://github.com/boostorg/coroutine/issues/30#issuecomment-325574878
option(WITH_ASAN "Build with Address sanitizer" OFF)
option(WITH_EXPERIMENTAL "Build with experimental features" OFF)
################################################################################
# Global build flags
if (WITH_ASAN)
add_compile_options("-fsanitize=address" "-fno-omit-frame-pointer")
endif()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
add_compile_options("-ggdb")
endif()
add_compile_options("-Wall")
################################################################################
project(ouinet)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH})
include(OuinetDependencies)
include(BuildVersion)
# This target needs to be linked by all code that includes ouinet headers.
add_library(ouinet_base INTERFACE)
add_library(ouinet::base ALIAS ouinet_base)
target_compile_options(ouinet_base
INTERFACE -std=c++20
)
target_include_directories(ouinet_base
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src
)
target_link_libraries(ouinet_base
INTERFACE
Boost::asio
Boost::boost
Boost::date_time
Boost::filesystem
Boost::nowide
Boost::program_options
Boost::regex
Boost::system
# generic_stream.h needs openssl headers, but not the library.
OpenSSL::headers
)
if (WITH_ASAN)
# NOTE: https://stackoverflow.com/a/50163972
target_link_libraries(ouinet_base
INTERFACE -fsanitize=address
)
endif()
###########################################################
option(ASIO_UTP_WITH_TESTS "" OFF)
option(ASIO_UTP_WITH_EXAMPLES "" OFF)
option(ASIO_UTP_DEBUG_LOGGING "" OFF)
option(UTP_DEBUG_LOGGING "" OFF)
add_subdirectory(./modules/asio-utp)
add_library(lib::asio_utp ALIAS asio_utp)
###########################################################
set(CPPUPnP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/modules/cpp-upnp)
find_package(CPPUPnP REQUIRED)
###########################################################
if(WITH_EXPERIMENTAL)
target_compile_definitions(ouinet_base
INTERFACE -D__EXPERIMENTAL__
)
add_subdirectory(./src/ouiservice/i2p)
#add_subdirectory(./src/ouiservice/lampshade)
add_subdirectory(./src/ouiservice/obfs4proxy)
set(EXPERIMENTAL_SOURCES
# "./src/ouiservice/lampshade.cpp"
"./src/ouiservice/pt-obfs2.cpp"
"./src/ouiservice/pt-obfs3.cpp"
"./src/ouiservice/pt-obfs4.cpp"
"./src/ouiservice/pluggable-transports/*.cpp"
)
set(EXPERIMENTAL_LIBRARIES
# ouinet::lampshade-asio
ouinet::ouiservice-i2p
)
endif()
################################################################################
file(GLOB client_sources
"./src/client.cpp"
"./src/connect_to_host.cpp"
"./src/client_front_end.cpp"
"./src/endpoint.cpp"
"./src/cache_control.cpp"
"./src/request_routing.cpp"
"./src/ouiservice.cpp"
"./src/response_part.cpp"
"./src/bep5_swarms.cpp"
"./src/ssl/ca_certificate.cpp"
"./src/ssl/dummy_certificate.cpp"
"./src/ouiservice/tcp.cpp"
"./src/ouiservice/utp.cpp"
"./src/ouiservice/tls.cpp"
"./src/ouiservice/bep5/client.cpp"
"./src/ouiservice/multi_utp_server.cpp"
"./src/ouiservice/connect_proxy.cpp"
"./src/logger.cpp"
"./src/cache/*.cpp"
"./src/bittorrent/*.cpp"
"./src/util/atomic_dir.cpp"
"./src/util/atomic_file.cpp"
"./src/util/persistent_lru_cache.cpp"
"./src/util/crypto.cpp"
"./src/util/random.cpp"
"./src/util/file_io.cpp"
"./src/util/temp_dir.cpp"
"./src/util/temp_file.cpp"
"./src/util/hash.cpp"
"./src/util/reachability.cpp"
"./src/util.cpp"
"./src/util/handler_tracker.cpp"
"./src/doh.cpp"
"./src/http_util.cpp"
${EXPERIMENTAL_SOURCES}
${VERSION_CPP}
)
if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
add_executable(client ${client_sources})
else()
add_library(client SHARED ${client_sources})
add_library(ouinet::client ALIAS client)
find_library(android_log log)
target_link_libraries(client PUBLIC ${android_log})
endif()
target_link_libraries(client
PRIVATE
Boost::asio_ssl
Boost::iostreams
lib::asio_utp
cpp_upnp
lib::zdnsparser
lib::gcrypt
lib::json
lib::uri
OpenSSL::Crypto
${EXPERIMENTAL_LIBRARIES}
PUBLIC
ouinet::base
)
################################################################################
if (WITH_INJECTOR)
file(GLOB injector_sources
"./src/injector.cpp"
"./src/connect_to_host.cpp"
"./src/ouiservice.cpp"
"./src/response_part.cpp"
"./src/bep5_swarms.cpp"
"./src/ouiservice/tcp.cpp"
"./src/ouiservice/utp.cpp"
"./src/ouiservice/tls.cpp"
"./src/ouiservice/bep5/server.cpp"
"./src/ouiservice/multi_utp_server.cpp"
"./src/ssl/ca_certificate.cpp"
"./src/logger.cpp"
"./src/endpoint.cpp"
"./src/cache/http_sign.cpp"
"./src/bittorrent/*.cpp"
"./src/util/atomic_file.cpp"
"./src/util/persistent_lru_cache.cpp"
"./src/util/crypto.cpp"
"./src/util/random.cpp"
"./src/util/file_io.cpp"
"./src/util/temp_file.cpp"
"./src/util/hash.cpp"
"./src/util/handler_tracker.cpp"
"./src/util.cpp"
"./src/http_util.cpp"
${EXPERIMENTAL_SOURCES}
)
add_executable(injector ${injector_sources})
target_link_libraries(injector
Boost::asio_ssl
Boost::iostreams
lib::asio_utp
lib::gcrypt
lib::json
lib::uri
OpenSSL::Crypto
ouinet::base
${EXPERIMENTAL_LIBRARIES}
)
endif() # if WITH_INJECTOR
################################################################################
# Config file directory
set(config_files
"repos/client/ouinet-client.conf"
"repos/injector/ouinet-injector.conf"
)
set(config_targets )
if(NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
foreach(config_file ${config_files})
get_filename_component(config_dir ${config_file} DIRECTORY)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${config_file}
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${config_file}
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${config_dir}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${config_file} ${CMAKE_CURRENT_BINARY_DIR}/${config_file}
)
set(config_targets ${config_targets} ${CMAKE_CURRENT_BINARY_DIR}/${config_file})
endforeach()
add_custom_target(configfiles ALL DEPENDS ${config_targets})
endif()
################################################################################
# Tests
if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
add_subdirectory(test)
endif()
################################################################################