-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
672 lines (540 loc) · 21.9 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
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
cmake_minimum_required(VERSION 3.16)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) # cmake_policy(SET CMP0077 NEW)
if (WIN32)
cmake_policy(SET CMP0091 NEW) # for CMAKE_MSVC_RUNTIME_LIBRARY
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
project(avpn LANGUAGES CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
################################################################################
string(TIMESTAMP VERSION_YEAR "%Y")
string(TIMESTAMP VERSION_MONTH_YEAR "%m")
string(TIMESTAMP VERSION_DAY_YEAR "%j")
string(TIMESTAMP HOUR24 "%H")
string(TIMESTAMP MINUTE "%M")
math(EXPR VERSION_MAJOR "${VERSION_YEAR} - 2018")
math(EXPR VERSION_TINY "${VERSION_DAY_YEAR} % 100")
math(EXPR VERSION_MINOR "${VERSION_MONTH_YEAR} + ${VERSION_DAY_YEAR} / 100")
math(EXPR VERSION_BUILD "${HOUR24}*60+${MINUTE}")
# Touch cmake everytime for update version
add_custom_target(invalidate_files ALL
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_LIST_FILE})
set_target_properties(invalidate_files PROPERTIES FOLDER "third_party")
include(CheckCXXCompilerFlag)
include(CheckLibraryExists)
include(CheckIPOSupported)
################################################################################
# Disable in-source builds to prevent source tree corruption.
if ("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "
FATAL: In-source builds are not allowed.
You should create a separate directory for build files.
")
endif()
message(STATUS "CMAKE Version: ${CMAKE_VERSION}")
message(STATUS "Source Dir: ${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "Host System name: ${CMAKE_HOST_SYSTEM_NAME}")
set(default_build_type "Release")
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
message(STATUS "System name: ${CMAKE_SYSTEM_NAME}")
message(STATUS "System version: ${CMAKE_SYSTEM_VERSION}")
if (WIN32)
message(STATUS "Platform version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
endif()
if (NOT MSVC)
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
endif()
# 跨平台性定义.
message(STATUS "SYSTEM NAME: ${CMAKE_SYSTEM_NAME}")
if (WIN32)
cmake_policy(SET CMP0091 NEW) # for CMAKE_MSVC_RUNTIME_LIBRARY
add_definitions(-DAVPN_USE_WINAPI -DAVPN_WINDOWS)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_definitions(-DAVPN_LINUX)
elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
add_definitions(-DAVPN_FREEBSD)
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_definitions(-DAVPN_APPLE)
elseif (CMAKE_SYSTEM_NAME MATCHES "Android")
add_definitions(-DAVPN_ANDROID)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/cmake")
include(CheckCXXLinkerFlag)
################################################################################
option(ENABLE_INTERPROCEDURAL_OPTIMIZATION "Enable Interprocedural Optimization" OFF)
option(ENABLE_INTEGRATE_SOCKS_SERVER "Enable integrate socks server" OFF)
option(ENABLE_USE_IO_URING "Enable auto use io_uring" OFF)
if (WIN32)
option(ENABLE_USE_WINTUN "Enable use Wintun instead tap-windows" ON)
option(REQUIRE_ADMINISTRATOR "Require administrator" OFF)
else()
option(ENABLE_USE_WINTUN "Enable use Wintun instead tap-windows" OFF)
endif()
option(ENABLE_BUILD_WERROR "All warnings being treated as errors" OFF)
option(ENABLE_SYSTEM_ZLIB "Build with system zlib support" OFF)
option(ENABLE_SYSTEM_OPENSSL "Build with system openssl support" OFF)
option(ENABLE_TCMALLOC_STATIC "Build with Tcmalloc support" OFF)
option(ENABLE_JEMALLOC_STATIC "Build with Jemalloc support" OFF)
option(ENABLE_MIMALLOC_STATIC "Build with Mimalloc support" OFF)
option(ENABLE_SNMALLOC_STATIC "Build with snmalloc support" OFF)
option(ENABLE_GIT_VERSION "Enable git version" ON)
option(ENABLE_SYSTEMD_LOGGING "Build with systemd journal support" OFF)
option(DISABLE_WRITE_LOGGING "Build with log file writer disabled" OFF)
option(ENABLE_BUILD_WITH_LIBCXX "Build with libc++" OFF)
option(ENABLE_NATIVE_ARCH "Enable native architecture" OFF)
option(ENABLE_MOLD "Build using mold" OFF)
option(ENABLE_LLD "Build using lld" OFF)
option(ENABLE_STATIC_LINK_TO_GCC "Build static link to gcc" ON)
option(ENABLE_BUILD_TESTS "Build avpn's unit tests" OFF)
option(ENABLE_LINKE_TO_LIBATOMIC "Link to libatomic.so - some platform requires it" OFF)
################################################################################
if (ENABLE_INTERPROCEDURAL_OPTIMIZATION)
check_ipo_supported(RESULT lto_supported OUTPUT lto_error)
if (lto_supported)
message(STATUS "IPO / LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif()
################################################################################
find_program(MOLD_LINKER mold)
find_program(LLD_LINKER lld)
################################################################################
if (ENABLE_GIT_VERSION)
find_package(Git)
gitGetVersion(${CMAKE_CURRENT_SOURCE_DIR} avpn)
set(VERSION_GIT ${avpn_WC_REVISION_HASH})
string(TIMESTAMP PVERSION "%Y%m%d-${VERSION_GIT}-${CMAKE_SYSTEM_NAME}")
endif()
set(CMAKE_C_STANDARD 11)
################################################################################
if (MSVC)
set(MSVC_DISABLED_WARNINGS_LIST
"C4702" # unreachable code
)
set(MSVC_LEVEL4_WARNINGS_LIST
"C4265" # class has virtual functions, but destructor is not virtual
)
string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
${MSVC_DISABLED_WARNINGS_LIST})
string(REPLACE "C" " -w4" MSVC_LEVEL4_WARNINGS_STR
${MSVC_LEVEL4_WARNINGS_LIST})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
add_definitions(
-D_CRT_SECURE_NO_DEPRECATE
-D_CRT_SECURE_NO_WARNINGS
-D_CRT_NONSTDC_NO_DEPRECATE
-D_CRT_NONSTDC_NO_WARNINGS
-D_SCL_SECURE_NO_DEPRECATE
-D_SCL_SECURE_NO_WARNINGS
)
add_definitions(
-D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
-D_SILENCE_ALL_CXX23_DEPRECATION_WARNINGS
-D_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING
-D_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS
)
add_definitions(
-DWIN32_LEAN_AND_MEAN
-D_WIN32_WINNT=0x0601
-DNOMINMAX
-DUNICODE
-D_UNICODE
)
add_definitions(
-DBOOST_ALL_STATIC_LINK
-DBOOST_THREAD_USE_LIB
-DBOOST_FILESYSTEM_STATIC_LINK
-DBOOST_USE_WINAPI_VERSION=0x0601
)
#add_compile_options(/utf-8)
#add_compile_options(/bigobj)
#add_compile_options(/MP)
#add_compile_options(/Zc:__cplusplus)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /MP /Zc:__cplusplus")
message(STATUS "Set stack size: 100000000 bytes")
add_link_options(/STACK:100000000)
#set(CMAKE_CXX_STACK_SIZE "100000000")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /MP /Zc:__cplusplus")
CHECK_CXX_COMPILER_FLAG(/std:c++20 COMPILER_HAS_STD_CXX20)
if (COMPILER_HAS_STD_CXX20)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "Set default cxx standard: C++20")
elseif (MSVC_VERSION GREATER_EQUAL "1900")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "Set default cxx standard: C++17")
endif()
endif()
################################################################################
CHECK_CXX_COMPILER_FLAG(-fvisibility-inlines-hidden COMPILER_HAS_VISIBILITY_INLINE_HIDDEN)
CHECK_CXX_COMPILER_FLAG(-fvisibility=hidden COMPILER_HAS_VISIBILITY_HIDDEN)
CHECK_CXX_COMPILER_FLAG(-fdiagnostics-color=always COMPILER_HAS_COLOR)
CHECK_CXX_COMPILER_FLAG(-fcoroutines COMPILER_HAS_FCOROUTINES)
CHECK_CXX_COMPILER_FLAG(-fcoroutines-ts COMPILER_HAS_FCOROUTINES_TS)
CHECK_CXX_COMPILER_FLAG(-std=c++20 COMPILER_HAS_STD_CXX20)
################################################################################
if (${COMPILER_HAS_VISIBILITY_INLINE_HIDDEN})
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fvisibility-inlines-hidden>)
endif()
if (${COMPILER_HAS_VISIBILITY_HIDDEN})
add_compile_options(-fvisibility=hidden)
endif()
if (${COMPILER_HAS_COLOR})
add_compile_options(-fdiagnostics-color=always)
endif()
#if (COMPILER_HAS_FCOROUTINES)
# add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fcoroutines>)
#elseif(COMPILER_HAS_FCOROUTINES_TS)
# if (CMAKE_CXX_COMPILER_ID STREQUAL Clang AND CMAKE_CXX_COMPILER_VERSION STRLESS 16)
# add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fcoroutines-ts>)
# endif()
#endif()
if (ENABLE_SYSTEMD_LOGGING)
add_compile_definitions(USE_SYSTEMD_LOGGING)
endif()
if (DISABLE_WRITE_LOGGING)
add_compile_definitions(DISABLE_WRITE_LOGGING)
endif()
################################################################################
if (NOT MSVC)
if (NOT APPLE)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (ENABLE_BUILD_WITH_LIBCXX)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-stdlib=libc++>)
add_link_options(-stdlib=libc++)
CHECK_LINKER_FLAG(CXX "-rtlib=compiler-rt" IS_COMPILER_RT_SUPPORTED)
if (IS_COMPILER_RT_SUPPORTED)
message(STATUS "clang supports compiler-rt, use it")
add_link_options(-rtlib=compiler-rt)
endif()
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
if (ENABLE_STATIC_LINK_TO_GCC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
endif()
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
if (ENABLE_STATIC_LINK_TO_GCC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
endif()
endif()
endif()
if (ANDROID)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie")
endif()
if (COMPILER_HAS_STD_CXX20)
set(CMAKE_CXX_STANDARD 20)
add_definitions(-DUSE_STD_STRING_VIEW)
message(STATUS "Set default cxx standard: C++20")
else()
message(FATAL_ERROR "need at least GCC 11 or clang 14")
endif()
if (ENABLE_MOLD)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (MOLD_LINKER)
list(APPEND CMAKE_EXE_LINKER_FLAGS "-fuse-ld=mold")
endif()
endif()
endif()
if (ENABLE_LLD)
if (LLD_LINKER)
list(APPEND CMAKE_EXE_LINKER_FLAGS "-fuse-ld=lld")
endif()
endif()
endif(NOT MSVC)
################################################################################
# Attempt to determine a suitable native option
if (ENABLE_NATIVE_ARCH)
if (NOT MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif()
endif()
################################################################################
if (ENABLE_SYSTEM_OPENSSL)
find_package(OpenSSL)
else()
set(OpenSSL_FOUND TRUE)
add_subdirectory(third_party/openssl)
if (NOT MSVC AND NOT APPLE)
if (NOT (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--exclude-libs,ALL ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--exclude-libs,ALL ${CMAKE_MODULE_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--exclude-libs,ALL ${CMAKE_EXE_LINKER_FLAGS}")
endif()
endif()
endif()
include_directories(${OPENSSL_INCLUDE_DIR})
################################################################################
if (ENABLE_BUILD_TESTS)
set(USE_BOOST_TEST ON)
endif()
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
#独立编译asio时, 必须要在使用者项目定义, 否则会将
#定义BOOST_ASIO_HEADER_ONLY, 使用者将会导致符号冲突.
add_definitions(-DBOOST_ASIO_SEPARATE_COMPILATION)
add_definitions(-DBOOST_BEAST_SEPARATE_COMPILATION)
#此BOOST_ASIO_DYN_LINK只有在编译asio为动态链接的时候
#才能启用, 它在msvc下将BOOST_ASIO_DECL分别自动作为
#dllimport、dllexport添加.
#add_definitions(-DBOOST_ASIO_DYN_LINK)
add_definitions(-DBOOST_LOCALE_HIDE_AUTO_PTR)
add_definitions(-DBOOST_BIND_GLOBAL_PLACEHOLDERS)
add_definitions(-DBOOST_DISABLE_PRAGMA_MESSAGE)
add_definitions(-DBOOST_COROUTINES_NO_DEPRECATION_WARNING)
add_definitions(-DBOOST_PROCESS_USE_STD_FS)
if (ENABLE_USE_IO_URING)
find_package(IOUring)
if (IOUring_FOUND)
message(STATUS "Linux using io_uring...")
add_definitions(-DBOOST_ASIO_HAS_IO_URING -DBOOST_ASIO_DISABLE_EPOLL)
link_libraries(${IOUring_LIBRARIES})
endif()
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_definitions(-DBOOST_ASIO_HAS_CO_AWAIT)
endif()
set(BOOST_IOSTREAMS_ENABLE_ZSTD OFF)
set(BOOST_IOSTREAMS_ENABLE_LZMA OFF)
set(BOOST_IOSTREAMS_ENABLE_BZIP2 OFF)
set(BOOST_IOSTREAMS_ENABLE_ZLIB OFF)
add_subdirectory(third_party/boost EXCLUDE_FROM_ALL)
set_property(TARGET boost_asio PROPERTY FOLDER "third_party")
set_property(TARGET boost_assign PROPERTY FOLDER "third_party")
set_property(TARGET boost_assert PROPERTY FOLDER "third_party")
set_property(TARGET boost_atomic PROPERTY FOLDER "third_party")
set_property(TARGET boost_bimap PROPERTY FOLDER "third_party")
set_property(TARGET boost_chrono PROPERTY FOLDER "third_party")
set_property(TARGET boost_container PROPERTY FOLDER "third_party")
set_property(TARGET boost_context PROPERTY FOLDER "third_party")
set_property(TARGET boost_core PROPERTY FOLDER "third_party")
set_property(TARGET boost_coroutine PROPERTY FOLDER "third_party")
set_property(TARGET boost_date_time PROPERTY FOLDER "third_party")
set_property(TARGET boost_exception PROPERTY FOLDER "third_party")
set_property(TARGET boost_filesystem PROPERTY FOLDER "third_party")
set_property(TARGET boost_json PROPERTY FOLDER "third_party")
set_property(TARGET boost_lockfree PROPERTY FOLDER "third_party")
set_property(TARGET boost_multi_index PROPERTY FOLDER "third_party")
set_property(TARGET boost_nowide PROPERTY FOLDER "third_party")
set_property(TARGET boost_process PROPERTY FOLDER "third_party")
set_property(TARGET boost_program_options PROPERTY FOLDER "third_party")
set_property(TARGET boost_random PROPERTY FOLDER "third_party")
set_property(TARGET boost_system PROPERTY FOLDER "third_party")
set_property(TARGET boost_thread PROPERTY FOLDER "third_party")
set_property(TARGET boost_url PROPERTY FOLDER "third_party")
set_property(TARGET boost_variant2 PROPERTY FOLDER "third_party")
set_property(TARGET boost_prg_exec_monitor PROPERTY FOLDER "third_party")
set_property(TARGET boost_test_exec_monitor PROPERTY FOLDER "third_party")
set_property(TARGET boost_unit_test_framework PROPERTY FOLDER "third_party")
################################################################################
if (ENABLE_USE_WINTUN)
add_definitions(-DAVPN_USE_WINTUN)
add_subdirectory(third_party/wintun)
set(WINTUN_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/wintun/include)
set(nci ${CMAKE_CURRENT_SOURCE_DIR}/third_party/wintun/src/nci.lib)
endif()
################################################################################
set(CRYPTOPP_DISABLE_ASM OFF CACHE BOOL "" FORCE)
set(CRYPTOPP_BUILD_TESTING OFF CACHE BOOL "" FORCE)
add_subdirectory(third_party/crypto)
set(CRYPTOPP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/crypto/src/cryptopp)
set_property(TARGET cryptopp PROPERTY FOLDER "third_party")
################################################################################
find_package(Threads)
link_libraries(${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
################################################################################
if (ENABLE_TCMALLOC_STATIC)
find_package(Tcmalloc)
link_libraries(${Tcmalloc_LIBRARY})
endif()
################################################################################
if (ENABLE_JEMALLOC_STATIC)
find_package(JeMalloc)
link_libraries(${JEMALLOC_LIBRARIES})
endif()
################################################################################
if (ENABLE_MIMALLOC_STATIC)
add_definitions(-DUSE_MIMALLOC)
set(mimalloc_DIR ${CMAKE_SOURCE_DIR}/third_party/mimalloc/cmake)
set(MI_DEBUG_FULL OFF CACHE BOOL "" FORCE) # Use full internal heap invariant checking in DEBUG mode (expensive)
set(MI_PADDING ON CACHE BOOL "" FORCE) # Enable padding to detect heap block overflow (used only in DEBUG mode)
if (APPLE)
set(MI_OVERRIDE OFF CACHE BOOL "" FORCE) # Override the standard malloc interface (e.g. define entry points for malloc() etc)
else()
set(MI_OVERRIDE ON CACHE BOOL "" FORCE)
endif()
set(MI_XMALLOC OFF CACHE BOOL "" FORCE) # Enable abort() call on memory allocation failure by default
set(MI_SHOW_ERRORS OFF CACHE BOOL "" FORCE) # Show error and warning messages by default (only enabled by default in DEBUG mode)
set(MI_USE_CXX ON CACHE BOOL "" FORCE) # Use the C++ compiler to compile the library (instead of the C compiler)
set(MI_SEE_ASM OFF CACHE BOOL "" FORCE) # Generate assembly files
set(MI_INTERPOSE ON CACHE BOOL "" FORCE) # Use interpose to override standard malloc on macOS
set(MI_OSX_ZONE ON CACHE BOOL "" FORCE) # Use malloc zone to override standard malloc on macOS
set(MI_LOCAL_DYNAMIC_TLS OFF CACHE BOOL "" FORCE) # Use slightly slower, dlopen-compatible TLS mechanism (Unix)
set(MI_BUILD_SHARED OFF CACHE BOOL "" FORCE) # Build shared library
set(MI_BUILD_STATIC ON CACHE BOOL "" FORCE) # Build static library
set(MI_BUILD_OBJECT OFF CACHE BOOL "" FORCE) # Build object library
set(MI_BUILD_TESTS OFF CACHE BOOL "" FORCE) # Build test executables
set(MI_DEBUG_TSAN OFF CACHE BOOL "" FORCE) # Build with thread sanitizer (needs clang)
set(MI_DEBUG_UBSAN OFF CACHE BOOL "" FORCE) # Build with undefined-behavior sanitizer (needs clang++)
set(MI_INSTALL_TOPLEVEL OFF CACHE BOOL "" FORCE) # Install directly into $CMAKE_INSTALL_PREFIX instead of PREFIX/lib/mimalloc-version
include_directories(third_party/mimalloc/include)
add_subdirectory(third_party/mimalloc EXCLUDE_FROM_ALL)
if (MI_OVERRIDE)
add_definitions(-DMI_OVERRIDE) # For preprocessor checks in our source.
endif()
endif()
################################################################################
if (ENABLE_SNMALLOC_STATIC)
set(SNMALLOC_HEADER_ONLY_LIBRARY ON)
add_definitions(-DUSE_SNMALLOC)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/snmalloc EXCLUDE_FROM_ALL)
link_libraries(snmalloc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/snmalloc)
endif()
################################################################################
if (ENABLE_SYSTEMD_LOGGING)
link_libraries(systemd)
endif()
################################################################################
if (WIN32 OR NOT ENABLE_SYSTEM_ZLIB)
add_subdirectory(third_party/zlib EXCLUDE_FROM_ALL)
set(ZLIB_LIBRARIES zlibstatic)
set(ZLIB_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/third_party/zlib
${CMAKE_CURRENT_SOURCE_DIR}/third_party/zlib/contrib/minizip
)
else()
find_package(ZLIB REQUIRED)
endif()
################################################################################
if (UNIX AND NOT APPLE AND NOT ANDROID)
add_subdirectory(third_party/iproute2)
set(IPROUTE2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/iproute2/include)
set(IPROUTE2_LIBRARIES iproute2)
include_directories(${IPROUTE2_INCLUDE_DIRS})
endif()
################################################################################
add_subdirectory(third_party/fmt)
################################################################################
add_subdirectory(utils)
add_subdirectory(proxy)
################################################################################
add_subdirectory(third_party/zstd)
set(ZSTD_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/zstd/lib)
set(ZSTD_LIBRARIES zstd)
################################################################################
include_directories(third_party
${ZLIB_INCLUDE_DIRS}
${ZSTD_INCLUDE_DIRS}
${CRYPTOPP_INCLUDE_DIRS}
${UTILS_INCLUDE_DIRS}
${PROXY_INCLUDE_DIRS}
)
################################################################################
if (ENABLE_USE_WINTUN)
include_directories(${WINTUN_INCLUDE_DIRS})
link_libraries(
${nci}
wintun)
endif()
link_libraries(
Boost::asio
Boost::assign
Boost::beast
Boost::bimap
Boost::date_time
Boost::filesystem
Boost::json
Boost::lockfree
Boost::multi_index
Boost::nowide
Boost::program_options
Boost::signals2
Boost::thread
Boost::url
Boost::uuid
Boost::process
# Boost::thread
# Boost::date_time
# Boost::program_options
# Boost::filesystem
# Boost::signals2
# Boost::nowide
# Boost::json
# Boost::url
# Boost::uuid
# Boost::asio
# Boost::beast
# Boost::multi_index
fmt
cryptopp::cryptopp
${OPENSSL_LIBRARIES}
${ZLIB_LIBRARIES}
${ZSTD_LIBRARIES}
${UTILS_LIBRARIES}
)
if (WIN32)
if (MINGW)
link_libraries(
secur32
ws2_32
mswsock
bcrypt
iphlpapi
)
else()
link_libraries(
Secur32.lib
Bcrypt.lib
Winmm.lib
Mswsock.lib
)
endif()
elseif (UNIX AND NOT APPLE)
# aviod link std::filesystem fail.
set(std_fs_workaround "")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
set(std_fs_workaround stdc++fs)
endif()
link_libraries(
${std_fs_workaround}
${IPROUTE2_LIBRARIES}
)
endif()
if (ENABLE_LINKE_TO_LIBATOMIC)
link_libraries(atomic)
endif()
################################################################################
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if (WIN32)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin/debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin/release)
endif()
################################################################################
add_subdirectory(avpn)
################################################################################
if (ENABLE_BUILD_TESTS)
link_libraries(
Boost::prg_exec_monitor
Boost::test_exec_monitor
Boost::unit_test_framework
)
enable_testing()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/avpn/include)
add_subdirectory(unittests)
endif()
################################################################################
configure_file(avpn.service.in avpn.service)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/avpn.service DESTINATION /usr/lib/systemd/system/)