Skip to content

Commit d301b2e

Browse files
committed
feat: add Qt5 and Qt6 dual version support
1. Added automatic Qt version detection in CMakeLists.txt to support both Qt5 and Qt6 2. Modified CMake configuration to use dynamic Qt version variables instead of hardcoded Qt6 3. Updated debian/control to include Qt5 package alternatives for build dependencies 4. Enhanced debian/rules to detect available Qt version and set appropriate QT_DIR 5. This change allows the project to build on systems with either Qt5 or Qt6 installed Log: Added support for both Qt5 and Qt6 versions Influence: 1. Test building on systems with only Qt5 installed 2. Test building on systems with only Qt6 installed 3. Verify application functionality on both Qt5 and Qt6 environments 4. Check that all UI components render correctly in both versions 5. Test device formatting functionality remains consistent across Qt versions feat: 添加 Qt5 和 Qt6 双版本支持 1. 在 CMakeLists.txt 中添加自动 Qt 版本检测,支持 Qt5 和 Qt6 2. 修改 CMake 配置使用动态 Qt 版本变量替代硬编码的 Qt6 3. 更新 debian/control 包含 Qt5 包替代方案用于构建依赖 4. 增强 debian/rules 以检测可用 Qt 版本并设置合适的 QT_DIR 5. 此更改允许项目在安装 Qt5 或 Qt6 的系统上构建 Log: 新增对 Qt5 和 Qt6 双版本的支持 Influence: 1. 在仅安装 Qt5 的系统上测试构建 2. 在仅安装 Qt6 的系统上测试构建 3. 验证应用在 Qt5 和 Qt6 环境下的功能 4. 检查所有 UI 组件在两个版本中是否正确渲染 5. 测试设备格式化功能在 Qt 版本间保持一致 TASK: https://pms.uniontech.com/task-view-383509.html
1 parent 91a9500 commit d301b2e

File tree

3 files changed

+48
-30
lines changed

3 files changed

+48
-30
lines changed

CMakeLists.txt

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
1010
# 包含 GNUInstallDirs,用于获取标准安装路径
1111
include(GNUInstallDirs)
1212

13+
# Find Qt version
14+
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
15+
message(" >>> Found Qt version: ${QT_VERSION_MAJOR}")
16+
17+
if (QT_VERSION_MAJOR MATCHES 6)
18+
set(DTK_VERSION_MAJOR 6)
19+
else()
20+
set(DTK_VERSION_MAJOR "")
21+
endif()
22+
1323
# 查找必要的包
14-
find_package(Qt6 COMPONENTS Core Gui Widgets Concurrent Network DBus LinguistTools REQUIRED)
15-
find_package(Dtk6 COMPONENTS Widget Gui REQUIRED)
16-
find_package(udisks2-qt6 REQUIRED)
24+
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets Concurrent Network DBus LinguistTools REQUIRED)
25+
find_package(Dtk${DTK_VERSION_MAJOR} COMPONENTS Widget Gui REQUIRED)
26+
find_package(udisks2-qt${QT_VERSION_MAJOR} REQUIRED)
1727
find_package(PkgConfig REQUIRED)
1828
pkg_check_modules(PKGS REQUIRED
1929
x11
@@ -83,16 +93,16 @@ target_include_directories(${PROJECT_NAME} PRIVATE
8393

8494
# 链接库
8595
target_link_libraries(${PROJECT_NAME} PRIVATE
86-
Qt6::Core
87-
Qt6::Gui
88-
Qt6::GuiPrivate
89-
Qt6::Widgets
90-
Qt6::Concurrent
91-
Qt6::Network
92-
Qt6::DBus
93-
Dtk6::Widget
94-
Dtk6::Gui
95-
udisks2-qt6::udisks2-qt6
96+
Qt${QT_VERSION_MAJOR}::Core
97+
Qt${QT_VERSION_MAJOR}::Gui
98+
Qt${QT_VERSION_MAJOR}::GuiPrivate
99+
Qt${QT_VERSION_MAJOR}::Widgets
100+
Qt${QT_VERSION_MAJOR}::Concurrent
101+
Qt${QT_VERSION_MAJOR}::Network
102+
Qt${QT_VERSION_MAJOR}::DBus
103+
Dtk${DTK_VERSION_MAJOR}::Widget
104+
Dtk${DTK_VERSION_MAJOR}::Gui
105+
udisks2-qt${QT_VERSION_MAJOR}::udisks2-qt${QT_VERSION_MAJOR}
96106
${PKGS_LIBRARIES}
97107
)
98108

@@ -103,21 +113,21 @@ target_compile_options(${PROJECT_NAME} PRIVATE ${PKGS_CFLAGS_OTHER})
103113
set(TRANSLATIONS_INSTALL_DIR "${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/translations")
104114

105115
# 添加编译定义,传递安装路径到代码中
106-
target_compile_definitions(${PROJECT_NAME} PRIVATE
116+
target_compile_definitions(${PROJECT_NAME} PRIVATE
107117
"TRANSLATIONS_DIR=\"${TRANSLATIONS_INSTALL_DIR}\""
108118
)
109119

110120
# 安装目标
111-
install(TARGETS ${PROJECT_NAME}
121+
install(TARGETS ${PROJECT_NAME}
112122
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
113123
)
114124

115125
# 安装翻译文件
116-
install(FILES ${QM_FILES}
126+
install(FILES ${QM_FILES}
117127
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/translations
118128
)
119129

120130
# 安装桌面文件
121-
install(FILES dde-device-formatter.desktop
131+
install(FILES dde-device-formatter.desktop
122132
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications
123-
)
133+
)

debian/control

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Priority: optional
44
Maintainer: Deepin Packages Builder <[email protected]>
55
Build-Depends: cmake,
66
debhelper (>=9),
7-
qt6-base-dev,
8-
qt6-declarative-dev,
9-
qt6-tools-dev,
10-
qt6-tools-dev-tools,
11-
qt6-base-private-dev,
12-
libdtk6widget-dev,
13-
libdtk6gui-dev,
14-
libdtk6core-dev,
15-
libudisks2-qt6-dev
7+
qt6-base-dev | qtbase5-dev,
8+
qt6-declarative-dev | qtdeclarative5-dev,
9+
qt6-tools-dev | qttools5-dev,
10+
qt6-tools-dev-tools | qttools5-dev-tools,
11+
qt6-base-private-dev | qtbase5-private-dev,
12+
libdtk6widget-dev | libdtkwidget-dev,
13+
libdtk6gui-dev | libdtkgui-dev,
14+
libdtk6core-dev | libdtkcore-dev,
15+
libudisks2-qt6-dev | libudisks2-qt5-dev
1616
Standards-Version: 3.9.8
1717
Homepage: http://www.deepin.org
1818

debian/rules

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
#!/usr/bin/make -f
22

3-
export QT_SELECT=5
43
include /usr/share/dpkg/default.mk
5-
64
DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
5+
6+
# 检测当前安装的Qt版本,优先使用Qt6,否则使用Qt5
7+
define detect_qt_version
8+
ifneq (,$(shell which qmake6 2>/dev/null))
9+
QT_DIR="/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/Qt6"
10+
else
11+
QT_DIR="/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/Qt5"
12+
endif
13+
endef
14+
715
export DEB_LDFLAGS_APPEND = -Wl,-z,now
816

917
%:
1018
dh $@ --parallel
1119

1220
override_dh_auto_configure:
13-
dh_auto_configure -- VERSION=$(VERSION) LIB_INSTALL_DIR=/usr/lib/$(DEB_HOST_MULTIARCH) DEFINES+="VERSION=$(DEB_VERSION_UPSTREAM)"
21+
dh_auto_configure -- VERSION=$(VERSION) LIB_INSTALL_DIR=/usr/lib/$(DEB_HOST_MULTIARCH) DEFINES+="VERSION=$(DEB_VERSION_UPSTREAM)" QT_DIR=$(QT_DIR)

0 commit comments

Comments
 (0)