-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
483 lines (420 loc) · 15.6 KB
/
CMakeLists.txt
File metadata and controls
483 lines (420 loc) · 15.6 KB
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
cmake_minimum_required(VERSION 3.16)
# Version
project(Fang VERSION 0.3.0 LANGUAGES CXX C)
# Set suffix to:
# "-beta.1" Beta
# "-rc.1" Release candidate
# "" Release
set(VERSION_SUFFIX "-beta.1")
# C++ Standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Coverage option - enabled by default for Debug builds when lcov is available
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# Check if lcov is available
find_program(LCOV_AVAILABLE lcov)
if(LCOV_AVAILABLE)
option(ENABLE_COVERAGE "Enable code coverage" ON)
else()
option(ENABLE_COVERAGE "Enable code coverage" OFF)
endif()
else()
option(ENABLE_COVERAGE "Enable code coverage" OFF)
endif()
# Parallel compilation settings
# Automatically use all available CPU cores for faster builds
if(NOT DEFINED CMAKE_BUILD_PARALLEL_LEVEL)
include(ProcessorCount)
ProcessorCount(CPU_CORES)
if(CPU_CORES GREATER 0)
set(CMAKE_BUILD_PARALLEL_LEVEL ${CPU_CORES})
message(STATUS "Parallel build enabled with ${CPU_CORES} cores")
endif()
endif()
# Qt-specific settings
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
# Find Qt6 modules
find_package(Qt6 REQUIRED COMPONENTS
Concurrent
Core
CorePrivate
Qml
Quick
QuickControls2
QuickEffects
Widgets
Network
Sql
Svg
WebSockets
Test
Gui
HttpServer
)
# Optional modules
find_package(Qt6 COMPONENTS WebEngineQuick)
if(DEFINED ENV{BUILD_NUMBER})
set(BUILD_NUMBER $ENV{BUILD_NUMBER})
set(APP_VERSION "${PROJECT_VERSION}.${BUILD_NUMBER}${VERSION_SUFFIX}")
else()
set(APP_VERSION "${PROJECT_VERSION}${VERSION_SUFFIX}")
endif()
file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/APP_VERSION" "${APP_VERSION}")
# Get git commit hash for build identification
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
# Add TidyLib subdirectory
add_subdirectory(external/tidylib)
# Add QSingleInstanceCheck directory
add_subdirectory(external/QSingleInstanceCheck)
# Add QSimpleStateMachine directory
add_subdirectory(external/QSimpleStateMachine)
# QSimpleStateMachine is header-only with Q_OBJECT. Its INTERFACE_SOURCES propagates the
# header to every consumer target, causing each one's AUTOMOC to generate duplicate MOC.
# Clear it here; the INTERFACE_INCLUDE_DIRECTORIES still lets consumers #include the header.
# FangFeedDiscovery compiles the MOC exactly once via qt_wrap_cpp().
set_property(TARGET QSimpleStateMachine PROPERTY INTERFACE_SOURCES "")
# Add QAutoStart directory
add_subdirectory(external/QAutoStart)
# Add QObjectLeakTracker directory
add_subdirectory(external/QObjectLeakTracker)
# Add QMLRearrangeableTreeView directory
add_subdirectory(external/QMLRearrangeableTreeView)
set(QML_IMPORT_PATH "${CMAKE_BINARY_DIR}/external/QMLRearrangeableTreeView" CACHE STRING "" FORCE)
# External libraries
add_subdirectory(external/QImageCache)
add_subdirectory(external/QWebDownload)
# Feed parsing, network core, and discovery libraries
add_subdirectory(lib/FangFeedParser)
add_subdirectory(lib/FangFeedDiscovery)
# Main application target
qt_add_executable(Fang WIN32
# Sources
src/main.cpp
src/models/FolderFeedItem.cpp
src/models/ListModel.cpp
src/models/NewsFeedInteractor.cpp
src/models/NewsItem.cpp
src/models/FeedItem.cpp
src/models/NewsList.cpp
src/operations/BookmarkOperation.cpp
src/operations/AsyncOperation.cpp
src/operations/SyncOperation.cpp
src/operations/InsertFolderOperation.cpp
src/operations/LoadFolderOperation.cpp
src/operations/LoadNewsOperation.cpp
src/operations/MarkAllReadOrUnreadOperation.cpp
src/operations/UpdateFeedURLOperation.cpp
src/FangApp.cpp
src/operations/OperationManager.cpp
src/operations/UpdateFeedOperation.cpp
src/utilities/Utilities.cpp
src/operations/LoadAllFeedsOperation.cpp
src/db/DB.cpp
src/operations/DBOperation.cpp
src/models/FeedValidator.cpp
src/operations/AddFeedOperation.cpp
src/operations/RemoveFeedOperation.cpp
src/utilities/FaviconGrabber.cpp
src/utilities/FangLogging.cpp
src/operations/SetBookmarkOperation.cpp
src/operations/SetFolderOpenOperation.cpp
src/operations/ReloadNewsOperation.cpp
src/operations/FaviconUpdateOperation.cpp
src/models/AllNewsFeedItem.cpp
src/utilities/ImageGrabber.cpp
src/operations/UpdateTitleOperation.cpp
src/models/FangSettings.cpp
src/utilities/RawFeedRewriter.cpp
src/utilities/HTMLSanitizer.cpp
src/operations/LoadAllNewsOperation.cpp
src/utilities/UnreadCountReader.cpp
src/operations/UpdateOrdinalsOperation.cpp
src/utilities/UpdateChecker.cpp
src/models/OPMLInteractor.cpp
src/utilities/BatchFeedDiscovery.cpp
src/network/FangQQmlNetworkAccessManagerFactory.cpp
src/notifications/Notification.cpp
src/operations/SetPinOperation.cpp
src/models/PinnedFeedItem.cpp
src/models/SearchFeedItem.cpp
src/operations/LoadPinnedNewsOperation.cpp
src/models/LisvelFeedItem.cpp
src/operations/LisvelLoadNewsOperation.cpp
src/operations/SearchNewsOperation.cpp
src/operations/ExpireNewsOperation.cpp
src/operations/SetDBSettingOperation.cpp
src/db/DBSettings.cpp
src/db/DBSettingsInterface.cpp
src/operations/GetAllDBSettingsOperation.cpp
src/server/WebSocketServer.cpp
src/server/WebServer.cpp
# Headers
src/models/DBObject.h
src/models/FolderFeedItem.h
src/models/ListModel.h
src/models/NewsFeedInteractor.h
src/models/NewsItem.h
src/models/FeedItem.h
src/models/NewsList.h
src/operations/BookmarkOperation.h
src/operations/AsyncOperation.h
src/operations/SyncOperation.h
src/operations/InsertFolderOperation.h
src/operations/LoadFolderOperation.h
src/operations/LoadNewsOperation.h
src/operations/MarkAllReadOrUnreadOperation.h
src/operations/UpdateFeedURLOperation.h
src/FangApp.h
src/operations/OperationManager.h
src/operations/UpdateFeedOperation.h
src/utilities/Utilities.h
src/operations/LoadAllFeedsOperation.h
src/db/DB.h
src/operations/DBOperation.h
src/models/FeedValidator.h
src/operations/AddFeedOperation.h
src/operations/RemoveFeedOperation.h
src/utilities/FaviconGrabber.h
src/utilities/FangLogging.h
src/operations/SetBookmarkOperation.h
src/operations/SetFolderOpenOperation.h
src/operations/ReloadNewsOperation.h
src/operations/FaviconUpdateOperation.h
src/models/AllNewsFeedItem.h
src/utilities/ImageGrabber.h
src/operations/UpdateTitleOperation.h
src/models/FangSettings.h
src/utilities/RawFeedRewriter.h
src/utilities/HTMLSanitizer.h
src/operations/LoadAllNewsOperation.h
src/utilities/UnreadCountReader.h
src/operations/UpdateOrdinalsOperation.h
src/models/OPMLInteractor.h
src/utilities/BatchFeedDiscovery.h
src/network/FangQQmlNetworkAccessManagerFactory.h
src/notifications/Notification.h
src/operations/SetPinOperation.h
src/models/PinnedFeedItem.h
src/models/SearchFeedItem.h
src/operations/LoadPinnedNewsOperation.h
src/models/LisvelFeedItem.h
src/operations/LisvelLoadNewsOperation.h
src/operations/SearchNewsOperation.h
src/operations/ExpireNewsOperation.h
src/operations/SetDBSettingOperation.h
src/db/DBSettings.h
src/db/DBSettingsInterface.h
src/operations/GetAllDBSettingsOperation.h
src/db/DBSettingsKey.h
src/server/WebSocketServer.h
src/server/WebServer.h
# Resource files
Resources.qrc
qml/qml.qrc
qml/images/images.qrc
html/html.qrc
)
# Include directories
target_include_directories(Fang PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/external/QAutoStart/src
)
# Compile definitions
target_compile_definitions(Fang PRIVATE
BUILD_NUMBER="${BUILD_NUMBER}"
APP_VERSION="${APP_VERSION}"
GIT_COMMIT_HASH="${GIT_COMMIT_HASH}"
FANG_SOURCE_QML_PATH="${CMAKE_SOURCE_DIR}/qml"
)
# QSimpleStateMachine is header-only with Q_OBJECT; its MOC is compiled once in
# FangFeedDiscovery via qt_wrap_cpp. Suppress AUTOMOC here to prevent duplicates.
set_source_files_properties(
${CMAKE_SOURCE_DIR}/external/QSimpleStateMachine/include/QSimpleStateMachine/QSimpleStateMachine.h
PROPERTIES SKIP_AUTOMOC TRUE
)
# Enable warnings as errors
set_property(TARGET Fang PROPERTY COMPILE_WARNING_AS_ERROR ON)
# Link libraries
target_link_libraries(Fang PRIVATE
FangFeedDiscovery
QImageCache
QSingleInstanceCheck
Qt6::Concurrent
Qt6::Core
Qt6::CorePrivate
Qt6::Qml
Qt6::Quick
Qt6::QuickControls2
Qt6::Widgets
Qt6::Network
Qt6::Sql
Qt6::Svg
Qt6::WebSockets
Qt6::HttpServer
Qt6::QuickEffects
QAutoStart
QObjectLeakTracker
rearrangeabletreeview
rearrangeabletreeviewplugin
)
# Optional WebEngineQuick
if(TARGET Qt6::WebEngineQuick)
target_link_libraries(Fang PRIVATE Qt6::WebEngineQuick)
target_compile_definitions(Fang PRIVATE QT_WEBVIEW_WEBENGINE_BACKEND)
endif()
# Precompiled headers for faster compilation
# These are the most frequently included Qt headers across the project
target_precompile_headers(Fang PRIVATE
<QObject>
<QString>
<QList>
<QMap>
<QUrl>
<QByteArray>
<QVariant>
<QNetworkAccessManager>
<QNetworkRequest>
<QNetworkReply>
<QTimer>
<QDebug>
<QQmlApplicationEngine>
<QQuickItem>
)
# Platform: macOS
if(APPLE)
enable_language(OBJCXX)
target_sources(Fang PRIVATE
icons/mac.icns
src/platform/MacWindowHelper.mm
src/platform/MacWindowHelper.h
)
target_link_libraries(Fang PRIVATE "-framework Cocoa")
target_link_options(Fang PRIVATE -Wl,-dead_strip)
# Configure macOS bundle
set(FULL_VERSION "${APP_VERSION}")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/Info.plist
${CMAKE_CURRENT_BINARY_DIR}/Info.plist
@ONLY
)
set_target_properties(Fang PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_BINARY_DIR}/Info.plist
MACOSX_BUNDLE_ICON_FILE mac.icns
)
set_source_files_properties(icons/mac.icns PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources"
)
endif()
# Platform: Windows
if(WIN32)
target_sources(Fang PRIVATE
win32.rc
src/platform/WinWindowHelper.cpp
src/platform/WinWindowHelper.h
)
target_link_libraries(Fang PRIVATE dwmapi)
endif()
# Platform: Android
if(ANDROID)
set_target_properties(Fang PROPERTIES
QT_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/android
)
add_custom_command(TARGET Fang PRE_BUILD
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/androidDeploy.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Preparing Android HTML assets"
)
endif()
# Coverage support
if(ENABLE_COVERAGE)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
message(STATUS "Code coverage enabled")
# Add coverage flags to main target and libraries
target_compile_options(Fang PRIVATE --coverage -O0 -g)
target_link_options(Fang PRIVATE --coverage)
target_compile_options(FangFeedParser PRIVATE --coverage -O0 -g)
target_link_options(FangFeedParser PRIVATE --coverage)
target_compile_options(QWebDownload PRIVATE --coverage -O0 -g)
target_link_options(QWebDownload PRIVATE --coverage)
target_compile_options(FangFeedDiscovery PRIVATE --coverage -O0 -g)
target_link_options(FangFeedDiscovery PRIVATE --coverage)
# Add custom target for coverage report generation
find_program(LCOV_PATH lcov)
find_program(GENHTML_PATH genhtml)
if(LCOV_PATH AND GENHTML_PATH)
add_custom_target(fang-coverage
# Reset coverage counters
COMMAND ${LCOV_PATH} --directory . --zerocounters
# Run tests
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
# Capture coverage data
COMMAND ${LCOV_PATH} --directory . --capture --output-file coverage.info --ignore-errors inconsistent,format,gcov,unsupported,unused
# Remove system and test files from coverage
COMMAND ${LCOV_PATH} --remove coverage.info '/usr/*' '*/Qt/*' '*/test/*' '*_autogen/*' '*/tidylib/*' --output-file coverage.info.cleaned --ignore-errors inconsistent,format,gcov,unsupported,unused
# Generate HTML report
COMMAND ${GENHTML_PATH} coverage.info.cleaned --output-directory coverage_html --ignore-errors inconsistent,format,unused
# Print summary
COMMAND ${LCOV_PATH} --list coverage.info.cleaned --ignore-errors inconsistent,format,gcov,unsupported,unused
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating coverage report"
)
# Add a lightweight target to generate HTML from existing coverage data
add_custom_target(fang-coverage-html
# Capture coverage data
COMMAND ${LCOV_PATH} --directory . --capture --output-file coverage.info
--ignore-errors inconsistent,format,gcov,unsupported,unused
# Remove system and test files
COMMAND ${LCOV_PATH} --remove coverage.info '/usr/*' '*/Qt/*' '*/test/*' '*_autogen/*' '*/tidylib/*'
--output-file coverage.info.cleaned
--ignore-errors inconsistent,format,gcov,unsupported,unused
# Generate HTML report
COMMAND ${GENHTML_PATH} coverage.info.cleaned --output-directory coverage_html
--ignore-errors inconsistent,format,unused
# Print location and try to open in browser
COMMAND ${CMAKE_COMMAND} -E echo ""
COMMAND ${CMAKE_COMMAND} -E echo "======================================================================"
COMMAND ${CMAKE_COMMAND} -E echo "Coverage report: ${CMAKE_BINARY_DIR}/coverage_html/index.html"
COMMAND ${CMAKE_COMMAND} -E echo "======================================================================"
COMMAND ${CMAKE_COMMAND} -E echo ""
# Try to open in default browser (best effort, may not work from all contexts)
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan "Opening in browser..."
COMMAND open ${CMAKE_BINARY_DIR}/coverage_html/index.html || xdg-open ${CMAKE_BINARY_DIR}/coverage_html/index.html || ${CMAKE_COMMAND} -E echo "Note: Could not open browser automatically. Use the link above."
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating HTML coverage report and opening in browser"
)
message(STATUS "Coverage target 'coverage' available - run: make coverage (runs tests + generates HTML)")
message(STATUS "Coverage target 'coverage-html' available - run: make coverage-html (generates HTML from existing test data)")
else()
message(WARNING "lcov or genhtml not found - coverage target not available")
endif()
else()
message(WARNING "Coverage only supported with GCC or Clang")
endif()
endif()
# Enable testing and add test subdirectory
enable_testing()
add_subdirectory(test)
# Installation
include(GNUInstallDirs)
install(TARGETS Fang
BUNDLE DESTINATION .
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# Qt 6.3+ deployment
if(QT_VERSION VERSION_GREATER_EQUAL "6.3")
qt_generate_deploy_app_script(
TARGET Fang
OUTPUT_SCRIPT deploy_script
NO_UNSUPPORTED_PLATFORM_ERROR
)
install(SCRIPT ${deploy_script})
endif()