-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
311 lines (271 loc) · 9.76 KB
/
CMakeLists.txt
File metadata and controls
311 lines (271 loc) · 9.76 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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# Not using `if (ANDROID)` because that's available only since cmake 3.7
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()
# Set cmake policies to avoid warnings in newer versions of cmake
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.19)
cmake_policy(SET CMP0114 NEW)
endif()
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
################################################################################
# Configurable options
# 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")
link_libraries(-fsanitize=address)
endif()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
add_compile_options("-ggdb")
endif()
add_compile_options("-Wall")
if(WIN32)
add_compile_options("-O1")
add_definitions(-DBOOST_USE_WINDOWS_H -DWIN32_LEAN_AND_MEAN)
endif()
if(APPLE AND NOT IOS)
# Boost.Stacktrace doesn't need _GNU_SOURCE on macOS
add_definitions(-DBOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED)
endif()
if ((NOT ANDROID) AND (NOT IOS))
# Adds -fPIC when building static libraries (which I think is the default
# when building dynamic ones). It's needed on x86 when linking the
# `client_lib` target.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
################################################################################
project(ouinet)
if(MINGW) # Note that MING gets defined only after `project(ouinet)`
# Fixes errors
# "Fatal error: can't write 103 bytes to section .text of <CPP_FILE>.obj: 'file too big'"
# https://digitalkarabela.com/mingw-w64-how-to-fix-file-too-big-too-many-sections/
add_compile_options(-Wa,-mbig-obj)
endif()
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_dependencies INTERFACE)
target_compile_options(ouinet_dependencies
INTERFACE -std=c++20
)
target_include_directories(ouinet_dependencies
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src
)
target_link_libraries(ouinet_dependencies
INTERFACE
ouinet_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 (${CMAKE_SYSTEM_NAME} STREQUAL "Windows" AND BOOST_VERSION GREATER_EQUAL 1.72.0)
# explicitly link with bcrypt after Boost::filesystem
target_link_libraries(ouinet_dependencies
INTERFACE
bcrypt
)
endif()
if (WITH_ASAN)
# NOTE: https://stackoverflow.com/a/50163972
target_link_libraries(ouinet_dependencies
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)
target_compile_definitions(cpp_upnp PUBLIC -DBOOST_ASIO_SEPARATE_COMPILATION)
###########################################################
if(WITH_EXPERIMENTAL)
target_compile_definitions(ouinet_dependencies
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()
################################################################################
# These are separate from `ouinet_common` because they're also required by
# `ouinet_rs`
add_library(ouinet_common_public
STATIC
"./src/logger.cpp"
"./src/util/log_path.cpp"
)
target_link_libraries(ouinet_common_public PUBLIC Boost::filesystem)
################################################################################
file(GLOB ouinet_common_sources
"./src/connect_to_host.cpp"
"./src/response_part.cpp"
"./src/util.cpp"
"./src/util/atomic_file.cpp"
"./src/util/random.cpp"
"./src/util/handler_tracker.cpp"
"./src/util/crypto.cpp"
"./src/util/log_path.cpp"
"./src/util/file_io.cpp"
"./src/util/temp_file.cpp"
"./src/util/hash.cpp"
"./src/util/url.cpp"
"./src/ssl/ca_certificate.cpp"
"./src/bittorrent/*.cpp"
"./src/bep5_swarms.cpp"
"./src/ouiservice.cpp"
"./src/ouiservice/tcp.cpp"
"./src/ouiservice/utp.cpp"
"./src/ouiservice/tls.cpp"
"./src/ouiservice/multi_utp_server.cpp"
"./src/util/persistent_lru_cache.cpp"
"./src/endpoint.cpp"
"./src/async_sleep.cpp"
"./src/http_util.cpp"
${EXPERIMENTAL_SOURCES}
)
add_library(ouinet_common STATIC ${ouinet_common_sources})
target_link_libraries(ouinet_common
PRIVATE
ouinet_dependencies
lib::url
OpenSSL::Crypto
${EXPERIMENTAL_LIBRARIES}
PUBLIC
Boost::iostreams
lib::gcrypt
lib::json
lib::asio_utp
ouinet_rs
ouinet_common_public
# Boost::asio_ssl is public for Android because the ClientConfig used
# in native-lib.cpp contains ssl::context and we need its move
# constructor and destructor implementations.
ouinet_asio_ssl
)
target_include_directories(ouinet_common PUBLIC "src")
################################################################################
file(GLOB client_sources
"./src/client.cpp"
"./src/client_config.cpp"
"./src/client_front_end.cpp"
"./src/client_lib.cpp"
"./src/cache_control.cpp"
"./src/request_routing.cpp"
"./src/ssl/dummy_certificate.cpp"
"./src/ouiservice/bep5/client.cpp"
"./src/ouiservice/connect_proxy.cpp"
"./src/cache/*.cpp"
"./src/util/atomic_dir.cpp"
"./src/util/temp_dir.cpp"
${VERSION_CPP}
)
if (IOS)
add_library(client_lib STATIC ${client_sources})
else()
add_library(client_lib SHARED ${client_sources})
endif()
if (NOT WIN32 AND NOT MINGW)
set_target_properties(client_lib PROPERTIES OUTPUT_NAME "client")
endif()
add_library(ouinet::client ALIAS client_lib)
target_link_libraries(client_lib
PUBLIC
ouinet_common
cpp_upnp
)
if (WIN32 OR MINGW)
target_compile_definitions(client_lib PRIVATE -DOUINET_DECL_EXPORT)
endif()
if (ANDROID)
find_library(android_log log)
target_link_libraries(client_lib PUBLIC ${android_log})
elseif (IOS)
set(ouinet_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ios/ouinet)
find_package(ouinet REQUIRED)
else()
add_executable(client "./src/client_main.cpp")
target_link_libraries(client client_lib)
endif()
################################################################################
file(GLOB injector_sources
"./src/injector.cpp"
"./src/ouiservice/bep5/server.cpp"
"./src/endpoint.cpp"
"./src/cache/http_sign.cpp"
"./src/http_logger.cpp"
${EXPERIMENTAL_SOURCES}
)
add_library(injector_lib SHARED ${injector_sources})
if (NOT WIN32 AND NOT MINGW)
set_target_properties(injector_lib PROPERTIES OUTPUT_NAME "injector")
endif ()
target_link_libraries(injector_lib ouinet_common)
if (WIN32 OR MINGW)
target_compile_definitions(injector_lib PRIVATE -DOUINET_DECL_EXPORT)
endif()
if ((NOT ANDROID) AND (NOT IOS))
add_executable(injector "./src/injector_main.cpp")
target_link_libraries(injector injector_lib)
endif()
################################################################################
# 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 ANDROID)
add_subdirectory(test)
endif()
################################################################################