forked from picotorrent/picotorrent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
348 lines (289 loc) · 8.66 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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project("PicoTorrent")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(Boost_USE_STATIC_LIBS ON)
set(OPENSSL_USE_STATIC_LIBS TRUE)
if(DEFINED ENV{OPENSSL_ROOT_DIR})
message("Using OpenSSL dir from env variable")
set(OPENSSL_ROOT_DIR $ENV{OPENSSL_ROOT_DIR})
endif()
find_package(Boost REQUIRED COMPONENTS system)
find_package(OpenSSL REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Svg Widgets)
find_package(Qt5WinExtras REQUIRED)
message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
# --------- libtorrent options
option(BUILD_SHARED_LIBS "" off)
option(deprecated-functions "" off)
# ----------------------------
add_subdirectory(vendor/libtorrent)
add_subdirectory(vendor/zlib)
# Generate version information file
file (STRINGS "${CMAKE_SOURCE_DIR}/VERSION" VERSION)
# Build version parts
set(VERSION_TMP "${VERSION}")
string(REPLACE "." ";" VERSION_LIST ${VERSION_TMP})
list(GET VERSION_LIST 0 VERSION_MAJOR)
list(GET VERSION_LIST 1 VERSION_MINOR)
list(GET VERSION_LIST 2 VERSION_REVISION)
# Get the current working branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMITISH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get current architecture
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(PICO_ARCH "x64")
else()
set(PICO_ARCH "x86")
endif()
# Generate buildinfo file
configure_file("${CMAKE_SOURCE_DIR}/src/picotorrent/buildinfo.cpp.in" "${CMAKE_SOURCE_DIR}/src/picotorrent/buildinfo.cpp" @ONLY)
# Debug flags
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Zi")
# Release flags
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /INCREMENTAL:NO /MAP /OPT:REF /OPT:ICF")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/DEBUG /INCREMENTAL:NO /MAP /OPT:REF /OPT:ICF")
add_library(
loguru
STATIC
vendor/loguru/loguru
)
target_compile_definitions(
loguru
PRIVATE
-D_CRT_SECURE_NO_WARNINGS
)
add_library(
sqlite
STATIC
src/sqlite/sqlite3
)
# MaxMind DB library
add_library(
maxminddb
STATIC
vendor/libmaxminddb/src/data-pool
vendor/libmaxminddb/src/maxminddb
)
target_compile_definitions(
maxminddb
PRIVATE
-DUNICODE
-DWIN32
-DWIN32_LEAN_AND_MEAN
)
target_include_directories(
maxminddb
PRIVATE
vendor/libmaxminddb/include
vendor/libmaxminddb/projects/VS12
)
target_link_libraries(
maxminddb
Ws2_32
)
add_executable(
PicoTorrent
WIN32
# Core
src/picotorrent/core/configuration
src/picotorrent/core/database
src/picotorrent/core/environment
src/picotorrent/core/utils
# GeoIP
src/picotorrent/core/geoip/geoip
src/picotorrent/core/geoip/gzipdecompressor
src/picotorrent/core/geoip/maxminddatabase
# HTTP
src/picotorrent/core/http/httpclient
src/picotorrent/core/http/httprequest
src/picotorrent/core/http/httpresponse
# Scripting
src/picotorrent/scripting/jsengine
# Various dialogs
src/picotorrent/aboutdialog
src/picotorrent/addtorrentdialog
# Preferences
src/picotorrent/connectionpreferencespage
src/picotorrent/downloadspreferencespage
src/picotorrent/generalpreferencespage
src/picotorrent/preferencesdialog
src/picotorrent/proxypreferencespage
src/picotorrent/application
src/picotorrent/buildinfo
src/picotorrent/crashpad
src/picotorrent/elidedlabel
src/picotorrent/filestorageitemdelegate
src/picotorrent/filestorageitemmodel
src/picotorrent/main
src/picotorrent/mainwindow
src/picotorrent/resources.qrc
src/picotorrent/resources.rc
src/picotorrent/scriptedtorrentfilter
src/picotorrent/session
src/picotorrent/sessionstate
src/picotorrent/statusbar
src/picotorrent/systemtrayicon
src/picotorrent/textinputdialog
src/picotorrent/torrentcontextmenu
src/picotorrent/torrentitemdelegate
src/picotorrent/torrenthandle
src/picotorrent/torrentlistmodel
src/picotorrent/torrentlistwidget
src/picotorrent/torrentsortfilterproxymodel
src/picotorrent/translator
src/picotorrent/updatechecker
src/picotorrent/models/peerlistmodel
src/picotorrent/models/trackerslistmodel
src/picotorrent/torrentdetails/torrentdetailswidget
src/picotorrent/torrentdetails/torrentfileswidget
src/picotorrent/torrentdetails/torrentoverviewwidget
src/picotorrent/torrentdetails/torrentpeerswidget
src/picotorrent/torrentdetails/torrenttrackerswidget
)
target_compile_definitions(
PicoTorrent
PRIVATE
-D_UNICODE
-D_WIN32
-D_WIN32_WINNT=0x0600
-DBOOST_ALL_NO_LIB
-DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE
-DNOMINMAX
-DPICOJSON_USE_INT64
-DTORRENT_NO_DEPRECATE
-DTORRENT_USE_OPENSSL
-DUNICODE
-DWIN32
-DWIN32_LEAN_AND_MEAN
-DPICO_GIT_COMMITISH=${GIT_COMMITISH}
-DPICO_VERSION_MAJOR=${VERSION_MAJOR}
-DPICO_VERSION_MINOR=${VERSION_MINOR}
-DPICO_VERSION_REVISION=${VERSION_REVISION}
-DZLIB_CONST
)
target_include_directories(
PicoTorrent
PRIVATE
# libmaxminddb
vendor/libmaxminddb/include
vendor/libmaxminddb/projects/VS12
# zlib
vendor/zlib
"$<TARGET_FILE_DIR:zlibstatic>/../"
"${Boost_INCLUDE_DIRS}"
"${CMAKE_SOURCE_DIR}/tools/Microsoft.ChakraCore.vc140/build/native/include"
"${CMAKE_SOURCE_DIR}/tools/UnidentifiedDeveloper.Crashpad.vc142/build/native/crashpad/include"
"${CMAKE_SOURCE_DIR}/tools/UnidentifiedDeveloper.Crashpad.vc142/build/native/mini_chromium/include"
"${CMAKE_SOURCE_DIR}/vendor/libtorrent/include"
"${CMAKE_SOURCE_DIR}/vendor/loguru"
"${Qt5WinExtras_INCLUDE_DIRS}"
)
target_link_directories(
PicoTorrent
PRIVATE
"${CMAKE_SOURCE_DIR}/tools/Microsoft.ChakraCore.vc140/lib/native/v140/${PICO_ARCH}"
"${CMAKE_SOURCE_DIR}/tools/UnidentifiedDeveloper.Crashpad.vc142/lib/native/v142/${PICO_ARCH}"
)
target_link_libraries(
PicoTorrent
# Windows
Comctl32
crypt32
iphlpapi
legacy_stdio_definitions
shlwapi
wininet
winhttp
# Boost
${Boost_LIBRARIES}
# Crashpad
crashpad_client
crashpad_util
mini_chromium
# ChakraCore
ChakraCore
# loguru
loguru
# Rasterbar-libtorrent
"torrent-rasterbar"
# OpenSSL
OpenSSL::Crypto
OpenSSL::SSL
maxminddb
sqlite
zlibstatic
# Qt
Qt5::Svg
Qt5::Widgets
Qt5::WinExtras
)
# Copy scripts
add_custom_command(
TARGET PicoTorrent POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_SOURCE_DIR}/src/scripts"
"$<TARGET_FILE_DIR:PicoTorrent>/scripts"
)
# Copy base Qt dependencies
add_custom_command(
TARGET PicoTorrent POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:Qt5::Core>
$<TARGET_FILE:Qt5::Gui>
$<TARGET_FILE:Qt5::Svg>
$<TARGET_FILE:Qt5::Widgets>
$<TARGET_FILE:Qt5::WinExtras>
$<TARGET_FILE_DIR:PicoTorrent>
)
# Copy image format plugins
add_custom_command(
TARGET PicoTorrent POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:Qt5::QICOPlugin>
"$<TARGET_FILE_DIR:PicoTorrent>/imageformats/$<TARGET_FILE_NAME:Qt5::QICOPlugin>"
)
# Copy platform plugins
add_custom_command(
TARGET PicoTorrent POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:Qt5::QWindowsIntegrationPlugin>
"$<TARGET_FILE_DIR:PicoTorrent>/platforms/$<TARGET_FILE_NAME:Qt5::QWindowsIntegrationPlugin>"
)
# Copy style plugins
add_custom_command(
TARGET PicoTorrent POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:Qt5::QWindowsVistaStylePlugin>
"$<TARGET_FILE_DIR:PicoTorrent>/styles/$<TARGET_FILE_NAME:Qt5::QWindowsVistaStylePlugin>"
)
# Copy ChakraCore
add_custom_command(
TARGET PicoTorrent POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/tools/Microsoft.ChakraCore.vc140/lib/native/v140/${PICO_ARCH}/$<CONFIG>/ChakraCore.dll"
$<TARGET_FILE_DIR:PicoTorrent>
)
# Copy Crashpad handler
add_custom_command(
TARGET PicoTorrent POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/tools/UnidentifiedDeveloper.Crashpad.vc142/lib/native/v142/${PICO_ARCH}/$<CONFIG>/crashpad_handler.exe"
$<TARGET_FILE_DIR:PicoTorrent>
)