Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 73 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,25 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 包含 GNUInstallDirs,用于获取标准安装路径
include(GNUInstallDirs)

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

if (QT_VERSION_MAJOR MATCHES 6)
set(DTK_VERSION_MAJOR 6)
else()
set(DTK_VERSION_MAJOR "")
endif()

# 查找必要的包
find_package(Qt6 COMPONENTS Core Gui Widgets Concurrent Network DBus LinguistTools REQUIRED)
find_package(Dtk6 COMPONENTS Widget Gui REQUIRED)
find_package(udisks2-qt6 REQUIRED)
set(QT_COMPONENTS Core Gui Widgets Concurrent Network DBus LinguistTools)
if (QT_VERSION_MAJOR MATCHES 5)
list(APPEND QT_COMPONENTS X11Extras)
endif()
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${QT_COMPONENTS} REQUIRED)
find_package(Dtk${DTK_VERSION_MAJOR} COMPONENTS Widget Gui REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(UDISKS2QT REQUIRED IMPORTED_TARGET udisks2-qt${QT_VERSION_MAJOR})
pkg_check_modules(PKGS REQUIRED
x11
)
Expand Down Expand Up @@ -52,20 +66,39 @@ set(HEADERS
# 设置翻译文件
file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/translations/${PROJECT_NAME}*.ts")

# 使用 Qt 提供的翻译工具
qt_add_translations(${PROJECT_NAME}
# 指定翻译源文件
TS_FILES ${TS_FILES}
# 指定 QM 文件输出变量
QM_FILES_OUTPUT_VARIABLE QM_FILES
# 指定源文件,用于更新翻译
SOURCES ${SOURCES} ${HEADERS}
# 指定 LRELEASE 选项
LRELEASE_OPTIONS
-compress
-nounfinished
-removeidentical
)
# 根据 Qt 版本使用不同的翻译工具
if (QT_VERSION_MAJOR MATCHES 6)
# Qt6 使用 qt_add_translations
qt_add_translations(${PROJECT_NAME}
# 指定翻译源文件
TS_FILES ${TS_FILES}
# 指定 QM 文件输出变量
QM_FILES_OUTPUT_VARIABLE QM_FILES
# 指定源文件,用于更新翻译
SOURCES ${SOURCES} ${HEADERS}
# 指定 LRELEASE 选项
LRELEASE_OPTIONS
-compress
-nounfinished
-removeidentical
)
else()
# Qt5 手动生成 QM 文件
find_program(QT_LRELEASE_EXECUTABLE NAMES lrelease-qt5 lrelease)
set(QM_FILES)
foreach(TS_FILE ${TS_FILES})
get_filename_component(TS_FILE_NAME ${TS_FILE} NAME_WE)
set(QM_FILE "${CMAKE_CURRENT_BINARY_DIR}/${TS_FILE_NAME}.qm")
add_custom_command(
OUTPUT ${QM_FILE}
COMMAND ${QT_LRELEASE_EXECUTABLE} -compress -nounfinished -removeidentical ${TS_FILE} -qm ${QM_FILE}
DEPENDS ${TS_FILE}
COMMENT "Generating ${QM_FILE} from ${TS_FILE}"
)
list(APPEND QM_FILES ${QM_FILE})
endforeach()
add_custom_target(translations ALL DEPENDS ${QM_FILES})
endif()

# 在文件开头部分添加自动 moc 处理
set(CMAKE_AUTOMOC ON)
Expand All @@ -79,45 +112,53 @@ add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${PKGS_INCLUDE_DIRS}
${UDISKS2QT_INCLUDE_DIRS}
)

# 链接库
target_link_libraries(${PROJECT_NAME} PRIVATE
Qt6::Core
Qt6::Gui
Qt6::GuiPrivate
Qt6::Widgets
Qt6::Concurrent
Qt6::Network
Qt6::DBus
Dtk6::Widget
Dtk6::Gui
udisks2-qt6::udisks2-qt6
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::GuiPrivate
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Concurrent
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::DBus
Dtk${DTK_VERSION_MAJOR}::Widget
Dtk${DTK_VERSION_MAJOR}::Gui
PkgConfig::UDISKS2QT
${PKGS_LIBRARIES}
)

# Qt5 需要链接 X11Extras
if (QT_VERSION_MAJOR MATCHES 5)
target_link_libraries(${PROJECT_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::X11Extras
)
endif()

# 添加编译选项
target_compile_options(${PROJECT_NAME} PRIVATE ${PKGS_CFLAGS_OTHER})

# 设置翻译文件路径
set(TRANSLATIONS_INSTALL_DIR "${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/translations")

# 添加编译定义,传递安装路径到代码中
target_compile_definitions(${PROJECT_NAME} PRIVATE
target_compile_definitions(${PROJECT_NAME} PRIVATE
"TRANSLATIONS_DIR=\"${TRANSLATIONS_INSTALL_DIR}\""
)

# 安装目标
install(TARGETS ${PROJECT_NAME}
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

# 安装翻译文件
install(FILES ${QM_FILES}
install(FILES ${QM_FILES}
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/translations
)

# 安装桌面文件
install(FILES dde-device-formatter.desktop
install(FILES dde-device-formatter.desktop
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications
)
)
18 changes: 9 additions & 9 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Priority: optional
Maintainer: Deepin Packages Builder <packages@linuxdeepin.com>
Build-Depends: cmake,
debhelper (>=9),
qt6-base-dev,
qt6-declarative-dev,
qt6-tools-dev,
qt6-tools-dev-tools,
qt6-base-private-dev,
libdtk6widget-dev,
libdtk6gui-dev,
libdtk6core-dev,
libudisks2-qt6-dev
qt6-base-dev | qtbase5-dev,
qt6-declarative-dev | qtdeclarative5-dev,
qt6-tools-dev | qttools5-dev,
qt6-tools-dev-tools | qttools5-dev-tools,
qt6-base-private-dev | qtbase5-private-dev,
libdtk6widget-dev | libdtkwidget-dev,
libdtk6gui-dev | libdtkgui-dev,
libdtk6core-dev | libdtkcore-dev,
libudisks2-qt6-dev | libudisks2-qt5-dev
Standards-Version: 3.9.8
Homepage: http://www.deepin.org

Expand Down
14 changes: 11 additions & 3 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#!/usr/bin/make -f

export QT_SELECT=5
include /usr/share/dpkg/default.mk

DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)

# 检测当前安装的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

export DEB_LDFLAGS_APPEND = -Wl,-z,now

%:
dh $@ --parallel

override_dh_auto_configure:
dh_auto_configure -- VERSION=$(VERSION) LIB_INSTALL_DIR=/usr/lib/$(DEB_HOST_MULTIARCH) DEFINES+="VERSION=$(DEB_VERSION_UPSTREAM)"
dh_auto_configure -- VERSION=$(VERSION) LIB_INSTALL_DIR=/usr/lib/$(DEB_HOST_MULTIARCH) DEFINES+="VERSION=$(DEB_VERSION_UPSTREAM)" QT_DIR=$(QT_DIR)
8 changes: 6 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
#include "app/singletonapp.h"
#include "utils/udisksutils.h"
#include <QProcessEnvironment>
#include <X11/Xlib.h>

Check warning on line 20 in main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <X11/Xlib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QGuiApplication>

Check warning on line 21 in main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QGuiApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QScreen>

Check warning on line 22 in main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QScreen> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QtGui/private/qtx11extras_p.h>
#else
#include <QX11Info>

Check warning on line 26 in main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QX11Info> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#endif

DCORE_USE_NAMESPACE

Expand All @@ -29,7 +33,7 @@
int main(int argc, char *argv[])
{
qDebug() << "Main: Starting dde-device-formatter application";

// 设置Deepin平台主题
if (qgetenv("QT_QPA_PLATFORMTHEME").isEmpty()) {
qputenv("QT_QPA_PLATFORMTHEME", "deepin");
Expand Down Expand Up @@ -131,7 +135,7 @@
}

int code = a.exec();

qDebug() << "Main: Performing quick exit";
quick_exit(code);
}