Skip to content

fix: [build]add Qt5/Qt6 compatibility and improve build system config…#114

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
re2zero:cherry-eagle
Dec 2, 2025
Merged

fix: [build]add Qt5/Qt6 compatibility and improve build system config…#114
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
re2zero:cherry-eagle

Conversation

@re2zero
Copy link
Contributor

@re2zero re2zero commented Dec 1, 2025

…uration

  • Update CMakeLists.txt to dynamically detect Qt version and use appropriate DTK versions
  • Modify debian/control to support both Qt5 and Qt6 build dependencies

Log: Fix Qt5/Qt6 compatibility building issue.

Summary by Sourcery

Add Qt5/Qt6 compatible build configuration and centralised translation generation while aligning DTK usage with detected Qt version.

New Features:

  • Introduce a reusable CMake translation generation module and hook it into the downloader target.

Bug Fixes:

  • Resolve build failures by making moc/resource generation, DTK linkage, and QTextStream line endings compatible with both Qt5 and Qt6.
  • Fix missing includes causing build issues in the extension service components.

Enhancements:

  • Use GNUInstallDirs and conditional CMAKE_INSTALL_PREFIX configuration instead of a hard-coded install prefix.
  • Automatically detect the Qt major version and configure DTK major version and Qt components accordingly across the project.
  • Remove ad-hoc translation generation scripts in favor of CMake-based handling of translation files and installation.
  • Unify and modernize CMake logic across UI, database, aria2, extension service, and tests for Qt-dependent code generation macros.

Tests:

  • Update test CMake configuration to respect the detected Qt version and DTK major version for moc generation and linking.

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 1, 2025

Reviewer's Guide

This PR makes the project buildable with both Qt5 and Qt6 by centralizing Qt/DTK detection in the top-level CMake, conditionally using the correct Qt moc/resource macros throughout subdirectories, introducing a reusable translation generation CMake module, and adapting logging/IO code to API differences between Qt5 and Qt6, alongside updating Debian packaging to declare dual Qt build dependencies.

Flow diagram for Qt version specific moc/resource handling

flowchart TB
  Start["Configure subdirectory CMakeLists.txt"] --> CheckQt["Check QT_VERSION or QT_VERSION_MAJOR"]

  CheckQt -->|"Qt >= 6.0"| Qt6Path
  CheckQt -->|"Qt < 6.0"| Qt5Path

  subgraph Qt6Path[Qt6 path]
    Qt6MocUi["ui/CMakeLists: qt_wrap_cpp(UDLC_UI_HEADERS_MOC)"]
    Qt6ResUi["ui/CMakeLists: qt_add_resources(QRC_FILES)"]
    Qt6MocExt["extensionService/CMakeLists: qt_wrap_cpp(DWM_EXTENSIONSERVICE_HEADERS_MOC)"]
    Qt6MocAria["aria2/CMakeLists: qt_wrap_cpp(DWM_ARIA_HEADERS_MOC)"]
    Qt6MocDb["database/CMakeLists: qt_wrap_cpp(DWM_DATABASE_HEADERS_MOC)"]
  end

  subgraph Qt5Path[Qt5 path]
    Qt5MocUi["ui/CMakeLists: qt5_wrap_cpp(UDLC_UI_HEADERS_MOC)"]
    Qt5ResUi["ui/CMakeLists: qt5_add_resources(QRC_FILES)"]
    Qt5MocExt["extensionService/CMakeLists: qt5_wrap_cpp(DWM_EXTENSIONSERVICE_HEADERS_MOC)"]
    Qt5MocAria["aria2/CMakeLists: qt5_wrap_cpp(DWM_ARIA_HEADERS_MOC)"]
    Qt5MocDb["database/CMakeLists: qt5_wrap_cpp(DWM_DATABASE_HEADERS_MOC)"]
  end

  Qt6Path --> End["Targets built with Qt6-compatible macros"]
  Qt5Path --> End
Loading

File-Level Changes

Change Details Files
Centralize installation and translation configuration in the top-level CMake and introduce a reusable translation generation module.
  • Use GNUInstallDirs and restore conditional default CMAKE_INSTALL_PREFIX logic instead of hardcoding /usr.
  • Extend CMAKE_MODULE_PATH and include a new translation-generate CMake module.
  • Remove ad-hoc release-time translation generation script execution and translation installation from the top-level CMake.
  • Add a cmake/translation-generate.cmake function that locates lrelease for the current Qt major version, finds .ts files in a given directory, and defines custom commands to produce .qm files.
CMakeLists.txt
cmake/translation-generate.cmake
Make the build system compatible with both Qt5 and Qt6 and align DTK usage accordingly.
  • Use find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) to detect the Qt major version and set QT_VERSION_MAJOR accordingly.
  • Derive DTK_VERSION_MAJOR from QT_VERSION_MAJOR (6 vs empty for older versions) and use it in all DTK-related find_package calls and target_link_libraries usages.
  • Unify the list of Qt components and remove LinguistTools from the global Qt component list, since translation handling is moved to the new module.
  • Replace hardcoded Dtk6* libraries/targets with Dtk${DTK_VERSION_MAJOR}* everywhere, including ui, extensionService, database, aria2, and tests targets.
  • Conditionally choose between qt_wrap_cpp/qt_add_resources and qt5_wrap_cpp/qt5_add_resources based on the active Qt version in ui, extensionService, aria2, database, and tests CMakeLists.
CMakeLists.txt
src/src/ui/CMakeLists.txt
src/src/extensionService/CMakeLists.txt
src/src/aria2/CMakeLists.txt
src/src/database/CMakeLists.txt
tests/CMakeLists.txt
Adjust translation generation and installation to work with both Qt5 and Qt6.
  • Introduce a TRANSLATION_GENERATE(QM_FILES ...) call in the downloader CMakeLists to build .qm files from translations at configure/build time.
  • Create a custom target for translation files and make the main downloader target depend on it so translations are generated before the binary is built/installed.
  • Install generated .qm files under share/${PROJECT_NAME}/translations instead of using a hard-coded share/downloader path and manual GLOB of prebuilt .qm files.
  • Remove legacy commented-out translation generation in the ui CMakeLists now superseded by the centralized module.
src/src/downloader/CMakeLists.txt
src/src/ui/CMakeLists.txt
cmake/translation-generate.cmake
CMakeLists.txt
Make logging and text-stream newline usage compatible with both Qt5 and Qt6.
  • Introduce an ENDL macro in log.cpp that maps to Qt::endl for Qt6 and endl for Qt5, and use it for QTextStream line termination in log writing functions.
  • Introduce a QT_ENDL macro in ui func.h with the same Qt5/Qt6 mapping and use it when writing MIME and autostart configuration files.
  • Update all QTextStream usages that previously hard-coded Qt::endl to use the new macros.
src/src/log/log.cpp
src/include/ui/func.h
src/src/ui/func.cpp
src/src/ui/mainFrame/mainframe.cpp
Minor Qt6-oriented source updates and packaging/build system adjustments.
  • Include QDebug in extensionService main.cpp and websockethandle.cpp to support debug logging, likely used elsewhere with Qt6.
  • Add or update Debian packaging files (control, rules, .install) to declare both Qt5 and Qt6 build dependencies and align install paths with the new CMake install layout.
  • Add a .cursorindexingignore file and adjust .gitignore (diff not shown) to tune repository tooling and ignore patterns.
src/src/extensionService/main.cpp
src/src/extensionService/websockethandle.cpp
debian/control
debian/rules
debian/org.deepin.downloader.install
.cursorindexingignore
.gitignore

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

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 there - I've reviewed your changes - here's some feedback:

  • The CMake conditionals like if (QT_VERSION VERSION_GREATER_EQUAL "6.0") rely on a QT_VERSION variable that doesn't seem to be set anywhere; consider basing these checks on QT_VERSION_MAJOR (e.g. if (QT_VERSION_MAJOR GREATER_EQUAL 6)) or the Qt package's own version variables to avoid configuration-time errors.
  • The ENDL/QT_ENDL macros currently map to bare endl for Qt < 6, which is a std manipulator and may not be visible without std::endl or using std::endl; to keep behavior consistent and avoid namespace issues, either map both branches to Qt::endl or explicitly use std::endl with the appropriate header.
  • In translation-generate.cmake, the fallback QT_LRELEASE path /lib/qt${QT_VERSION_MAJOR}/bin/lrelease is hard-coded and may not exist on many systems; it’d be more robust to use find_program (with common search paths as hints) or make this a cache variable the packager can override.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The CMake conditionals like `if (QT_VERSION VERSION_GREATER_EQUAL "6.0")` rely on a `QT_VERSION` variable that doesn't seem to be set anywhere; consider basing these checks on `QT_VERSION_MAJOR` (e.g. `if (QT_VERSION_MAJOR GREATER_EQUAL 6)`) or the Qt package's own version variables to avoid configuration-time errors.
- The `ENDL`/`QT_ENDL` macros currently map to bare `endl` for Qt < 6, which is a `std` manipulator and may not be visible without `std::endl` or `using std::endl`; to keep behavior consistent and avoid namespace issues, either map both branches to `Qt::endl` or explicitly use `std::endl` with the appropriate header.
- In `translation-generate.cmake`, the fallback `QT_LRELEASE` path `/lib/qt${QT_VERSION_MAJOR}/bin/lrelease` is hard-coded and may not exist on many systems; it’d be more robust to use `find_program` (with common search paths as hints) or make this a cache variable the packager can override.

## Individual Comments

### Comment 1
<location> `cmake/translation-generate.cmake:4-5` </location>
<code_context>
+function(TRANSLATION_GENERATE QMS)
+  find_package(Qt${QT_VERSION_MAJOR}LinguistTools QUIET)
+
+  if (NOT Qt${QT_VERSION_MAJOR}_LRELEASE_EXECUTABLE)
+    set(QT_LRELEASE "/lib/qt${QT_VERSION_MAJOR}/bin/lrelease")
+    message(STATUS "NOT found lrelease, set QT_LRELEASE = ${QT_LRELEASE}")
+  else()
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Hard-coding a fallback lrelease path is brittle; prefer a search or an explicit failure.

This fallback to `/lib/qt${QT_VERSION_MAJOR}/bin/lrelease` will fail on many setups (non-standard prefixes, Windows, custom Qt installs) and may do so silently. Instead, consider using `find_program(QT_LRELEASE lrelease)` (optionally with hints) and, if still not found, emit a `FATAL_ERROR` so configuration fails clearly rather than producing missing or stale translations.

Suggested implementation:

```
function(TRANSLATION_GENERATE QMS)
  find_package(Qt${QT_VERSION_MAJOR}LinguistTools QUIET)

  if (Qt${QT_VERSION_MAJOR}_LRELEASE_EXECUTABLE)
    # Prefer the lrelease executable provided by the found Qt package
    set(QT_LRELEASE "${Qt${QT_VERSION_MAJOR}_LRELEASE_EXECUTABLE}")
  else()
    # Fallback: search lrelease on PATH (optionally extended by the caller)
    find_program(QT_LRELEASE NAMES lrelease)

    if (NOT QT_LRELEASE)
      message(FATAL_ERROR
        "Could not find Qt lrelease executable. "
        "Ensure Qt Linguist tools are installed and lrelease is available on PATH, "
        "or provide Qt${QT_VERSION_MAJOR}_LRELEASE_EXECUTABLE via find_package(Qt${QT_VERSION_MAJOR}LinguistTools)."
      )
    else()
      message(STATUS "Using lrelease found at: ${QT_LRELEASE}")
    endif()
  endif()

```

```
  if(NOT ARGN)
    message(SEND_ERROR "Error: TRANSLATION_GENERATE() called without any .ts path")
    return()
  endif()

```
</issue_to_address>

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.

…uration

- Update CMakeLists.txt to dynamically detect Qt version and use appropriate DTK versions
- Modify debian/control to support both Qt5 and Qt6 build dependencies

Log: Fix Qt5/Qt6 compatibility building issue.
@deepin-ci-robot
Copy link
Contributor

deepin pr auto review

这是一个包含多个文件修改的 Git diff,主要涉及构建系统和 Qt 版本兼容性的更改。让我逐一分析主要修改:

  1. 构建系统改进:
  • 添加了 .cursorindexingignore 文件来忽略 SpecStory 自动保存文件
  • 更新了 .gitignore,添加了 build*/ 模式
  • 修改了 CMakeLists.txt,改进了 Qt 版本检测和 DTK 版本处理
  • 添加了新的 cmake/translation-generate.cmake 文件用于翻译文件生成
  1. Qt 版本兼容性:
  • 添加了对 Qt5 和 Qt6 的兼容性支持
  • 修改了多个 CMakeLists.txt 文件以支持不同 Qt 版本的构建
  • 在源代码中添加了版本检查宏(如 QT_ENDL 和 ENDL)
  1. 包依赖更新:
  • 更新了 debian/control 文件,添加了对 Qt5 和 Qt6 的可选依赖
  • 修改了 debian/rules 文件以支持 Qt 版本检测
  1. 翻译系统改进:
  • 重构了翻译文件的生成和安装过程
  • 将翻译文件的生成从 CMakeLists.txt 移到了专门的 cmake 模块中

建议改进:

  1. 代码质量:
  • 在 translation-generate.cmake 中,建议添加对 TS_FILES 是否为空的检查
  • 在 Qt 版本检查时,建议使用更明确的版本比较方式
  1. 性能优化:
  • 可以考虑在 CMakeLists.txt 中添加编译选项优化,如 -O3 用于 Release 构建
  • 建议添加并行编译支持以提高构建速度
  1. 安全性:
  • 建议在文件操作中添加更多的错误检查
  • 在路径处理时建议使用标准库函数而不是字符串拼接
  1. 可维护性:
  • 建议将 Qt 版本相关的宏定义集中到一个头文件中
  • 可以考虑添加更多的构建文档说明不同 Qt 版本的构建要求
  1. 具体修改建议:
# 在 CMakeLists.txt 中添加
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif()

# 添加编译器特定优化
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
    set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
endif()

# 在 translation-generate.cmake 中添加检查
if(NOT EXISTS "${ARGN}")
    message(WARNING "Translation directory does not exist: ${ARGN}")
    return()
endif()

这些修改提高了代码的可维护性和健壮性,同时保持了与不同 Qt 版本的兼容性。建议在实施这些更改时进行充分的测试,特别是在不同的 Qt 版本环境下。

@deepin-ci-robot
Copy link
Contributor

[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
Copy link
Contributor Author

re2zero commented Dec 2, 2025

/merge

@deepin-bot deepin-bot bot merged commit ed7b9b6 into linuxdeepin:master Dec 2, 2025
18 checks passed
@re2zero re2zero deleted the cherry-eagle branch December 2, 2025 01:28
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