forked from nomoresat/DPITunnel-cli
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
114 lines (94 loc) · 3.32 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
# Set the minimum version of CMake that can be used
cmake_minimum_required(VERSION 3.24)
# Set the project name
file(STRINGS include/dpitunnel.h _raw_version_string REGEX "DPITUNNEL_VERSION \"([0-9]+\\.[0-9]+\\.[0-9]+)\"")
string(REGEX MATCH "([0-9]+\\.?)+" _dpitunnel_version "${_raw_version_string}")
project(DPITunnel DESCRIPTION "A program for bypassing internet censorship without a proxy server" VERSION ${_dpitunnel_version} LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CXX_STANDARD_REQUIRED on)
cmake_policy(SET CMP0065 NEW)
cmake_policy(SET CMP0138 NEW)
set(CMAKE_CXX_FLAGS "-Wall -pedantic -fstack-protector-strong --param=ssp-buffer-size=4 ${CMAKE_CXX_FLAGS}")
# set CXXFLAGS for build targets
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -D_FORTIFY_SOURCE=2 ${CMAKE_CXX_FLAGS_RELEASE}")
option(ENABLE_LTO "Enable Link Time Optimization" off)
if (ENABLE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_error)
if (ipo_supported)
if (CMAKE_BUILD_TYPE)
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL TRUE)
message(STATUS "IPO / LTO enabled")
else ()
message(STATUS "Not enabling IPO / LTO on debug builds")
endif ()
else ()
message(STATUS "IPO / LTO will only be enabled for release builds")
endif ()
else ()
message(STATUS "IPO / LTO not supported: <${ipo_error}>")
endif ()
endif ()
if (STATIC_BINARY)
message(STATUS "Building static portable binary with small size")
endif ()
# Add dependencies
add_subdirectory(RawSocket)
add_subdirectory(dnslib)
# Add an executable
add_executable(dpitunnel
autoconf.cpp
desync.cpp
dns.cpp
dpitunnel.cpp
netiface.cpp
packet.cpp
profiles.cpp
socket.cpp
ssl.cpp
utils.cpp
)
if (STATIC_BINARY)
target_link_libraries(dpitunnel -static)
target_link_options(dpitunnel PRIVATE "LINKER:--gc-sections")
target_link_options(dpitunnel PRIVATE "LINKER:-s")
target_compile_options(dpitunnel PRIVATE -ffunction-sections)
endif ()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if (STATIC_BINARY)
set(OPENSSL_USE_STATIC_LIBS TRUE)
endif ()
find_package(OpenSSL 3.0.0 REQUIRED COMPONENTS SSL Crypto)
# Add httplib (cpp-httplib)
find_package(httplib COMPONENTS OpenSSL ZLIB Brotli)
if (NOT HTTPLIB_FOUND)
add_subdirectory(cpp-httplib)
message(STATUS "Using bundled httplib")
endif ()
# Add libnl (libnl)
find_package(LibNL REQUIRED)
# Set the directories that should be included in the build command for this target
target_include_directories(dpitunnel
PRIVATE
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/RawSocket/include
${PROJECT_SOURCE_DIR}/dnslib/include
${LibNL_INCLUDE_DIR}
)
target_link_libraries(dpitunnel
RawSocket
httplib::httplib
dnslib
nl-3
nl-genl-3
Threads::Threads
OpenSSL::SSL
OpenSSL::Crypto
)
if (STATIC_BINARY)
target_link_libraries(dpitunnel ${CMAKE_DL_LIBS})
endif ()