Skip to content

Commit a64e259

Browse files
re2zerodeepin-bot[bot]
authored andcommitted
build(cmake): refactor Qt version compatibility
- Add Qt auto-detection using find_package(QT NAMES Qt6 Qt5) instead of hardcoded QT_VERSION_MAJOR=6 - Separate debian/control files: * control: V25 (Qt6) with explicit qt6-base-dev, libdtk6*-dev deps * control.1: V20 (Qt5) with explicit qtbase5-dev, libdtk*-dev deps - Add Wayland support with dynamic detection for Qt5 This enables seamless building on both V25 (Qt6) and V20 (Qt5) systems without version-specific conditional dependencies. Log: 分离Qt5/Qt6构建配置,支持V25/V20双版本 PMS: https://pms.uniontech.com/task-view-386321.html
1 parent 1a6a04f commit a64e259

File tree

6 files changed

+89
-23
lines changed

6 files changed

+89
-23
lines changed

CMakeLists.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,17 @@ else()
4444
SET(IS_LOONGARCH_TYPE 0)
4545
endif()
4646

47-
if (NOT DEFINED QT_VERSION_MAJOR)
48-
set(QT_VERSION_MAJOR 6)
49-
endif()
50-
if (QT_VERSION_MAJOR EQUAL 6)
47+
# Auto-detect Qt version (tries Qt6 first, falls back to Qt5)
48+
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
49+
message(STATUS "Found Qt version: ${QT_VERSION_MAJOR}")
50+
51+
# Map to DTK version (Qt6→DTK6, Qt5→DTK5)
52+
if (QT_VERSION_MAJOR MATCHES 6)
5153
set(DTK_VERSION_MAJOR 6)
5254
else()
5355
set(DTK_VERSION_MAJOR)
5456
endif()
57+
message(STATUS "Build with DTK: ${DTK_VERSION_MAJOR}")
5558
set(QT_NS Qt${QT_VERSION_MAJOR})
5659
set(DTK_NS Dtk${DTK_VERSION_MAJOR})
5760

@@ -90,7 +93,7 @@ set(system_monitor_plugin_server assets/configs/org.deepin.system-monitor.server
9093
# DTK6 提供 dtk_add_config_meta_files 命令,DTK5 需要手动安装
9194
# 需要显式引入 DConfig 模块以确保 DSG_DATA_DIR 在当前作用域可用
9295
if (DTK_VERSION_MAJOR EQUAL 6)
93-
find_package(Dtk6DConfig QUIET)
96+
find_package(Dtk${DTK_VERSION_MAJOR}DConfig QUIET)
9497
endif()
9598

9699
if (COMMAND dtk_add_config_meta_files)

debian/control

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ Build-Depends:
66
debhelper-compat (= 11),
77
cmake,
88
pkg-config,
9-
qt6-base-dev | qtbase5-dev,
10-
qt6-svg-dev | libqt5svg5-dev,
11-
qt6-tools-dev | qttools5-dev,
12-
qt6-tools-dev-tools | qttools5-dev-tools,
13-
libdtk6core-dev | libdtkcore-dev,
14-
libdtk6gui-dev | libdtkgui-dev,
15-
libdtk6widget-dev | libdtkwidget-dev,
9+
qt6-base-dev,
10+
qt6-svg-dev,
11+
qt6-tools-dev,
12+
qt6-tools-dev-tools,
13+
libdtk6core-dev,
14+
libdtk6gui-dev,
15+
libdtk6widget-dev,
1616
libxcb1-dev,
1717
libxext-dev,
1818
libpcap-dev,
@@ -26,14 +26,14 @@ Build-Depends:
2626
dde-tray-loader-dev | dde-dock-dev,
2727
libgtest-dev,
2828
libgmock-dev,
29-
libpolkit-qt6-1-dev | libpolkit-qt5-1-dev
29+
libpolkit-qt6-1-dev
3030
Standards-Version: 4.6.2
3131
Homepage: https://github.com/linuxdeepin/deepin-system-monitor
3232

3333
Package: deepin-system-monitor
3434
Architecture: any
35-
Depends: ${shlibs:Depends},
36-
${misc:Depends},
35+
Depends: ${shlibs:Depends},
36+
${misc:Depends},
3737
libcap2-bin,
3838
deepin-service-manager
3939
Recommends: uos-reporter, deepin-event-log

debian/control.1

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Source: deepin-system-monitor
2+
Section: utils
3+
Priority: optional
4+
Maintainer: Deepin Packages Builder <packages@deepin.com>
5+
Build-Depends:
6+
debhelper-compat (= 11),
7+
cmake,
8+
pkg-config,
9+
qtbase5-dev,
10+
libqt5svg5-dev,
11+
qttools5-dev,
12+
qttools5-dev-tools,
13+
libdtkcore-dev,
14+
libdtkgui-dev,
15+
libdtkwidget-dev,
16+
libxcb1-dev,
17+
libxext-dev,
18+
libpcap-dev,
19+
libicu-dev,
20+
deepin-gettext-tools,
21+
libxcb-util0-dev,
22+
libxcb-icccm4-dev,
23+
libnl-3-dev,
24+
libnl-route-3-dev,
25+
libudev-dev,
26+
dde-tray-loader-dev | dde-dock-dev,
27+
libgtest-dev,
28+
libgmock-dev,
29+
libpolkit-qt5-1-dev,
30+
libdwayland-dev | libkf5wayland-dev
31+
Standards-Version: 4.6.2
32+
Homepage: https://github.com/linuxdeepin/deepin-system-monitor
33+
34+
Package: deepin-system-monitor
35+
Architecture: any
36+
Depends: ${shlibs:Depends},
37+
${misc:Depends},
38+
libcap2-bin,
39+
deepin-service-manager
40+
Recommends: uos-reporter, deepin-event-log
41+
Replaces: deepin-system-monitor-plugin
42+
Description: A system monitor tool.
43+
System Monitor is a system tool monitoring and managing hardware load, program running and system services. It's capable to real-time monitor CPU status, memory footprint, and upload/download speed, manage system and application processes, search and force end processes as well.

deepin-system-monitor-daemon/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wl,-Map=deepin-system-monitor-daemon.map
5454
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wl,-Map=deepin-system-monitor-daemon.map")
5555

5656
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
57-
EXECUTE_PROCESS(COMMAND mkdir -p ${CMAKE_BINARY_DIR}/share/user/)
58-
EXECUTE_PROCESS(COMMAND cp -f ${CMAKE_CURRENT_SOURCE_DIR}/${BIN_NAME}.json ${CMAKE_BINARY_DIR}/share/system/)
57+
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/share/user/)
58+
EXECUTE_PROCESS(COMMAND cp -f ${CMAKE_CURRENT_SOURCE_DIR}/${BIN_NAME}.json ${CMAKE_BINARY_DIR}/share/user/)
5959
else()
6060
install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/deepin-service-manager/)
6161
install(FILES ${BIN_NAME}.json DESTINATION share/deepin-service-manager/user/)

deepin-system-monitor-main/CMakeLists.txt

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "sw_64")
2525
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mieee")
2626
endif ()
2727
if (CMAKE_BUILD_TYPE STREQUAL "Release")
28-
add_definitions("-DQT_NO_DEBUG_OUTPUT")
29-
endif()
30-
if (USE_DEEPIN_WAYLAND AND QT_VERSION LESS 6)
31-
add_definitions("-DUSE_DEEPIN_WAYLAND")
28+
add_definitions("-DQT_NO_DEBUG_OUTPUT")
3229
endif()
3330

3431
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/environments.h.in ${CMAKE_CURRENT_BINARY_DIR}/environments.h @ONLY)
@@ -40,6 +37,21 @@ check_symbol_exists(syscall "unistd.h" HAVE_SYS_CALL)
4037
check_symbol_exists(SYS_getrandom "sys/syscall.h" HAVE_SYS_GETRANDOM)
4138
include(FindPkgConfig)
4239

40+
if (USE_DEEPIN_WAYLAND AND QT_VERSION LESS 6)
41+
add_definitions("-DUSE_DEEPIN_WAYLAND")
42+
find_package(DWayland QUIET)
43+
find_package(KF5Wayland QUIET)
44+
if (DWayland_FOUND)
45+
message(STATUS "Build with Qt5 and DWayland found.")
46+
add_definitions(-DDWAYLAND)
47+
elseif(KF5Wayland_FOUND)
48+
message(STATUS "Build with Qt5 and KF5Wayland found.")
49+
add_definitions(-DKF5WAYLAND)
50+
elseif(NOT DWayland_FOUND AND NOT KF5Wayland_FOUND)
51+
message(WARNING "Neither DWayland nor KF5Wayland found, Wayland support will be disabled")
52+
endif()
53+
endif()
54+
4355
find_package(${QT_NS} COMPONENTS Core Widgets Gui DBus Concurrent LinguistTools REQUIRED)
4456
find_package(${DTK_NS} COMPONENTS Core Gui Widget REQUIRED)
4557

@@ -584,6 +596,14 @@ set(LIBS
584596
# ${DFrameworkDBus_LIBRARIES} # chinalife
585597
)
586598

599+
if (USE_DEEPIN_WAYLAND)
600+
if (DWayland_FOUND)
601+
list(APPEND LIBS DWaylandClient DWaylandServer)
602+
elseif(KF5Wayland_FOUND)
603+
list(APPEND LIBS KF5::WaylandClient KF5::WaylandServer)
604+
endif()
605+
endif()
606+
587607
file(GLOB APP_TS_FILES LIST_DIRECTORIES false translations/*.ts)
588608
if (QT_VERSION_MAJOR LESS 6)
589609
qt5_add_translation(APP_QM_FILES ${APP_TS_FILES})

tests/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ find_package(ICU COMPONENTS i18n uc REQUIRED)
6262

6363
# For UT Test
6464
find_package(GTest REQUIRED)
65-
find_package(Qt5Test REQUIRED)
65+
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Test REQUIRED)
6666
find_package(Threads REQUIRED)
6767
include_directories(${GTEST_INCLUDE_DIRS})
6868

@@ -632,7 +632,7 @@ target_link_libraries(${PROJECT_NAME_TEST}
632632
${LIB_NL3_ROUTE_LIBRARIES}
633633
${LIB_UDEV_LIBRARIES}
634634
Threads::Threads
635-
Qt5::Test
635+
Qt${QT_VERSION_MAJOR}::Test
636636
${GTEST_LIBRARYS}
637637
${GTEST_MAIN_LIBRARYS}
638638
gmock

0 commit comments

Comments
 (0)