-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
CMakeLists.txt
202 lines (159 loc) · 6.17 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
if(UNIX)
# Creates wrapper scripts and installs them in the user's binaries directory, which is usually "/usr/local/bin".
# This is required because symlinks use the folder they are in as working directory.
#
# The actual wrapper script needs to be generated at install time, not build time, because it depends on the
# installation prefix. This is especially important when generating packages (rpm/deb) where the prefix is
# changed from /usr to /usr/local for the install step.
#
# The placeholder is needed to satisfy the "install" dependency scanner which runs early.
#
macro(install_wrapper_script component)
file(GENERATE OUTPUT ${BUILD_DIRECTORY}/${component}.sh
CONTENT "# placeholder\n"
)
install(CODE "file(WRITE ${BUILD_DIRECTORY}/${component}.sh \"#!/bin/sh\nexec \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBEXECDIR}/softether/${component}/${component} \\\"$@\\\"\n\")"
COMPONENT ${component}
)
install(PROGRAMS ${BUILD_DIRECTORY}/${component}.sh
COMPONENT ${component}
DESTINATION bin
RENAME ${component}
)
endmacro(install_wrapper_script)
# Same approach for systemd unit files
#
macro(install_unit_file component)
file(GENERATE OUTPUT ${BUILD_DIRECTORY}/softether-${component}.service
CONTENT "# placeholder\n"
)
install(CODE "set(DIR \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBEXECDIR}\")\nconfigure_file(${TOP_DIRECTORY}/systemd/softether-${component}.service ${BUILD_DIRECTORY}/softether-${component}.service)"
COMPONENT ${component}
)
install(FILES ${BUILD_DIRECTORY}/softether-${component}.service
COMPONENT ${component}
DESTINATION ${CMAKE_INSTALL_SYSTEMD_UNITDIR}
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
endmacro(install_unit_file)
endif()
if(BUILD_TYPE STREQUAL "Debug")
add_definitions(-D_DEBUG -DDEBUG)
else()
add_definitions(-DNDEBUG -DVPN_SPEED)
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
add_definitions(-DCPU_64)
endif()
add_definitions(-D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -D_FILE_OFFSET_BITS=64)
# Add /src to the include paths
include_directories(.)
if(WIN32)
add_definitions(-DWIN32 -D_WINDOWS -DOS_WIN32 -D_CRT_SECURE_NO_WARNINGS)
#
# https://msrc-blog.microsoft.com/2020/08/17/control-flow-guard-for-clang-llvm-and-rust/
#
message("Setting CONTROL FLOW GUARD")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:cf")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf /DYNAMICBASE")
message("Setting QSPECTRE")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Qspectre")
message("Setting CETCOMPAT")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /CETCOMPAT")
endif()
if(UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsigned-char")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
add_definitions(-DUNIX -DOS_UNIX)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
add_definitions(-DUNIX_LINUX)
if("$ENV{USE_MUSL}" STREQUAL "YES")
add_definitions(-DUNIX_LINUX_MUSL)
endif()
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
add_definitions(-DUNIX_BSD -DBRIDGE_BPF)
include_directories(SYSTEM /usr/local/include)
link_directories(SYSTEM /usr/local/lib)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")
add_definitions(-DUNIX_BSD -DUNIX_OPENBSD)
include_directories(SYSTEM /usr/local/include)
link_directories(SYSTEM /usr/local/lib)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS")
add_definitions(-DUNIX_SOLARIS -DNO_VLAN)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
add_definitions(-DUNIX_BSD -DUNIX_MACOS -DBRIDGE_PCAP)
endif()
# custom db, log, pid directory for Unix
set(SE_DBDIR "" CACHE STRING "Directory where config files are saved")
set(SE_LOGDIR "" CACHE STRING "Directory where log files are written")
set(SE_PIDDIR "" CACHE STRING "Directory where PID files are put")
if(SE_DBDIR)
add_definitions(-DSE_DBDIR="${SE_DBDIR}")
endif()
if(SE_LOGDIR)
add_definitions(-DSE_LOGDIR="${SE_LOGDIR}")
endif()
if(SE_PIDDIR)
add_definitions(-DSE_PIDDIR="${SE_PIDDIR}")
endif()
endif()
# Cedar communication module
add_subdirectory(Cedar)
# Mayaqua kernel
add_subdirectory(Mayaqua)
# vpnserver
add_subdirectory(vpnserver)
# vpnclient
add_subdirectory(vpnclient)
# vpnbridge
add_subdirectory(vpnbridge)
# vpncmd
add_subdirectory(vpncmd)
# vpntest
add_subdirectory(vpntest)
# libhamcore
add_subdirectory(libhamcore)
# hamcorebuilder utility
add_subdirectory(hamcorebuilder)
# hamcore.se2 archive file
add_custom_target(hamcore-archive-build
ALL
DEPENDS "${BUILD_DIRECTORY}/hamcore.se2"
)
add_custom_command(
COMMENT "Building hamcore.se2 archive file..."
COMMAND hamcorebuilder "hamcore.se2" "${TOP_DIRECTORY}/src/bin/hamcore"
DEPENDS hamcorebuilder "${TOP_DIRECTORY}/src/bin/hamcore/"
OUTPUT "${BUILD_DIRECTORY}/hamcore.se2"
WORKING_DIRECTORY "${BUILD_DIRECTORY}"
VERBATIM
)
if(WIN32)
# PenCore
add_subdirectory(PenCore)
add_dependencies(hamcore-archive-build PenCore)
# vpndrvinst
add_subdirectory(vpndrvinst)
add_dependencies(hamcore-archive-build vpndrvinst)
# vpnsmgr
add_subdirectory(vpnsmgr)
# vpncmgr
add_subdirectory(vpncmgr)
# vpnsetup
add_subdirectory(vpnsetup)
endif()
if(UNIX)
# Print message after installing the targets
install(CODE "message(\"\n----------------------------------------------------------------------------------------------------------------------------\")")
install(CODE "message(\"Build completed successfully.\n\")")
install(CODE "message(\"Execute 'vpnserver start' to run the SoftEther VPN Server background service.\")")
install(CODE "message(\"Execute 'vpnbridge start' to run the SoftEther VPN Bridge background service.\")")
install(CODE "message(\"Execute 'vpnclient start' to run the SoftEther VPN Client background service.\")")
install(CODE "message(\"Execute 'vpncmd' to run the SoftEther VPN Command-Line Utility to configure VPN Server, VPN Bridge or VPN Client.\")")
install(CODE "message(\"----------------------------------------------------------------------------------------------------------------------------\n\")")
endif()