Skip to content

Commit

Permalink
feat: Enable Qt6 building
Browse files Browse the repository at this point in the history
Enable build with Qt6, and it compats Qt5.

Log: Enable Qt6 building.
  • Loading branch information
re2zero authored and deepin-bot[bot] committed Jan 3, 2025
1 parent 24bc50e commit e7d9048
Show file tree
Hide file tree
Showing 52 changed files with 437 additions and 199 deletions.
5 changes: 5 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ Files: debian/*
Copyright: UnionTech Software Technology Co., Ltd.
License: CC0-1.0

# cmake
Files: cmake/*
Copyright: UnionTech Software Technology Co., Ltd.
License: CC0-1.0

# Project file
Files: *.pro *.prf *.pri *.qrc *CMakeLists.txt .tx/*
Copyright: UnionTech Software Technology Co., Ltd.
Expand Down
22 changes: 19 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,22 @@ set(CMAKE_SAFETYTEST OFF)
project(deepin_deb_installer)
option(DMAN_RELEAE OFF "Install dman resources to system or not")

find_package(Qt5LinguistTools REQUIRED)
set(POLICY_FILE com.deepin.pkexec.aptInstallDepend.policy)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
# 引入翻译生成
include(translation-generate)

# Find Qt version
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
message(" >>> Found Qt version: ${QT_VERSION_MAJOR}")
set(QT_DESIRED_VERSION ${QT_VERSION_MAJOR})

if (QT_VERSION_MAJOR MATCHES 6)
set(DTK_VERSION_MAJOR 6)
else()
set(DTK_VERSION_MAJOR "")
endif()
message(" >>> Build with DTK: ${DTK_VERSION_MAJOR}")

add_subdirectory(src/AptInstallDepend)
add_subdirectory(src/deb-installer)

Expand All @@ -24,6 +38,8 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
endif()

add_subdirectory(src/deepin-deb-installer-dev)
add_subdirectory(translations)

set(POLICY_FILE com.deepin.pkexec.aptInstallDepend.policy)
add_subdirectory(translations/policy)

# add_subdirectory(tests/FuzzyTest)
39 changes: 39 additions & 0 deletions cmake/translation-generate.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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()
set(QT_LRELEASE "${Qt${QT_VERSION_MAJOR}_LRELEASE_EXECUTABLE}")
endif()

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

# # 获取 translations 目录下的所有 .ts 文件
# file(GLOB_RECURSE TS_FILES "${ARGN}/*.ts")
# 获取指定目录下的所有 .ts 文件,不包括子目录
file(GLOB TS_FILES "${ARGN}/*.ts")

set(${QMS})
foreach(TSFIL ${TS_FILES})
get_filename_component(FIL_WE ${TSFIL} NAME_WE)
# get_filename_component(TS_DIR ${TSFIL} DIRECTORY)
set(QMFIL ${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.qm)
list(APPEND ${QMS} ${QMFIL})
add_custom_command(
OUTPUT ${QMFIL}
# COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${CMAKE_SOURCE_DIR} -ts ${TSFIL}
COMMAND ${QT_LRELEASE} ${TSFIL} -qm ${QMFIL}
DEPENDS ${TSFIL}
COMMENT "Running ${QT_LRELEASE} on ${TSFIL}"
VERBATIM
)
endforeach()

set_source_files_properties(${${QMS}} PROPERTIES GENERATED TRUE)
set(${QMS} ${${QMS}} PARENT_SCOPE)
endfunction()
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
deepin-deb-installer (6.5.4) unstable; urgency=medium

* feat: Enable support Qt6 build.

-- re2zero <[email protected]> Fri, 3 Jan 2025 16:27:05 +0800

deepin-deb-installer (6.5.3) unstable; urgency=medium

* fix: assume yes in immutable install(Bug: 291783)(Influence: immutable)
Expand Down
21 changes: 18 additions & 3 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,30 @@ Source: deepin-deb-installer
Section: utils
Priority: optional
Maintainer: Deepin Packages Builder <[email protected]>
Build-Depends: debhelper (>= 9), pkg-config, cmake, libqt5widgets5, libqt5concurrent5, libqapt-dev, libdtkwidget-dev, qtbase5-dev, qttools5-dev-tools, qttools5-dev, qtchooser, libgtest-dev, deepin-gettext-tools, libpolkit-qt5-1-dev
Build-Depends:
debhelper (>= 9),
pkg-config,
cmake,
qt6-5compat-dev | hello,
qt6-base-dev | qtbase5-dev,
qt6-tools-dev-tools | qttools5-dev-tools,
qt6-tools-dev | qttools5-dev,
qt6-svg-dev | libqt5svg5-dev,
libdtk6widget-dev | libdtkwidget-dev,
libdtk6gui-dev | libdtkgui-dev,
libdtk6core-dev | libdtkcore-dev,
libqapt-qt6-dev | libqapt-dev,
libpolkit-qt6-1-dev | libpolkit-qt5-1-dev,
libgtest-dev,
deepin-gettext-tools,
Standards-Version: 4.3.0
Homepage: https://www.deepin.com/

Package: deepin-deb-installer
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends},
libqapt3-runtime,
libqapt3,
libqapt3-qt6-runtime | libqapt-runtime,
libqapt3-qt6 | libqapt3,
# deepin-app-store-runtime is available in the community edition.
deepin-elf-verify | deepin-app-store-runtime,
deepin-elf-sign-tool | deepin-app-store-runtime
Expand Down
28 changes: 23 additions & 5 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,31 @@ export QT_SELECT := 5
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
include /usr/share/dpkg/default.mk

override_dh_auto_configure:
dh_auto_configure -- \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SAFETYTEST_ARG="CMAKE_SAFETYTEST_ARG_OFF" \
-DAPP_VERSION=$(DEB_VERSION_UPSTREAM) -DVERSION=$(DEB_VERSION_UPSTREAM) LIB_INSTALL_DIR=/usr/lib/$(DEB_HOST_MULTIARCH)
# 检测当前安装的Qt版本,优先使用Qt6,否则使用Qt5
define detect_qt_version
ifneq (,$(shell which qmake6 2>/dev/null))
QT_DIR="/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/Qt6"
else
QT_DIR="/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/Qt5"
endif
endef

# 调用检测Qt版本的命令
$(eval $(call detect_qt_version))

# hardcode this if want to force build with sepecific Qt version
# QT_DIR="/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/Qt5"

%:
dh $@ --parallel

override_dh_auto_configure:
dh_auto_configure -- \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SAFETYTEST_ARG="CMAKE_SAFETYTEST_ARG_OFF" \
-DAPP_VERSION=$(DEB_VERSION_UPSTREAM) \
-DVERSION=$(DEB_VERSION_UPSTREAM) \
-DQT_DIR=$(QT_DIR)

override_dh_shlibdeps:
dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
30 changes: 21 additions & 9 deletions src/AptInstallDepend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ endif()

project(AptInstallDepend)
set(EXE_NAME deepin-deb-installer-dependsInstall)
set(LINK_LIBS
Qt5::Core
)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
Expand All @@ -38,14 +36,28 @@ add_executable(${EXE_NAME}
)

# Find the library
find_package(Qt5 REQUIRED Core Gui Widgets)
set(qt_required_components Core Gui Widgets)

if (QT_DESIRED_VERSION MATCHES 6)
list(APPEND qt_required_components Core5Compat)
endif()
find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS ${qt_required_components})

set(LINK_LIBS
Qt${QT_DESIRED_VERSION}::Core
Qt${QT_DESIRED_VERSION}::Gui
Qt${QT_DESIRED_VERSION}::Widgets
)

if (QT_DESIRED_VERSION MATCHES 6)
list(APPEND LINK_LIBS Qt${QT_DESIRED_VERSION}::Core5Compat)
endif()

set(CMAKE_INSTALL_PREFIX /usr)

# Install files
install(TARGETS ${EXE_NAME} DESTINATION bin)
target_link_libraries(${EXE_NAME} ${LINK_LIBS})
target_link_libraries(${EXE_NAME}
Qt5::Core
Qt5::Gui
Qt5::Widgets
)
PUBLIC
${LINK_LIBS}
)
119 changes: 64 additions & 55 deletions src/deb-installer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,45 @@ if(NOT DEFINED VERSION)
set(VERSION 5.3.9)
endif()

# 检查qapt版本
execute_process(COMMAND dpkg -s libqapt-dev
COMMAND grep Version
TIMEOUT 5
OUTPUT_VARIABLE QAPT_VERSION_STR)
string(REPLACE "Version: " "" QAPT_VERSION_STR ${QAPT_VERSION_STR})
message(STATUS "BUILD QAPT VERSION ${QAPT_VERSION_STR}")

if(${QAPT_VERSION_STR} VERSION_LESS "3.0.5-1")
if(${QAPT_VERSION_STR} VERSION_LESS "3.0.4.8-1+deepin2")
message(STATUS "disable virtual package enhance")
else()
message(STATUS "enable virtual package enhance")
add_definitions(-DENABLE_VIRTUAL_PACKAGE_ENHANCE)
endif()
if (QT_DESIRED_VERSION MATCHES 6)
# Qt6支持的qapt已基于3.0.5.2-1-deepin3版本变为libqapt-qt6-dev
# execute_process(COMMAND dpkg -s libqapt-qt6-dev
# COMMAND grep Version
# TIMEOUT 5
# OUTPUT_VARIABLE QAPT_VERSION_STR)
# string(REPLACE "Version: " "" QAPT_VERSION_STR ${QAPT_VERSION_STR})
message(STATUS "enable virtual package enhance")
add_definitions(-DENABLE_VIRTUAL_PACKAGE_ENHANCE)
else()
# 部分包名后可能添加后缀,后续更新的deepin分支libqapt包应包含虚包处理
if(${QAPT_VERSION_STR} VERSION_GREATER_EQUAL "3.0.5.1-1-deepin1" AND ${QAPT_VERSION_STR} MATCHES ".*deepin.*")
message(STATUS "enable virtual package enhance")
add_definitions(-DENABLE_VIRTUAL_PACKAGE_ENHANCE)
# 检查qapt版本
execute_process(COMMAND dpkg -s libqapt-dev
COMMAND grep Version
TIMEOUT 5
OUTPUT_VARIABLE QAPT_VERSION_STR)
string(REPLACE "Version: " "" QAPT_VERSION_STR ${QAPT_VERSION_STR})
message(STATUS "BUILD QAPT VERSION ${QAPT_VERSION_STR}")

if(${QAPT_VERSION_STR} VERSION_LESS "3.0.5-1")
if(${QAPT_VERSION_STR} VERSION_LESS "3.0.4.8-1+deepin2")
message(STATUS "disable virtual package enhance")
else()
message(STATUS "enable virtual package enhance")
add_definitions(-DENABLE_VIRTUAL_PACKAGE_ENHANCE)
endif()
else()
message(STATUS "disable virtual package enhance")
# 部分包名后可能添加后缀,后续更新的deepin分支libqapt包应包含虚包处理
if(${QAPT_VERSION_STR} VERSION_GREATER_EQUAL "3.0.5.1-1-deepin1" AND ${QAPT_VERSION_STR} MATCHES ".*deepin.*")
message(STATUS "enable virtual package enhance")
add_definitions(-DENABLE_VIRTUAL_PACKAGE_ENHANCE)
else()
message(STATUS "disable virtual package enhance")
endif()
endif()
endif()

# common resource names
set(APP_RES_DIR "${CMAKE_SOURCE_DIR}/assets")
set(APP_BIN_NAME "deepin-deb-installer")
set(APP_TRANS_SCRIPT "${APP_RES_DIR}/translate_generation.sh")
set(APP_DESKTOP "${APP_RES_DIR}/deepin-deb-installer.desktop")
set(APP_MIME "${APP_RES_DIR}/deepin-deb-installer.xml")
set(APP_QRC "${APP_RES_DIR}/resources.qrc")
Expand Down Expand Up @@ -104,38 +114,39 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -O2 -Wl,-O1 -Wl,--gc-sections")
endif()

# Generate the qm file
execute_process(COMMAND bash ${APP_TRANS_SCRIPT}
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/")

configure_file(${APP_RES_DIR}/environments.h.in environments.h @ONLY)

add_definitions(-DUSE_POLKIT -DENABLE_INACTIVE_DISPLAY)

# Find the library
find_package(PkgConfig REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5LinguistTools REQUIRED)
find_package(Qt5Concurrent REQUIRED)
find_package(DtkWidget REQUIRED)
find_package(DtkGui REQUIRED)
find_package(DtkCore REQUIRED)
find_package(Qt5DBus REQUIRED)
find_package(PolkitQt5-1 REQUIRED)

find_package(PolkitQt${QT_DESIRED_VERSION}-1)
set(qt_required_components Core DBus Gui Widgets Concurrent)

if (QT_DESIRED_VERSION MATCHES 6)
list(APPEND qt_required_components Core5Compat)
endif()

find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS ${qt_required_components})
find_package(Dtk${DTK_VERSION_MAJOR} COMPONENTS Core Gui Widget REQUIRED)

set(LINK_LIBS
Qt5::Core
Qt5::Widgets
Qt5::Gui
Qt5::DBus
QApt
Qt5::Concurrent
${DtkWidget_LIBRARIES}
${DtkCore_LIBRARIES}
${DtkGUI_LIBRARIES}
Qt${QT_DESIRED_VERSION}::Core
Qt${QT_DESIRED_VERSION}::DBus
Qt${QT_DESIRED_VERSION}::Gui
Qt${QT_DESIRED_VERSION}::Widgets
Qt${QT_DESIRED_VERSION}::Concurrent
Dtk${DTK_VERSION_MAJOR}::Widget
Dtk${DTK_VERSION_MAJOR}::Core
Dtk${DTK_VERSION_MAJOR}::Gui
PolkitQt${QT_DESIRED_VERSION}-1::Agent
)

if (QT_DESIRED_VERSION MATCHES 6)
list(APPEND LINK_LIBS Qt${QT_DESIRED_VERSION}::Core5Compat)
endif()

macro(SUBDIRLIST result curdir)
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
set(dirlist "")
Expand Down Expand Up @@ -164,28 +175,26 @@ file(GLOB_RECURSE APP_SRCS
${CMAKE_CURRENT_LIST_DIR}/*.cpp
)

include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})

# Tell CMake to create the executable
add_executable(${PROJECT_NAME} ${APP_SRCS} ${APP_QRC})

target_include_directories(${APP_BIN_NAME}
PUBLIC ${DtkWidget_INCLUDE_DIRS} ${OBJECT_BINARY_DIR})

target_link_libraries(${APP_BIN_NAME}
Qt5::Core
Qt5::Widgets
Qt5::Gui
Qt5::DBus
${LINK_LIBS}
QApt
Qt5::Concurrent
PolkitQt5-1::Agent
${DtkWidget_LIBRARIES}
${DtkCore_LIBRARIES}
${DtkGUI_LIBRARIES}
)
set(CMAKE_INSTALL_PREFIX /usr)

# translation files
TRANSLATION_GENERATE(QM_FILES ${CMAKE_SOURCE_DIR}/translations)
add_custom_target(${PROJECT_NAME}_qm_files DEPENDS ${QM_FILES})
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_qm_files)

# Install translations
install(FILES ${QM_FILES} DESTINATION share/${PROJECT_NAME}/translations)

# Install files
install(DIRECTORY ${APP_RES_DIR}/deepin-deb-installer DESTINATION /usr/share/deepin-manual/manual-assets/application/)
install(TARGETS deepin-deb-installer RUNTIME DESTINATION bin)
Expand Down
1 change: 1 addition & 0 deletions src/deb-installer/compatible/compatible_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define COMPATIBLEBACKEND_H

#include <QObject>
#include <QHash>

#include "compatible_defines.h"

Expand Down
Loading

0 comments on commit e7d9048

Please sign in to comment.