-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathCMakeLists.txt
134 lines (117 loc) · 2.69 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
# Minimum CMake version
cmake_minimum_required(VERSION 3.5...3.27)
project(xfrp C)
# Build options
option(THIRDPARTY_STATIC_BUILD "Build with static third party libraries" OFF)
option(ENABLE_SANITIZER "Enable sanitizer(Debug+Gcc/Clang/AppleClang)" ON)
# Configure static/dynamic build
if(THIRDPARTY_STATIC_BUILD)
add_subdirectory(${PROJECT_SOURCE_DIR}/thirdparty/)
include_directories(
${PROJECT_SOURCE_DIR}/thirdparty/include/libevent
${PROJECT_SOURCE_DIR}/thirdparty/include/
)
link_directories(${PROJECT_SOURCE_DIR}/thirdparty/libs/)
set(EXTRA_LIBS dl pthread)
else()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
# Find required packages
find_package(LibEvent REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(JSON-C REQUIRED)
find_package(ZLIB REQUIRED)
include_directories(
${JSON-C_INCLUDE_DIR}
${ZLIB_INCLUDE_DIRS}
)
endif()
# Sanitizer configuration
macro(check_asan _RESULT)
include(CheckCSourceRuns)
set(CMAKE_REQUIRED_FLAGS "-fsanitize=address")
check_c_source_runs("int main() { return 0; }" ${_RESULT})
unset(CMAKE_REQUIRED_FLAGS)
endmacro()
if(ENABLE_SANITIZER AND NOT MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
check_asan(HAS_ASAN)
if(HAS_ASAN)
message(STATUS "Adding address sanitizer")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=leak")
list(APPEND EXTRA_LIBS asan)
else()
message(STATUS "Sanitizer not supported with current toolchain")
endif()
else()
message(STATUS "Sanitizer only available in Debug build")
endif()
endif()
# Source files
set(CORE_SOURCES
main.c
client.c
config.c
control.c
ini.c
msg.c
xfrpc.c
debug.c
zip.c
commandline.c
crypto.c
fastpbkdf2.c
utils.c
common.c
login.c
)
set(PROXY_SOURCES
proxy_tcp.c
proxy_udp.c
proxy_ftp.c
proxy.c
tcpmux.c
tcp_redir.c
mongoose.c
)
set(PLUGIN_SOURCES
plugins/telnetd.c
plugins/instaloader.c
plugins/httpd.c
plugins/youtubedl.c
)
# Combine all sources
set(src_xfrpc
${CORE_SOURCES}
${PROXY_SOURCES}
${PLUGIN_SOURCES}
)
# Required libraries
set(SYSTEM_LIBS
pthread
m
crypt
dl
)
set(EXTERNAL_LIBS
ssl
crypto
event
${JSON-C_LIBRARIES}
${ZLIB_LIBRARIES}
)
# Compiler flags
add_definitions(
-D_GNU_SOURCE
-Wall
-Werror
)
# Build target
add_executable(xfrpc ${src_xfrpc})
# Link libraries
target_link_libraries(xfrpc PRIVATE
${EXTERNAL_LIBS}
${SYSTEM_LIBS}
${EXTRA_LIBS}
)
# Installation
install(TARGETS xfrpc DESTINATION bin)