-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
295 lines (249 loc) · 8.53 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
######## CMAKE CONFIG ########
cmake_minimum_required(VERSION 3.18)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
##############################
######### PRE_BUILD #########
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/buildinfo.cmake")
option(USE_CORE_V5 "V2ray Core Version >= 5.0" OFF)
if(USE_CORE_V5)
add_definitions(-DCORE_V5)
endif()
#############################
project(across VERSION ${GUI_VERSION} LANGUAGES CXX)
######## FIND DEPENDENCES ########
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/get_cpm.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake")
set(FETCHCONTENT_BASE_DIR "${CMAKE_SOURCE_DIR}/3rdpart")
set(CPM_USE_LOCAL_PACKAGES ON)
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/grpc.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/Semver.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/MagicEnum.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/SingleApplication.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/qrc.cmake")
# Qt 6.3
find_package(Qt6 6.6 REQUIRED COMPONENTS Gui Core Quick Widgets DBus QuickControls2
Core5Compat Sql LinguistTools Concurrent ToolsTools )
# curl
CPMAddPackage(
NAME CURL
GITHUB_REPOSITORY "curl/curl"
VERSION 8.8.0
)
# fmt
CPMAddPackage(
NAME fmt
GITHUB_REPOSITORY "fmtlib/fmt"
VERSION 10.2.0
)
# spdlog
CPMAddPackage(
NAME spdlog
GITHUB_REPOSITORY "gabime/spdlog"
VERSION 1.14.1
OPTIONS "SPDLOG_BUILD_BENCH OFF" "SPDLOG_FMT_EXTERNAL ON" "SPDLOG_BUILD_SHARED ON" "SPDLOG_BUILD_TESTS OFF"
)
# A hack to prevent installing ZXing stuffs.
install(CODE [[set(CMAKE_INSTALL_LOCAL_ONLY ON)]])
# ZXing
CPMAddPackage(
NAME ZXing
GITHUB_REPOSITORY "nu-book/zxing-cpp"
VERSION 2.2.1
OPTIONS "BUILD_EXAMPLES OFF" "BUILD_BLACKBOX_TESTS OFF"
)
# JSON
CPMAddPackage(
NAME nlohmann_json
GITHUB_REPOSITORY "nlohmann/json"
VERSION 3.11.2
OPTIONS "JSON_BuildTests OFF"
)
find_package(Threads REQUIRED)
# BEGIN Special case for QtCreator
list(APPEND QML_DIRS "${CMAKE_CURRENT_BINARY_DIR}")
set(QML_IMPORT_PATH "${QML_DIRS}" CACHE STRING "Qt Creator extra qml import paths")
# END Special case
##################################
######## SOURCE FILES ########
include_directories(${CMAKE_CURRENT_BINARY_DIR}/generated/)
set(PROJECT_HEADERS
src/app.h
src/view_models/logview.h
src/view_models/configtools.h
src/view_models/grouplist.h
src/view_models/groupmodel.h
src/view_models/nodelist.h
src/view_models/nodemodel.h
src/view_models/nodeformmodel.h
src/view_models/notificationmodel.h
src/view_models/buildinfo.h.in
src/view_models/systemtray.h
src/view_models/imageprovider.h
src/view_models/jsonhighlighter.h
src/view_models/loghighlighter.h
src/models/apitools.h
src/models/dbtools.h
src/models/envtools.h
src/models/qrcodetools.h
src/models/networktools.h
src/models/serializetools.h
src/models/clipboardtools.h
src/models/notifytools.h
src/models/dbustools.h
src/models/coretools.h
src/models/confighelper.h
${GRPC_HEADERS}
${PROTO_HEADERS}
)
set(PROJECT_SOURCES
src/main.cpp
src/app.cpp
src/view_models/logview.cpp
src/view_models/configtools.cpp
src/view_models/grouplist.cpp
src/view_models/groupmodel.cpp
src/view_models/nodelist.cpp
src/view_models/nodemodel.cpp
src/view_models/nodeformmodel.cpp
src/view_models/notificationmodel.cpp
src/view_models/systemtray.cpp
src/view_models/imageprovider.cpp
src/view_models/jsonhighlighter.cpp
src/view_models/loghighlighter.cpp
src/models/apitools.cpp
src/models/dbtools.cpp
src/models/envtools.cpp
src/models/qrcodetools.cpp
src/models/networktools.cpp
src/models/serializetools.cpp
src/models/clipboardtools.cpp
src/models/notifytools.cpp
src/models/dbustools.cpp
src/models/coretools.cpp
src/models/confighelper.cpp
${GRPC_SOURCES}
${PROTO_SOURCES}
)
##############################
######## COMPILE ########
qt_add_executable(across
MANUAL_FINALIZATION
${PROJECT_HEADERS}
${PROJECT_SOURCES}
misc/across.rc
)
if(NOT ZXing_ADDED)
# Include header files from system package or fetch content with the sample path
target_include_directories(across PRIVATE $<TARGET_PROPERTY:ZXing::Core,INTERFACE_INCLUDE_DIRECTORIES>/ZXing)
endif()
target_compile_definitions(across
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(across PRIVATE
Qt::Core
Qt::Quick
Qt::Widgets
Qt::DBus
Qt::Core5Compat
Qt::Sql
Qt::Concurrent
Qt::QuickControls2
CURL::libcurl
fmt::fmt
gRPC::grpc++
gRPC::grpc++_reflection
magic_enum::magic_enum
nlohmann_json::nlohmann_json
semver::semver
SingleApplication::SingleApplication
spdlog::spdlog
Threads::Threads
ZXing::Core
)
if(WIN32)
target_compile_definitions(across PUBLIC -DWIN32_LEAN_AND_MEAN)
set_target_properties(across PROPERTIES WIN32_EXECUTABLE TRUE)
if (MSVC)
# For CppWinRT pregenerated headers in Windows SDK
target_compile_options(across PRIVATE "/await" "/Zc:twoPhase-")
target_link_libraries(across PRIVATE WindowsApp.lib)
endif()
target_link_libraries(across PRIVATE
wsock32
ws2_32
)
endif()
qt_add_qml_module(across
URI "Arktoria.ACross"
VERSION 1.0
RESOURCE_PREFIX "/"
QML_FILES
${QML_FILES}
)
qt_add_translations(across
TS_FILES ${CMAKE_SOURCE_DIR}/i18n/across_zh_CN.ts
RESOURCE_PREFIX "/i18n/"
)
qt_add_resources(across misc
PREFIX "/misc/"
BASE "${CMAKE_CURRENT_LIST_DIR}/misc"
FILES
${ICON_FILES}
${CMAKE_SOURCE_DIR}/misc/across.proto
${CMAKE_SOURCE_DIR}/misc/v2ray_config.proto
)
qt_import_qml_plugins(across)
qt_finalize_executable(across)
# update translation
add_dependencies(across across_lupdate)
######## UNIT_TEST ########
###########################
#########################
######## INSTALL ########
#########################
option(ENABLE_DEPLOYMENT "Enable fixup_bundle and windeployqt when installing." ON)
if(WIN32 AND ENABLE_DEPLOYMENT)
install(TARGETS across RUNTIME DESTINATION .)
# For Global Target
list(APPEND DIRS "${CMAKE_BINARY_DIR}")
list(APPEND DIRS "${CMAKE_CURRENT_BINARY_DIR}")
list(APPEND DIRS "${Qt6Core_DIR}/../../")
list(APPEND DIRS "${Qt6Core_DIR}/../../../bin/")
if(CMAKE_PREFIX_PATH)
foreach(dir ${CMAKE_PREFIX_PATH})
list(APPEND DIRS "${dir}/bin" "${dir}/lib")
endforeach()
endif()
list(APPEND DIRS "${Qt6Core_DIR}/../..")
foreach(d ${DIRS})
string(REPLACE "\\" "/" newd ${d})
list(APPEND NEW_DIRS ${newd})
endforeach()
set(DIRS ${NEW_DIRS})
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .)
set(APP "${CMAKE_INSTALL_PREFIX}/across.exe")
install(CODE "include(BundleUtilities)")
install(CODE "fixup_bundle(\"${APP}\" \"\" \"${DIRS}\")")
install(CODE "message(\"Now running windeployqt\")")
install(CODE "execute_process(COMMAND \"$<TARGET_FILE:Qt::windeployqt>\" \"${APP}\" --no-virtualkeyboard --no-compiler-runtime --no-opengl-sw -qmldir=${CMAKE_CURRENT_SOURCE_DIR}/src/views/ -qmlimport=.)")
install(CODE "message(\"Completed\")")
else()
install(TARGETS across RUNTIME DESTINATION bin)
install(FILES ${CMAKE_SOURCE_DIR}/misc/org.arktoria.across.desktop DESTINATION share/applications)
install(FILES ${CMAKE_SOURCE_DIR}/misc/design/logo.svg DESTINATION share/icons/hicolor/scalable/apps/ RENAME org.arktoria.across.svg)
install(FILES ${CMAKE_SOURCE_DIR}/misc/icons/light/tray_logo_running.svg DESTINATION share/icons/hicolor/scalable/apps/ RENAME org.arktoria.across.light.running.svg)
install(FILES ${CMAKE_SOURCE_DIR}/misc/icons/light/tray_logo_stop.svg DESTINATION share/icons/hicolor/scalable/apps/ RENAME org.arktoria.across.light.stop.svg)
install(FILES ${CMAKE_SOURCE_DIR}/misc/icons/dark/tray_logo_running.svg DESTINATION share/icons/hicolor/scalable/apps/ RENAME org.arktoria.across.dark.running.svg)
install(FILES ${CMAKE_SOURCE_DIR}/misc/icons/dark/tray_logo_stop.svg DESTINATION share/icons/hicolor/scalable/apps/ RENAME org.arktoria.across.dark.stop.svg)
endif()
######## DEBUG ALL VARIABLES ########
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
#################################