Skip to content

build(cmake): refactor Qt version compatibility#190

Merged
re2zero merged 1 commit intolinuxdeepin:masterfrom
re2zero:bugfix
Jan 27, 2026
Merged

build(cmake): refactor Qt version compatibility#190
re2zero merged 1 commit intolinuxdeepin:masterfrom
re2zero:bugfix

Conversation

@re2zero
Copy link
Contributor

@re2zero re2zero commented Jan 27, 2026

  • 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
  • remove Qt5 fallback build dependencies
  • adjust Qt private include paths to use modern Qt6 syntax
  • add conditional Qt6 WidgetsPrivate linking
  • refactor DTK version variable usage throughout build system
  • maintain NO_DBUS_CALLER_AUTH_CHECK for Qt5 builds

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

Summary by Sourcery

Refactor the CMake-based build to support both Qt5 and Qt6/DTK6 via auto-detection, modern Qt private include usage, and updated Debian packaging for separate Qt5/Qt6 build configurations.

Build:

  • Raise minimum CMake version to 3.13 across all CMake targets.
  • Introduce unified Qt auto-detection (Qt6 first, falling back to Qt5) and map the detected Qt major version to corresponding DTK major versions in the root CMake configuration.
  • Update all targets to use Qt major-versioned targets (Qt${QT_VERSION_MAJOR}::) and DTK major-versioned packages (Dtk${DTK_VERSION_MAJOR}) including private Gui includes.
  • Make WidgetsPrivate linking conditional on Qt6, avoiding invalid linkage for Qt5.
  • Keep NO_DBUS_CALLER_AUTH_CHECK defined only for Qt5 builds.

Tests:

  • Switch tests to link against the versioned Qt core target (Qt${QT_VERSION_MAJOR}::Core) and align their DTK and private include usage with the main build.

Chores:

  • Split Debian packaging into separate control files for Qt6 (V25) and Qt5 (V20) build dependencies, removing legacy Qt5 fallback build dependencies.

- 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
- remove Qt5 fallback build dependencies
- adjust Qt private include paths to use modern Qt6 syntax
- add conditional Qt6 WidgetsPrivate linking
- refactor DTK version variable usage throughout build system
- maintain NO_DBUS_CALLER_AUTH_CHECK for Qt5 builds

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
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 27, 2026

Reviewer's Guide

Refactors CMake and Debian packaging to auto-detect Qt (Qt6/Qt5), align DTK version handling, modernize Qt private include and WidgetsPrivate usage, and split Debian control files so V25 (Qt6) and V20 (Qt5) builds use appropriate dependencies.

File-Level Changes

Change Details Files
Introduce unified Qt auto-detection and DTK version mapping in top-level CMake and preserve Qt5-specific DBus define.
  • Increase minimum CMake version from 3.0 to 3.13 across multiple CMakeLists to support modern Qt usage and targets.
  • Replace manual Qt6/Qt5 detection logic with find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) and log the detected major Qt version.
  • Introduce DTK_VERSION_MAJOR derived from QT_VERSION_MAJOR and remove the older DTK_VERSION variable usage.
  • Retain NO_DBUS_CALLER_AUTH_CHECK only for Qt5 builds by conditioning the compile definition on QT_VERSION_MAJOR == 5.
CMakeLists.txt
application/CMakeLists.txt
service/CMakeLists.txt
basestruct/CMakeLists.txt
log/CMakeLists.txt
Normalize DTK and Qt usage in subprojects and tests, including private includes and WidgetsPrivate linking for Qt6 only.
  • Update all Dtk find_package calls and link targets to use Dtk${DTK_VERSION_MAJOR} instead of Dtk${DTK_VERSION}.
  • Switch from raw *_PRIVATE_INCLUDE_DIRS variables to Qt${QT_VERSION_MAJOR}::GuiPrivate in target_include_directories for application, service, basestruct, log, and tests.
  • Make WidgetsPrivate linking conditional on Qt6 by appending Qt${QT_VERSION_MAJOR}::WidgetsPrivate to LINK_LIBS only when QT_VERSION_MAJOR == 6.
  • Adjust tests and auxiliary targets to link against Qt${QT_VERSION_MAJOR}::Core instead of hardcoded Qt5::Core and fix the Qt Gui private target name casing (Gui_private→GuiPrivate).
tests/CMakeLists.txt
application/CMakeLists.txt
service/CMakeLists.txt
basestruct/CMakeLists.txt
log/CMakeLists.txt
test/CMakeLists.txt
Separate Debian packaging metadata for Qt5 and Qt6 environments and remove Qt5 fallbacks from the main control file.
  • Split Debian control into a new control.1 for V20/Qt5 that explicitly depends on qtbase5-dev, qttools5-* and libdtk*-dev packages.
  • Keep the primary debian/control aligned with V25/Qt6 and drop Qt5 fallback build dependencies.
  • Ensure build-dependency sets are version-specific so that V25 uses Qt6/DTK6 while V20 uses Qt5/DTK5 without conditional logic in a single control file.
debian/control
debian/control.1

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
Copy link

deepin pr auto review

这份代码变更主要是将项目从 Qt5/Qt6 混合支持迁移到以 Qt6 为主,并统一了 CMake 的版本要求和构建逻辑。以下是对该 diff 的详细审查意见:

1. 语法逻辑审查

  • CMake 最低版本提升
    • 变更点:将 cmake_minimum_required(VERSION 3.0) 提升至 VERSION 3.13
    • 意见合理。CMake 3.13 引入了 find_packageNAMES 参数列表功能(即 find_package(QT NAMES Qt6 Qt5 ...)),这是代码中使用的核心特性。提升版本是必要的。
  • Qt 版本检测逻辑
    • 变更点:使用了 find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
    • 意见优秀。这是现代 CMake 处理多版本依赖的标准方式,优先尝试 Qt6,失败后回退到 Qt5。
  • DTK 版本映射
    • 变更点:根据 QT_VERSION_MAJOR 设置 DTK_VERSION_MAJOR
    • 意见逻辑正确。Qt6 对应 DTK6,Qt5 对应 DTK5。
    • 潜在问题:在根目录 CMakeLists.txt 中,当 QT_VERSION_MAJOR 为 5 时,DTK_VERSION_MAJOR 被设置为空字符串 ("")。
      • 建议:虽然后续代码中使用了 find_package(Dtk${DTK_VERSION_MAJOR}Widget ...),对于 Qt5 来说,DtkWidget 通常对应 DTK5。如果 DTK 的包名严格遵循 Dtk5Widget,那么这里设置为空字符串可能会导致查找失败(变成 find_package(DtkWidget ...))。建议改为 set(DTK_VERSION_MAJOR 5) 以确保显式匹配,或者确认 DTK 的 CMake 配置文件是否支持不带版本号的查找。不过,考虑到 debian/control 文件中移除了 Qt5 的依赖,这可能是为了彻底移除 Qt5 支持的前奏。
  • 目标名称修正
    • 变更点:在 tests/CMakeLists.txt 中,将 target_include_directories(${PROJECT_NAME} ...) 修正为 target_include_directories(${PROJECT_NAME_TEST} ...)
    • 意见关键修复。原代码引用了不存在的 ${PROJECT_NAME}(在该文件中定义为 deepin-diskmanager,但通常测试文件定义的是 ${PROJECT_NAME_TEST}),会导致构建错误。此修复非常必要。
  • 私有头文件引用
    • 变更点:将 ${Qt5Gui_PRIVATE_INCLUDE_DIRS} 替换为 Qt${QT_VERSION_MAJOR}::GuiPrivate
    • 意见正确。使用 CMake 导入的目标(如 Qt6::GuiPrivate)比直接使用变量路径更符合现代 CMake 实践,且能自动处理依赖关系。
    • 拼写修正:在 log/CMakeLists.txt 中,将 Qt${QT_VERSION_MAJOR}::Gui_private 修正为 Qt${QT_VERSION_MAJOR}::GuiPrivate。CMake 的目标名称通常区分大小写且遵循驼峰命名,这个修正避免了链接错误。

2. 代码质量审查

  • 一致性
    • 意见:代码在所有子模块中统一了变量命名(如 DTK_VERSION_MAJOR)和查找方式,提高了代码的可维护性。
  • 条件编译
    • 变更点:针对 WidgetsPrivate 模块,仅在 Qt6 时添加到 LINK_LIBS
    • 意见良好。这避免了在 Qt5 环境下链接不存在的模块,体现了对跨版本兼容性的细致处理(尽管主分支似乎正在移除 Qt5 支持)。
  • 依赖声明
    • 变更点:在 service/CMakeLists.txt 中,将 find_package(PolkitQt${QT_VERSION_MAJOR}-1) 改为 REQUIRED
    • 意见改进。显式声明该依赖为必须,如果缺失则立即报错,避免了后续链接时的模糊错误。

3. 代码性能审查

  • CMake 构建性能
    • 使用 find_packageNAMES 参数一次性查找,比原来的分别查找 Qt6 和 Qt5 再判断逻辑更高效,减少了 CMake 配置阶段的脚本执行开销。

4. 代码安全审查

  • 编译器标志保留
    • 代码保留了 -fstack-protector-all(栈保护)、-fPIE/-pie(位置无关可执行)、-z relro/-z now(重定位只读)、-z noexecstack(不可执行栈)等安全编译选项。
    • 意见优秀。这些是防御缓冲区溢出和代码注入攻击的重要措施,保留它们确保了二进制程序的安全性。
  • DBUS 认证检查
    • 变更点:保留了 if (QT_VERSION_MAJOR MATCHES 5) add_compile_definitions(NO_DBUS_CALLER_AUTH_CHECK)
    • 意见注意。这意味着在 Qt5 模式下会禁用 DBUS 调用者认证检查。这是一个潜在的安全风险点。
    • 建议:如果项目计划彻底移除 Qt5 支持(如 debian/control 所示),这段代码最终可以删除。如果短期内保留 Qt5 支持,需要确保 Qt5 版本的程序运行在受信任的环境或通过其他机制(如 PolicyKit)弥补这一安全缺口。

5. 构建系统与依赖审查

  • debian/control 变更
    • 变更点:移除了所有 Qt5 相关的构建依赖(qttools5-dev, qtbase5-dev, libdtkwidget-dev, libpolkit-qt5-1-dev),只保留 Qt6 版本。
    • 意见彻底。这与 CMake 脚本中保留 Qt5 回退逻辑看起来有些矛盾。
    • 解释:这很可能是一个两步走的迁移策略:
      1. 当前阶段:CMake 脚本保持兼容性,以便开发者本地环境如有 Qt5 仍可构建,或者为了平滑过渡。
      2. 打包阶段:官方发布的 Debian 包强制使用 Qt6 构建。
    • 风险:如果 CMake 脚本保留 Qt5 逻辑,但 debian/control 移除了 Qt5 依赖,那么在官方构建环境中,find_package 会自动找到 Qt6,逻辑是通的。但在没有 Qt6 的旧系统上,即使修改了 debian/control 加回 Qt5 依赖,CMake 脚本中的 DTK_VERSION_MAJOR 为空字符串的问题(如前所述)可能会导致构建失败。
    • 建议:确认 DTK_VERSION_MAJOR 在 Qt5 下的赋值逻辑,确保在极端情况下(强制回退 Qt5)构建系统的健壮性。

总结与改进建议

  1. 关于 DTK_VERSION_MAJOR 的赋值

    • 建议:在根目录 CMakeLists.txt 中,建议将 Qt5 分支的 set(DTK_VERSION_MAJOR "") 修改为 set(DTK_VERSION_MAJOR 5)。这样逻辑更清晰,且能确保 find_package(Dtk5Widget ...) 能正确执行。
    if (QT_VERSION_MAJOR MATCHES 6)
        set(DTK_VERSION_MAJOR 6)
    else()
        set(DTK_VERSION_MAJOR 5) # 建议显式设置为 5
    endif()
  2. 关于 Qt5 支持的去留

    • 建议:鉴于 debian/control 已经移除了 Qt5 依赖,建议在 CMake 代码中评估是否还需要保留 Qt5 的回退逻辑。如果确定只支持 Qt6,可以简化 CMake 脚本,移除 find_package 中的 Qt5 选项及相关的 if (QT_VERSION_MAJOR MATCHES 5) 判断,减少代码复杂度。
  3. 关于 debian/control.1

    • 观察:新增了一个 debian/control.1 文件,内容是旧的 Qt5 依赖配置。
    • 建议:明确该文件的用途。如果是备份,建议使用版本控制系统(Git)而不是在源码树中保留 .1 后缀的副本,以免造成混淆或被错误打包。如果是用于特定的发行版分支,建议在文档中说明。

总体而言,这次变更将构建系统向现代 CMake 标准和 Qt6 迈进了重要的一步,修复了明显的 Bug(如 tests/CMakeLists.txt 的目标名称),并保持了必要的安全编译选项。主要需要关注的是 Qt5 回退逻辑的完整性与实际打包策略的一致性。

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Using Qt${QT_VERSION_MAJOR}::GuiPrivate inside target_include_directories (e.g. in application, service, basestruct, log, tests) is not the intended pattern for Qt’s private modules; instead, you should link against the GuiPrivate target via target_link_libraries and rely on its usage requirements to propagate include directories.
  • The new DTK_VERSION_MAJOR mapping leaves it empty for Qt5 (QT_VERSION_MAJOR MATCHES 6 → 6, else empty), which changes the generated package/target names to DtkWidget, DtkGui, etc.; please double-check this matches the actual DTK target and package naming for Qt5, or make the Qt5/Qt6 DTK mapping explicit to avoid silent mismatches.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Using `Qt${QT_VERSION_MAJOR}::GuiPrivate` inside `target_include_directories` (e.g. in application, service, basestruct, log, tests) is not the intended pattern for Qt’s private modules; instead, you should link against the `GuiPrivate` target via `target_link_libraries` and rely on its usage requirements to propagate include directories.
- The new `DTK_VERSION_MAJOR` mapping leaves it empty for Qt5 (`QT_VERSION_MAJOR MATCHES 6` → 6, else empty), which changes the generated package/target names to `DtkWidget`, `DtkGui`, etc.; please double-check this matches the actual DTK target and package naming for Qt5, or make the Qt5/Qt6 DTK mapping explicit to avoid silent mismatches.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, re2zero

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@re2zero re2zero merged commit 6a54479 into linuxdeepin:master Jan 27, 2026
16 of 18 checks passed
@re2zero re2zero deleted the bugfix branch January 27, 2026 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants