Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adapt for Qt 6.8 #116

Merged
merged 1 commit into from
Dec 26, 2024
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
51 changes: 46 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
# 定义需要的cmake版本
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.16.0)

# 设置cmake参数
set(CMAKE_CXX_STANDARD 14)
# 设置工程名字
project(deepin-draw)

# 设置CMake参数
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wl,--as-needed -fPIE")
set(QT_MINIMUM_VERSION "6.0.0")
set(CMAKE_EXE_LINKER_FLAGS "-pie")

# 设置工程名字
project(deepin-draw)
# 查找Qt库
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core Widgets Gui DBus Xml Svg Test)
message("Using Qt version: ${QT_VERSION_MAJOR}")

# 选择DTK版本
if(QT_VERSION_MAJOR EQUAL "6")
set(BUILD_WITH_QT6 ON)
set(DTK_VERSION_MAJOR 6)
else()
set(DTK_VERSION_MAJOR "")
endif()
message("Using dtk version: ${DTK_VERSION_MAJOR}")

# 查找DTK库
find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Widget Gui Core)

# 包含目录
include_directories(${DtkWidget_INCLUDE_DIRS} ${DtkGui_INCLUDE_DIRS} ${DtkCore_INCLUDE_DIRS})

# 是否开启单元测试编译
option(DEEPINDRAW_TEST "only compile and generate deepin-draw-test program." OFF)
Expand Down Expand Up @@ -62,3 +84,22 @@ if(DEEPINDRAW_LOAD_TOOL_PLUGINS AND NOT DEEPINDRAW_LINK_DRAWBASELIB_STATIC)
add_subdirectory(deepin-draw-plugins)
endif()

# 设置链接库
set(LINK_LIBS
Qt6::Core
Qt6::DBus
Qt6::Widgets
Qt6::Xml
Qt6::Svg
Qt6::Test
Qt6::SvgWidgets
Dtk${DTK_VERSION_MAJOR}::Widget
Dtk${DTK_VERSION_MAJOR}::Gui
Dtk${DTK_VERSION_MAJOR}::Core
${DFrameworkDBus_LIBRARIES}
)

# 安装目标
install(TARGETS deepin-draw DESTINATION ${CMAKE_INSTALL_BINDIR})
file(GLOB QM_FILES "${CMAKE_CURRENT_LIST_DIR}/translations/*.qm")

21 changes: 11 additions & 10 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@ Maintainer: Deepin Packages Builder <[email protected]>
Build-Depends:
debhelper,
cmake,
qtbase5-dev,
qt6-base-dev,
pkg-config,
libexif-dev,
libqt5svg5-dev,
libraw-dev,
libfreeimage-dev,
libqt5opengl5-dev,
libdtkgui-dev,
qttools5-dev,
qttools5-dev-tools,
libdtkwidget-dev,
libqt6opengl6,
libdtk6gui-dev,
qt6-svg-dev,
qt6-tools-dev,
qt6-tools-dev-tools,
libdtk6widget-dev,
libdtk6gui-dev,
libdtk6core-dev,
libxcb-util0-dev,
libdtkcore5-bin,
libdtk6core-bin,
libgtest-dev,
libgmock-dev
Standards-Version: 3.9.8
Homepage: http://www.deepin.org

Package: deepin-draw
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, qt5-image-formats-plugins, deepin-picker-cli
Depends: ${shlibs:Depends}, ${misc:Depends}, qt6-image-formats-plugins, deepin-picker-cli
Description: Draw for UOS
Draw is a lightweight drawing tool for users to freely draw and simply edit images.
Recommends: uos-reporter, deepin-event-log, kimageformat-plugins
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/make -f
include /usr/share/dpkg/default.mk
export QT_SELECT=5
export QT_SELECT=qt6
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

%:
Expand Down
124 changes: 91 additions & 33 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
# 定义需要的cmake版本
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.16)

# 设置基础库名称为 "deepinDrawBase",并将其存储在缓存中
SET(BASE_LIB "deepinDrawBase" CACHE STRING INTERNAL FORCE)

# 设置cmake参数
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

#set complier/link flags
set(CMAKE_CXX_STANDARD 17) # 设置C++标准为C++14
set(CMAKE_INCLUDE_CURRENT_DIR ON) # 包含当前目录
set(CMAKE_AUTOMOC ON) # 自动处理moc文件
set(CMAKE_AUTORCC ON) # 自动处理rcc文件
set(CMAKE_AUTOUIC ON) # 自动处理uic文件
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wl,--as-needed -fPIE") # 设置C++编译标志,启用调试信息和警告
set(QT_MINIMUM_VERSION "6.0.0") # 定义Qt的最低版本为6.0.0
set(CMAKE_EXE_LINKER_FLAGS "-pie") # 设置可执行文件的链接标志

# 设置编译器/链接器标志
if(DEEPINDRAW_TEST)
message(DEEPINDRAW_TESTDEEPINDRAW_TESTDEEPINDRAW_TESTDEEPINDRAW_TEST)
#0.DEEPINDRAW_TEST mean that we should creat the lib that can get cover info
#mips not suport -fsanitize
# 如果定义了DEEPINDRAW_TEST,表示需要创建可以获取覆盖信息的库
# mips不支持-fsanitize
if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "mips64")
set(CMAKE_CXX_FLAGS "-g -O1 -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "-g -O1 -fprofile-arcs -ftest-coverage")
Expand All @@ -26,13 +30,13 @@ if(DEEPINDRAW_TEST)
set(CMAKE_L_FLAGS "-fsanitize=undefined,address,leak -fno-omit-frame-pointer -g -O1 -fprofile-arcs -ftest-coverage -lgcov")
endif()
else()
#1.no DEEPINDRAW_TEST mean that we just need one clearly lib(not include -ftest-coverage or -fsanitize)
# 如果没有定义DEEPINDRAW_TEST,表示只需要一个不包含-fsanitize或-ftest-coverage的清晰库
if(CMAKE_BUILD_TYPE MATCHES "Debug")
#DEBUG时不做优化方便调试
# 在DEBUG模式下不进行优化以方便调试
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
else()
#加速编译优化参数
# 加速编译优化参数
if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "mips64")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wl,-O1 -Wl,--as-needed -Wl,-E -fPIE -ffunction-sections -fdata-sections -Wl,--gc-sections -ftree-vectorize -march=loongson3a -mhard-float -mno-micromips -mno-mips16 -flax-vector-conversions -mloongson-ext2 -mloongson-mmi")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wl,-O1 -Wl,--as-needed -Wl,-E -fPIE -ffunction-sections -fdata-sections -Wl,--gc-sections -ftree-vectorize -march=loongson3a -mhard-float -mno-micromips -mno-mips16 -flax-vector-conversions -mloongson-ext2 -mloongson-mmi")
Expand All @@ -44,21 +48,35 @@ else()
endif()
endif()

#2.sometime we also want to test deepin-draw memery info
# 有时我们也想测试deepin-draw的内存信息
if(DEEPINDRAW_SANITIZERS)
set(CMAKE_CXX_FLAGS "-fsanitize=undefined,address,leak -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS "-fsanitize=undefined,address,leak -fno-omit-frame-pointer")
endif()
endif()

# 设置Qt模块
set(QtModule Core Gui Widgets DBus PrintSupport Svg Concurrent LinguistTools)
if(QT_VERSION_MAJOR EQUAL 6)
set(QtModule Core Gui Widgets DBus PrintSupport Svg SvgWidgets Concurrent LinguistTools)
find_package(Qt6 REQUIRED COMPONENTS ${QtModule})
else()
set(QtModule Core Gui Widgets DBus PrintSupport Svg Concurrent LinguistTools)
find_package(Qt5 REQUIRED COMPONENTS ${QtModule})
endif()

# 查找Qt相关的库链接
find_package(Qt5 REQUIRED ${QtModule})
#选择DTK版本
if(QT_VERSION_MAJOR EQUAL "6") # 如果Qt版本为6
set(BUILD_WITH_QT6 ON) # 启用Qt6构建
set(DTK_VERSION_MAJOR 6) # 设置DTK版本为6
else()
set(DTK_VERSION_MAJOR "") # 否则不设置DTK版本
endif()
message("Testing Using dtk version: ${DTK_VERSION_MAJOR}") # 输出使用的DTK版本

# 配置文件,将config.h.in转换为config.h
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../config.h.in ${PROJECT_BINARY_DIR}/config.h @ONLY)

# 定义源码目录
set(SRCDIRS
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/drawshape
Expand Down Expand Up @@ -87,51 +105,90 @@ FILE (GLOB allSource ${SRC_CPPS})
FILE (GLOB allHeaders ${SRC_HEADERS})
FILE (GLOB allQrcs ${SRC_QRCS})

# 查找翻译文件
FILE(GLOB targetTsFiles ../translations/*.ts)

# 创建翻译文件(将源文件${allSource} ${allHeaders}关联上${targetTsFiles}的ts文件 然后生成${tragetQmFiles}的qm文件)
qt5_create_translation(tragetQmFiles ${allSource} ${allHeaders} ${targetTsFiles})
#qt5_create_translation(tragetQmFiles ${allSource} ${allHeaders} ${targetTsFiles} OPTIONS -no-obsolete)
# 创建翻译文件,将源文件与ts文件关联生成qm文件
if(QT_VERSION_MAJOR EQUAL 6)
qt6_create_translation(tragetQmFiles ${allSource} ${allHeaders} ${targetTsFiles})
else()
qt5_create_translation(tragetQmFiles ${allSource} ${allHeaders} ${targetTsFiles})
endif()

# 设置不删除生成的文件夹内容文件(设置此项是为了翻译后的文件不被删除)
set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM 1)

qt5_add_resources(RESOURCE_ADDED ${allQrcs})
# 添加资源文件
if(QT_VERSION_MAJOR EQUAL 6)
qt6_add_resources(RESOURCE_ADDED ${allQrcs})
else()
qt5_add_resources(RESOURCE_ADDED ${allQrcs})
endif()

# 根据条件选择创建静态库或共享库
if(DEEPINDRAW_LINK_DRAWBASELIB_STATIC)
add_library(${BASE_LIB} STATIC ${allSource} ${allHeaders} ${RESOURCE_ADDED} ${tragetQmFiles})
else()
add_library(${BASE_LIB} SHARED ${allSource} ${allHeaders} ${RESOURCE_ADDED} ${tragetQmFiles})
endif()

# 设置目标属性
set_target_properties(${BASE_LIB}
PROPERTIES
VERSION 0.0
SOVERSION 0
PUBLIC_HEADER "${allHeaders}")

# Find includes in corresponding build directories
# 在相应的构建目录中查找包含文件
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories(${PROJECT_BINARY_DIR})
include_directories(${PROJECT_SOURCE_DIR})

#------------------------------ 添加第三方库 DTK -------------------------------
# 添加第三方库 DTK
# 使用第三方库需要用到的一个包
find_package(PkgConfig REQUIRED)

# 检查第三方库(这里检查了名字为dtkwidget的库和名字为dtkgui的库),然后取名3RMODULES
pkg_check_modules(3RMODULES REQUIRED
dtkwidget dtkgui dtkcore
dtk6widget dtk6gui dtk6core
)

# 添加调试信息
message(STATUS "DTK Widget Include Dirs: ${3RMODULES_INCLUDE_DIRS}")
message(STATUS "DTK Libraries: ${3RMODULES_LIBRARIES}")
message(STATUS "DTK Library Dirs: ${3RMODULES_LIBRARY_DIRS}")

# 添加第三方库的所有文件夹路径到工程中来(注意 *_INCLUDE_DIRS)
target_include_directories(${BASE_LIB} PUBLIC ${3RMODULES_INCLUDE_DIRS})
target_link_libraries(${BASE_LIB} ${3RMODULES_LIBRARIES} ${CMAKE_DL_LIBS})

#------------------------------添加第三方库end-------------------------------------

# 将工程与Qt模块链接起来
qt5_use_modules(${BASE_LIB} ${QtModule})

# ------------------------------- install script -------------------------------
# if(QT_MAJOR_VERSION EQUAL 6)
# foreach(module ${QtModule})
# target_link_libraries(${BASE_LIB} Qt6::${module})
# endforeach()
# message(STATUS "QtModule contents qt6: ${QtModule}")
# else()
# qt5_use_modules(${BASE_LIB} ${QtModule})
# message(STATUS "QtModule contents qt5: ${QtModule}")
# endif()
# 设置链接库
set(LINK_LIBS
Qt6::Core
Qt6::DBus
Qt6::Widgets
Qt6::PrintSupport
Qt6::Svg
Qt6::Concurrent
Dtk6::Widget
Dtk6::Gui
Dtk6::Core
)

# 替换原来的 if-else 链接逻辑
target_link_libraries(${BASE_LIB} ${LINK_LIBS})

# 安装脚本
set(DbusDir ${CMAKE_INSTALL_DATADIR}/dbus-1/services/)
set(DesktopDir ${CMAKE_INSTALL_DATADIR}/applications/)
set(ManIconDir ${CMAKE_INSTALL_DATADIR}/icons/deepin/apps/scalable)
Expand All @@ -140,21 +197,22 @@ set(MimeFileDir ${CMAKE_INSTALL_DATADIR}/mime/packages)
set(MimeTypeDir ${CMAKE_INSTALL_DATADIR}/application)
set(HelpFileDir ${CMAKE_INSTALL_DATADIR}/deepin-manual/manual-assets/application)

# 如果不是静态链接库,安装库文件
if(NOT DEEPINDRAW_LINK_DRAWBASELIB_STATIC)
install(TARGETS ${BASE_LIB}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
endif()

# install Translation files:
# 安装翻译文件
install(FILES ${tragetQmFiles} DESTINATION ${TranslationDir})

# install Manual icon
# 安装手册图标
install(FILES ./logo/deepin-draw.svg DESTINATION ${ManIconDir})

# install App icon
# 安装应用图标
install(FILES ./logo/deepin-draw.svg DESTINATION ${AppIconDir})

# 添加子目录
add_subdirectory(deepin-draw)

Loading
Loading