forked from trojan-gfw/trojan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
115 lines (100 loc) · 4.36 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
cmake_minimum_required(VERSION 3.7.2)
project(trojan CXX)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_STANDARD 11)
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
else()
add_definitions(-Wall -Wextra)
endif()
file(GLOB_RECURSE CPP_LIST src/*.cpp)
add_executable(trojan ${CPP_LIST})
target_include_directories(trojan PRIVATE src)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(trojan ${CMAKE_THREAD_LIBS_INIT})
find_package(Boost 1.66.0 REQUIRED COMPONENTS system program_options)
target_include_directories(trojan PRIVATE ${Boost_INCLUDE_DIR})
target_link_libraries(trojan ${Boost_LIBRARIES})
if(MSVC)
add_definitions(-DBOOST_DATE_TIME_NO_LIB)
endif()
find_package(OpenSSL 1.1.0 REQUIRED)
target_include_directories(trojan PRIVATE ${OPENSSL_INCLUDE_DIR})
target_link_libraries(trojan ${OPENSSL_LIBRARIES})
if(OPENSSL_VERSION VERSION_GREATER_EQUAL 1.1.1)
option(ENABLE_SSL_KEYLOG "Build with SSL KeyLog support" ON)
if(ENABLE_SSL_KEYLOG)
add_definitions(-DENABLE_SSL_KEYLOG)
endif()
option(ENABLE_TLS13_CIPHERSUITES "Build with TLS1.3 ciphersuites support" ON)
if(ENABLE_TLS13_CIPHERSUITES)
add_definitions(-DENABLE_TLS13_CIPHERSUITES)
endif()
endif()
option(ENABLE_MYSQL "Build with MySQL support" ON)
if(ENABLE_MYSQL)
find_package(MySQL REQUIRED)
target_include_directories(trojan PRIVATE ${MYSQL_INCLUDE_DIR})
target_link_libraries(trojan ${MYSQL_LIBRARIES})
add_definitions(-DENABLE_MYSQL)
endif()
option(FORCE_TCP_FASTOPEN "Force build with TCP Fast Open support" OFF)
if(FORCE_TCP_FASTOPEN)
add_definitions(-DTCP_FASTOPEN=23 -DTCP_FASTOPEN_CONNECT=30)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
option(ENABLE_NAT "Build with NAT support" ON)
if(ENABLE_NAT)
add_definitions(-DENABLE_NAT)
endif()
option(ENABLE_REUSE_PORT "Build with SO_REUSEPORT support" ON)
if(ENABLE_REUSE_PORT)
add_definitions(-DENABLE_REUSE_PORT)
endif()
endif()
if(APPLE)
find_library(CoreFoundation CoreFoundation)
find_library(Security Security)
target_link_libraries(trojan ${CoreFoundation} ${Security})
endif()
if(WIN32)
target_link_libraries(trojan wsock32 ws2_32 crypt32)
else()
set(SYSTEMD_SERVICE AUTO CACHE STRING "Install systemd service")
set_property(CACHE SYSTEMD_SERVICE PROPERTY STRINGS AUTO ON OFF)
set(SYSTEMD_SERVICE_PATH /lib/systemd/system CACHE PATH "Systemd service path")
if(SYSTEMD_SERVICE STREQUAL AUTO)
if(EXISTS /usr/lib/systemd/system)
set(SYSTEMD_SERVICE ON)
set(SYSTEMD_SERVICE_PATH /usr/lib/systemd/system CACHE PATH "Systemd service path" FORCE)
elseif(EXISTS /lib/systemd/system)
set(SYSTEMD_SERVICE ON)
set(SYSTEMD_SERVICE_PATH /lib/systemd/system CACHE PATH "Systemd service path" FORCE)
endif()
endif()
include(GNUInstallDirs)
install(TARGETS trojan DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES examples/server.json-example DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/trojan RENAME config.json)
set(DEFAULT_CONFIG ${CMAKE_INSTALL_FULL_SYSCONFDIR}/trojan/config.json CACHE STRING "Default config path")
add_definitions(-DDEFAULT_CONFIG="${DEFAULT_CONFIG}")
install(FILES docs/trojan.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
install(DIRECTORY docs/ DESTINATION ${CMAKE_INSTALL_DOCDIR} FILES_MATCHING PATTERN "*.md")
install(DIRECTORY examples DESTINATION ${CMAKE_INSTALL_DOCDIR} FILES_MATCHING PATTERN "*.json-example")
if(SYSTEMD_SERVICE STREQUAL ON)
set(CONFIG_NAME config)
configure_file(examples/trojan.service-example trojan.service)
set(CONFIG_NAME %i)
configure_file(examples/trojan.service-example trojan@.service)
install(FILES ${CMAKE_BINARY_DIR}/trojan.service ${CMAKE_BINARY_DIR}/trojan@.service DESTINATION ${SYSTEMD_SERVICE_PATH})
endif()
enable_testing()
add_test(NAME LinuxSmokeTest-basic
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/LinuxSmokeTest/basic.sh ${CMAKE_BINARY_DIR}/trojan)
add_test(NAME LinuxSmokeTest-fake-client
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/LinuxSmokeTest/fake-client.sh ${CMAKE_BINARY_DIR}/trojan)
SET_TESTS_PROPERTIES(LinuxSmokeTest-fake-client PROPERTIES DEPENDS "LinuxSmokeTest-basic")
endif()