-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
CMakeLists.txt
303 lines (247 loc) · 8.1 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
cmake_minimum_required(VERSION 3.5)
project(nekoray VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# WINDOWS PDB FILE
if (WIN32)
if (MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
endif ()
endif ()
# Find Qt
if (NOT QT_VERSION_MAJOR)
set(QT_VERSION_MAJOR 5)
endif ()
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network Svg LinguistTools)
if (NKR_CROSS)
set_property(TARGET Qt5::moc PROPERTY IMPORTED_LOCATION /usr/bin/moc)
set_property(TARGET Qt5::uic PROPERTY IMPORTED_LOCATION /usr/bin/uic)
set_property(TARGET Qt5::rcc PROPERTY IMPORTED_LOCATION /usr/bin/rcc)
set_property(TARGET Qt5::lrelease PROPERTY IMPORTED_LOCATION /usr/bin/lrelease)
set_property(TARGET Qt5::lupdate PROPERTY IMPORTED_LOCATION /usr/bin/lupdate)
endif ()
#### Platform Variables ####
if (WIN32)
include("cmake/windows/windows.cmake")
else ()
include("cmake/linux/linux.cmake")
endif ()
#### default prefix path ####
if (NOT NKR_LIBS)
if (NKR_PACKAGE)
list(APPEND NKR_LIBS ${CMAKE_SOURCE_DIR}/libs/deps/package)
else ()
list(APPEND NKR_LIBS ${CMAKE_SOURCE_DIR}/libs/deps/built)
endif ()
endif ()
if (NOT NKR_DISABLE_LIBS)
list(APPEND CMAKE_PREFIX_PATH ${NKR_LIBS})
endif ()
message("[CMAKE_PREFIX_PATH] ${CMAKE_PREFIX_PATH}")
# for some cross toolchain
list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_PREFIX_PATH})
message("[CMAKE_FIND_ROOT_PATH] ${CMAKE_FIND_ROOT_PATH}")
#### NKR ####
include("cmake/print.cmake")
include("cmake/nkr.cmake")
find_package(Threads)
#### NKR EXTERNAL ####
if (NKR_NO_EXTERNAL)
set(NKR_NO_GRPC 1)
set(NKR_NO_YAML 1)
set(NKR_NO_ZXING 1)
set(NKR_NO_QHOTKEY 1)
endif ()
# grpc
if (NKR_NO_GRPC)
nkr_add_compile_definitions(NKR_NO_GRPC)
else ()
# My proto
include("cmake/myproto.cmake")
list(APPEND NKR_EXTERNAL_TARGETS myproto)
endif ()
# yaml-cpp
if (NKR_NO_YAML)
nkr_add_compile_definitions(NKR_NO_YAML)
else ()
find_package(yaml-cpp CONFIG REQUIRED) # only Release is built
list(APPEND NKR_EXTERNAL_TARGETS yaml-cpp)
endif ()
# zxing-cpp
if (NKR_NO_ZXING)
nkr_add_compile_definitions(NKR_NO_ZXING)
else ()
find_package(ZXing CONFIG REQUIRED)
list(APPEND NKR_EXTERNAL_TARGETS ZXing::ZXing)
endif ()
# QHotkey (static submodule)
if (NKR_NO_QHOTKEY)
nkr_add_compile_definitions(NKR_NO_QHOTKEY)
else ()
set(QHOTKEY_INSTALL OFF)
set(BUILD_SHARED_LIBS OFF)
add_subdirectory(3rdparty/QHotkey)
list(APPEND NKR_EXTERNAL_TARGETS qhotkey)
endif ()
#### debug print ####
if (DBG_CMAKE)
print_all_variables()
print_target_properties(myproto)
print_target_properties(yaml-cpp)
print_target_properties(ZXing::ZXing)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CMAKE_COMMAND} -E time")
endif ()
# Sources
set(PROJECT_SOURCES
${PLATFORM_SOURCES}
main/main.cpp
main/NekoGui.cpp
main/NekoGui_Utils.cpp
main/HTTPRequestHelper.cpp
3rdparty/base64.cpp
3rdparty/qrcodegen.cpp
3rdparty/QtExtKeySequenceEdit.cpp
3rdparty/qv2ray/v2/ui/LogHighlighter.cpp
3rdparty/qv2ray/v2/ui/QvAutoCompleteTextEdit.cpp
3rdparty/qv2ray/v2/components/proxy/QvProxyConfigurator.cpp
3rdparty/qv2ray/v2/ui/widgets/common/QJsonModel.cpp
3rdparty/qv2ray/v2/ui/widgets/editors/w_JsonEditor.cpp
3rdparty/qv2ray/v2/ui/widgets/editors/w_JsonEditor.hpp
3rdparty/qv2ray/v2/ui/widgets/editors/w_JsonEditor.ui
3rdparty/qv2ray/v3/components/GeositeReader/GeositeReader.cpp
3rdparty/qv2ray/v3/components/GeositeReader/picoproto.cpp
rpc/gRPC.cpp
db/Database.cpp
db/traffic/TrafficLooper.cpp
db/ProfileFilter.cpp
db/ConfigBuilder.cpp
fmt/AbstractBean.cpp
fmt/Bean2CoreObj_box.cpp
fmt/Bean2External.cpp
fmt/Bean2Link.cpp
fmt/Link2Bean.cpp
fmt/ChainBean.hpp # translate
sub/GroupUpdater.cpp
sys/ExternalProcess.cpp
sys/AutoRun.cpp
ui/ThemeManager.cpp
ui/Icon.cpp
ui/mainwindow_grpc.cpp
ui/mainwindow.cpp
ui/mainwindow.h
ui/mainwindow.ui
ui/edit/dialog_edit_profile.h
ui/edit/dialog_edit_profile.cpp
ui/edit/dialog_edit_profile.ui
ui/edit/dialog_edit_group.h
ui/edit/dialog_edit_group.cpp
ui/edit/dialog_edit_group.ui
ui/edit/edit_chain.h
ui/edit/edit_chain.cpp
ui/edit/edit_chain.ui
ui/edit/edit_socks_http.h
ui/edit/edit_socks_http.cpp
ui/edit/edit_socks_http.ui
ui/edit/edit_shadowsocks.h
ui/edit/edit_shadowsocks.cpp
ui/edit/edit_shadowsocks.ui
ui/edit/edit_vmess.h
ui/edit/edit_vmess.cpp
ui/edit/edit_vmess.ui
ui/edit/edit_trojan_vless.h
ui/edit/edit_trojan_vless.cpp
ui/edit/edit_trojan_vless.ui
ui/edit/edit_naive.h
ui/edit/edit_naive.cpp
ui/edit/edit_naive.ui
ui/edit/edit_quic.h
ui/edit/edit_quic.cpp
ui/edit/edit_quic.ui
ui/edit/edit_custom.h
ui/edit/edit_custom.cpp
ui/edit/edit_custom.ui
ui/dialog_basic_settings.cpp
ui/dialog_basic_settings.h
ui/dialog_basic_settings.ui
ui/dialog_manage_groups.cpp
ui/dialog_manage_groups.h
ui/dialog_manage_groups.ui
ui/dialog_manage_routes.cpp
ui/dialog_manage_routes.h
ui/dialog_manage_routes.ui
ui/dialog_vpn_settings.cpp
ui/dialog_vpn_settings.h
ui/dialog_vpn_settings.ui
ui/dialog_hotkey.cpp
ui/dialog_hotkey.h
ui/dialog_hotkey.ui
ui/widget/ProxyItem.cpp
ui/widget/ProxyItem.h
ui/widget/ProxyItem.ui
ui/widget/GroupItem.cpp
ui/widget/GroupItem.h
ui/widget/GroupItem.ui
res/neko.qrc
res/theme/feiyangqingyun/qss.qrc
${QV2RAY_RC}
)
# Qt exe
if (${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(nekoray
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET nekoray APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else ()
if (ANDROID)
add_library(nekoray SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else ()
add_executable(nekoray
${PROJECT_SOURCES}
)
endif ()
endif ()
# Target
set_property(TARGET nekoray PROPERTY AUTOUIC ON)
set_property(TARGET nekoray PROPERTY AUTOMOC ON)
set_property(TARGET nekoray PROPERTY AUTORCC ON)
set_target_properties(nekoray PROPERTIES
WIN32_EXECUTABLE TRUE
)
# Target Source Translations
set(TS_FILES
translations/zh_CN.ts
translations/fa_IR.ts
translations/ru_RU.ts
)
set(LUPDATE_OPTIONS
-locations none -no-obsolete
)
if (${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_lupdate(nekoray TS_FILES ${TS_FILES} OPTIONS ${LUPDATE_OPTIONS})
qt_add_lrelease(nekoray TS_FILES ${TS_FILES} QM_FILES_OUTPUT_VARIABLE QM_FILES)
else ()
qt5_create_translation(QM_FILES ${PROJECT_SOURCES} ${TS_FILES} OPTIONS ${LUPDATE_OPTIONS})
endif ()
configure_file(translations/translations.qrc ${CMAKE_BINARY_DIR} COPYONLY)
target_sources(nekoray PRIVATE ${CMAKE_BINARY_DIR}/translations.qrc)
# Target Link
target_link_libraries(nekoray PRIVATE
Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Svg
Threads::Threads
${NKR_EXTERNAL_TARGETS}
${PLATFORM_LIBRARIES}
)
if (QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(nekoray)
endif ()