Skip to content

Commit f97d027

Browse files
re2zerodeepin-bot[bot]
authored andcommitted
build(cmake): refactor Qt version compatibility
- Add Qt auto-detection using find_package(QT NAMES Qt6 Qt5) - 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 - Removes legacy macro-based Qt version handling and implements dynamic package name resolution for Qt, DTK, PolkitQt and QApt dependencies. 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 42c885d commit f97d027

8 files changed

Lines changed: 258 additions & 243 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ CMakeLists.txt.user*
5050
.claude_settings.json
5151
# Auto Claude data directory
5252
.auto-claude/
53+
.claude/
5354

5455
# vs code
5556
.vscode/

CMakeLists.txt

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,17 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
1616
add_definitions(-DDISABLE_POLKIT)
1717
endif()
1818

19-
# 自动检测系统中的Qt版本
20-
if(NOT DEFINED QT_VERSION_MAJOR)
21-
# 首先尝试查找Qt6
22-
find_package(Qt6 QUIET)
23-
if(Qt6_FOUND)
24-
set(QT_VERSION_MAJOR 6)
25-
message("Found Qt6, using Qt version 6")
26-
else()
27-
set(QT_VERSION_MAJOR 5)
28-
message("Found Qt5, using Qt version 5")
29-
endif()
19+
# Auto-detect Qt version (tries Qt6 first, falls back to Qt5)
20+
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
21+
message(STATUS "Found Qt version: ${QT_VERSION_MAJOR}")
22+
23+
# Map to DTK version (Qt6→DTK6, Qt5→DTK5)
24+
if (QT_VERSION_MAJOR MATCHES 6)
25+
set(DTK_VERSION_MAJOR 6)
3026
else()
31-
message("Using manually specified QT_VERSION_MAJOR: ${QT_VERSION_MAJOR}")
27+
set(DTK_VERSION_MAJOR "")
3228
endif()
29+
message(STATUS "Build with DTK: ${DTK_VERSION_MAJOR}")
3330

3431
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-z,relro -Wl,-z,now")
3532

debian/control

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ Build-Depends: debhelper-compat (= 11),
99
libcups2-dev,
1010
libgtest-dev,
1111
libkmod-dev,
12-
libqapt-qt6-dev | libqapt-dev,
13-
libqapt3-qt6-runtime | libqapt3-runtime,
14-
libpolkit-qt6-1-dev | libpolkit-qt5-1-dev,
12+
libqapt-qt6-dev,
13+
libqapt3-qt6-runtime,
14+
libpolkit-qt6-1-dev,
1515
deepin-desktop-base,
1616
libdeepin-service-framework-dev (> 1.0.9),
17-
qt6-base-dev | qtbase5-dev,
18-
qt6-base-dev-tools | qtbase5-dev-tools,
19-
qt6-base-private-dev | qtbase5-private-dev,
20-
qt6-l10n-tools | qttools5-dev-tools,
21-
qt6-tools-dev | qttools5-dev,
22-
qt6-tools-dev-tools | qttools5-dev-tools,
23-
libdtk6gui-dev | libdtkgui-dev,
24-
libdtk6widget-dev | libdtkwidget-dev,
25-
libdtk6core-dev | libdtkcore-dev,
26-
qt6-svg-dev | libqt5svg5-dev,
27-
libqt6sql6 | libqt5sql5
17+
qt6-base-dev,
18+
qt6-base-dev-tools,
19+
qt6-base-private-dev,
20+
qt6-l10n-tools,
21+
qt6-tools-dev,
22+
qt6-tools-dev-tools,
23+
libdtk6gui-dev,
24+
libdtk6widget-dev,
25+
libdtk6core-dev,
26+
qt6-svg-dev,
27+
libqt6sql6
2828
Standards-Version: 4.1.3
2929

3030
Package: deepin-devicemanager
@@ -37,7 +37,7 @@ Depends: ${shlibs:Depends}, ${misc:Depends},
3737
upower,
3838
deepin-shortcut-viewer,
3939
lshw,
40-
libdtk6core | libdtkcore5,
40+
libdtk6core,
4141
libkmod2,
4242
libdeepin-service-framework,
4343
deepin-service-manager,

debian/control.1

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Source: deepin-devicemanager
2+
Section: utils
3+
Priority: optional
4+
Maintainer: Packages <packages@deepin.com>
5+
Build-Depends: debhelper-compat (= 11),
6+
pkg-config,
7+
cmake,
8+
libzmq3-dev,
9+
libcups2-dev,
10+
libgtest-dev,
11+
libkmod-dev,
12+
libqapt-dev,
13+
libqapt3-runtime,
14+
libpolkit-qt5-1-dev,
15+
deepin-desktop-base,
16+
libdeepin-service-framework-dev (> 1.0.9),
17+
qtbase5-dev,
18+
qtbase5-dev-tools,
19+
qtbase5-private-dev,
20+
qttools5-dev-tools,
21+
qttools5-dev,
22+
libdtkgui-dev,
23+
libdtkwidget-dev,
24+
libdtkcore-dev,
25+
libqt5svg5-dev,
26+
libqt5sql5
27+
Standards-Version: 4.1.3
28+
29+
Package: deepin-devicemanager
30+
Architecture: any
31+
Depends: ${shlibs:Depends}, ${misc:Depends},
32+
dmidecode,
33+
x11-xserver-utils,
34+
hwinfo,
35+
cups,
36+
upower,
37+
deepin-shortcut-viewer,
38+
lshw,
39+
libdtkcore5,
40+
libkmod2,
41+
libdeepin-service-framework,
42+
deepin-service-manager,
43+
usbutils,
44+
pciutils,
45+
smartmontools,
46+
bluez,
47+
apt,
48+
lastore-daemon,
49+
kmod,
50+
iputils-ping,
51+
net-tools
52+
Recommends: uos-reporter, deepin-event-log, deepin-elf-sign-tool
53+
Description: Device Manager is a handy tool for viewing hardware information and managing the devices.
54+
Device Manager helps users manage hardware devices installed on computers,
55+
through which users can view parameters and export data of all hardware devices running in the system.

deepin-devicemanager-server/customgpuinfo/CMakeLists.txt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,8 @@ cmake_minimum_required(VERSION 3.7)
22

33
set(BIN_NAME "customgpuinfo")
44

5-
macro(SET_QT_VERSION)
6-
if(${QT_VERSION_MAJOR} EQUAL 6)
7-
find_package(Qt6 COMPONENTS Core REQUIRED)
8-
elseif(${QT_VERSION_MAJOR} EQUAL 5)
9-
find_package(Qt5 COMPONENTS Core REQUIRED)
10-
else()
11-
message(FATAL_ERROR "Unsupported QT_VERSION_MAJOR: ${QT_VERSION_MAJOR}")
12-
endif()
13-
endmacro()
14-
15-
SET_QT_VERSION()
5+
# Find Qt package with detected version
6+
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
167

178
file(GLOB_RECURSE SRC
189
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"

deepin-devicemanager-server/deepin-devicecontrol/CMakeLists.txt

Lines changed: 64 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -32,43 +32,34 @@ endforeach()
3232
file(GLOB_RECURSE SRC_CPP ${CMAKE_CURRENT_LIST_DIR}/src/*.cpp)
3333
file(GLOB_RECURSE SRC_H ${CMAKE_CURRENT_LIST_DIR}/src/*.h)
3434

35-
macro(SET_QT_VERSION)
36-
if(${QT_VERSION_MAJOR} EQUAL 6)
37-
# Qt6 环境
38-
find_package(PkgConfig REQUIRED)
39-
find_package(Qt6 COMPONENTS Core DBus Network Sql REQUIRED)
40-
find_package(PolkitQt6-1 REQUIRED)
41-
find_package(deepin-qdbus-service REQUIRED)
42-
find_package(Dtk6 COMPONENTS
43-
Widget
44-
Core
45-
REQUIRED
46-
)
47-
elseif(${QT_VERSION_MAJOR} EQUAL 5)
48-
# Qt5 环境
49-
find_package(PkgConfig REQUIRED)
50-
find_package(Qt5 COMPONENTS Core DBus Network Sql REQUIRED)
51-
find_package(DtkCore REQUIRED)
52-
find_package(PolkitQt5-1 REQUIRED)
53-
find_package(deepin-qdbus-service REQUIRED)
54-
else()
55-
message(FATAL_ERROR "Unsupported QT_VERSION: ${QT_VERSION}")
56-
endif()
57-
endmacro()
58-
59-
# 调用宏
60-
SET_QT_VERSION()
35+
# Find Qt package with detected version
36+
find_package(PkgConfig REQUIRED)
37+
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core DBus Network Sql REQUIRED)
38+
39+
# Find Dtk package with mapped version
40+
find_package(Dtk${DTK_VERSION_MAJOR} COMPONENTS
41+
Widget
42+
Core
43+
REQUIRED
44+
)
6145

46+
# Define external dependency package names based on Qt version
6247
if(${QT_VERSION_MAJOR} EQUAL 6)
63-
find_package(QApt-qt6 REQUIRED)
64-
include_directories(${QApt-qt6_INCLUDE_DIRS})
65-
set(QAPT_LIB QApt-qt6)
48+
set(POLKITQT_NAME "PolkitQt6-1")
49+
set(QAPT_NAME "QApt-qt6")
6650
elseif(${QT_VERSION_MAJOR} EQUAL 5)
67-
find_package(QApt REQUIRED)
68-
include_directories(${QApt_INCLUDE_DIRS})
69-
set(QAPT_LIB QApt)
51+
set(POLKITQT_NAME "PolkitQt5-1")
52+
set(QAPT_NAME "QApt")
53+
else()
54+
message(FATAL_ERROR "Unsupported QT_VERSION_MAJOR: ${QT_VERSION_MAJOR}")
7055
endif()
7156

57+
# Find external dependencies
58+
find_package(${POLKITQT_NAME} REQUIRED)
59+
find_package(deepin-qdbus-service REQUIRED)
60+
find_package(${QAPT_NAME} REQUIRED)
61+
include_directories(${${QAPT_NAME}_INCLUDE_DIRS})
62+
7263
if(NOT DISABLE_DRIVER)
7364
PKG_SEARCH_MODULE(kmod REQUIRED libkmod IMPORTED_TARGET)
7465
endif()
@@ -82,58 +73,57 @@ include_directories("/usr/include/cups/")
8273

8374
add_definitions(-DSERVICE_CONFIG_DIR="${CMAKE_INSTALL_PREFIX}/share/deepin-service-manager/")
8475

76+
# Include directories with dynamic Qt/DTK versions
8577
if(${QT_VERSION_MAJOR} EQUAL 6)
86-
# Qt6 environment
8778
target_include_directories(${BIN_NAME} PUBLIC
88-
Dtk6::Core
89-
Dtk6::Widget
90-
Qt6::Core
91-
Qt6::DBus
92-
Qt6::Network
93-
Qt6::Sql
94-
Qt6::Gui
95-
${deepin-qdbus-service_INCLUDE_DIR}
96-
${QAPT_LIB}
97-
)
98-
99-
target_link_libraries(${BIN_NAME} PRIVATE
100-
Qt6::Core
101-
Qt6::DBus
102-
Qt6::Network
103-
Qt6::Sql
104-
PolkitQt6-1::Agent
105-
Dtk6::Core
106-
Dtk6::Widget
107-
${deepin-qdbus-service_LIBRARIES}
108-
${QAPT_LIB}
109-
cups
79+
Dtk${DTK_VERSION_MAJOR}::Core
80+
Dtk${DTK_VERSION_MAJOR}::Widget
81+
Qt${QT_VERSION_MAJOR}::Core
82+
Qt${QT_VERSION_MAJOR}::DBus
83+
Qt${QT_VERSION_MAJOR}::Network
84+
Qt${QT_VERSION_MAJOR}::Sql
85+
Qt${QT_VERSION_MAJOR}::Gui
86+
${deepin-qdbus-service_INCLUDE_DIR}
87+
${QAPT_NAME}
88+
)
89+
90+
target_link_libraries(${BIN_NAME} PRIVATE
91+
Qt${QT_VERSION_MAJOR}::Core
92+
Qt${QT_VERSION_MAJOR}::DBus
93+
Qt${QT_VERSION_MAJOR}::Network
94+
Qt${QT_VERSION_MAJOR}::Sql
95+
${POLKITQT_NAME}::Agent
96+
Dtk${DTK_VERSION_MAJOR}::Core
97+
Dtk${DTK_VERSION_MAJOR}::Widget
98+
${deepin-qdbus-service_LIBRARIES}
99+
${QAPT_NAME}
100+
cups
110101
)
111102
elseif(${QT_VERSION_MAJOR} EQUAL 5)
112-
# Qt5 environment
113103
target_include_directories(${BIN_NAME} PUBLIC
114-
Qt5::Core
115-
Qt5::DBus
116-
Qt5::Network
117-
Qt5::Sql
118-
${deepin-qdbus-service_INCLUDE_DIR}
119-
)
120-
121-
target_link_libraries(${BIN_NAME} PRIVATE
122-
Qt5::Core
123-
Qt5::DBus
124-
Qt5::Network
125-
Qt5::Sql
126-
PolkitQt5-1::Agent
127-
${DtkCore_LIBRARIES}
128-
${deepin-qdbus-service_LIBRARIES}
129-
cups
130-
)
104+
Qt${QT_VERSION_MAJOR}::Core
105+
Qt${QT_VERSION_MAJOR}::DBus
106+
Qt${QT_VERSION_MAJOR}::Network
107+
Qt${QT_VERSION_MAJOR}::Sql
108+
${deepin-qdbus-service_INCLUDE_DIR}
109+
)
110+
111+
target_link_libraries(${BIN_NAME} PRIVATE
112+
Qt${QT_VERSION_MAJOR}::Core
113+
Qt${QT_VERSION_MAJOR}::DBus
114+
Qt${QT_VERSION_MAJOR}::Network
115+
Qt${QT_VERSION_MAJOR}::Sql
116+
${POLKITQT_NAME}::Agent
117+
${DtkCore_LIBRARIES}
118+
${deepin-qdbus-service_LIBRARIES}
119+
cups
120+
)
131121
endif()
132122

133123
if(NOT DISABLE_DRIVER)
134124
target_link_libraries(${BIN_NAME} PRIVATE
135125
kmod
136-
${QAPT_LIB}
126+
${QAPT_NAME}
137127
)
138128
endif()
139129

0 commit comments

Comments
 (0)