Skip to content

Commit 84adde7

Browse files
committed
refactor: refactor CMake build system for unified DTK5/DTK6 support
1. Replaced BUILD_WITH_QT6 option with DTK5 option for unified DTK5/DTK6 build control 2. Updated project configuration to support both DTK5 (Qt5) and DTK6 (Qt6) versions 3. Modified version handling to use DTK_VERSION (5.y.z or 6.y.z) instead of PROJECT_VERSION 4. Updated library naming: dtklog for DTK5 and dtk6log for DTK6 5. Enhanced Debian packaging to generate separate packages for DTK5 and DTK6 6. Added Build-Profiles support (nodtk5, nodtk6) for selective package building 7. Updated installation paths to include dtk5/ and dtk6/ subdirectories 8. Modified CMake config files to use DTK_NAME_SUFFIX for proper target naming Log: Updated build system to support both DTK5 and DTK6 versions Influence: 1. Test building with DTK5=ON (default) to ensure Qt5 compatibility 2. Test building with DTK5=OFF to ensure Qt6 compatibility 3. Verify library naming: libdtklog.so for DTK5, libdtk6log.so for DTK6 4. Check installation paths: include/dtk5/ for DTK5, include/dtk6/ for DTK6 5. Test Debian package building with different profiles (nodtk5, nodtk6) 6. Verify CMake config files generate correct target names (DtkLog vs Dtk6Log) 7. Ensure pkg-config files have correct dependencies (Qt5Core vs Qt6Core) refactor: 重构CMake构建系统以支持统一的DTK5/DTK6构建 1. 将BUILD_WITH_QT6选项替换为DTK5选项,用于统一的DTK5/DTK6构建控制 2. 更新项目配置以同时支持DTK5(Qt5)和DTK6(Qt6)版本 3. 修改版本处理逻辑,使用DTK_VERSION(5.y.z或6.y.z)替代PROJECT_VERSION 4. 更新库命名:DTK5使用dtklog,DTK6使用dtk6log 5. 增强Debian打包系统,为DTK5和DTK6生成独立的软件包 6. 添加Build-Profiles支持(nodtk5, nodtk6)用于选择性构建软件包 7. 更新安装路径,包含dtk5/和dtk6/子目录 8. 修改CMake配置文件以使用DTK_NAME_SUFFIX进行正确的目标命名 Log: 更新构建系统以同时支持DTK5和DTK6版本 Influence: 1. 测试使用DTK5=ON(默认)构建,确保Qt5兼容性 2. 测试使用DTK5=OFF构建,确保Qt6兼容性 3. 验证库命名:DTK5使用libdtklog.so,DTK6使用libdtk6log.so 4. 检查安装路径:DTK5使用include/dtk5/,DTK6使用include/dtk6/ 5. 测试使用不同配置文件(nodtk5, nodtk6)构建Debian软件包 6. 验证CMake配置文件生成正确的目标名称(DtkLog vs Dtk6Log) 7. 确保pkg-config文件具有正确的依赖关系(Qt5Core vs Qt6Core)
1 parent 322b0c1 commit 84adde7

10 files changed

Lines changed: 140 additions & 56 deletions

CMakeLists.txt

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,39 @@ SET(CMAKE_CXX_STANDARD 11)
44
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
55
SET(CMAKE_AUTOMOC ON)
66

7-
FILE (READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" DTK_FILE_VERSION)
8-
STRING (STRIP "${DTK_FILE_VERSION}" DTK_FILE_VERSION)
9-
SET (DLOG_VERSION "${DTK_FILE_VERSION}" CACHE STRING "define project version")
10-
SET (BUILD_WITH_SYSTEMD OFF CACHE BOOL "Build with systemd")
11-
SET (BUILD_WITH_QT6 OFF CACHE BOOL "Build with Qt6")
12-
13-
IF(BUILD_WITH_QT6)
14-
SET(QT_VERSION_MAJOR "6")
15-
SET(DTK_VERSION_MAJOR "6")
16-
ELSE()
17-
SET(QT_VERSION_MAJOR "5")
18-
ENDIF()
7+
FILE (READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" FILE_VERSION)
8+
STRING (STRIP "${FILE_VERSION}" FILE_VERSION)
199

20-
SET (DLog "Dtk${DTK_VERSION_MAJOR}Log")
21-
PROJECT(${DLog}
22-
VERSION ${DLOG_VERSION}
10+
PROJECT(DtkLog
11+
VERSION ${FILE_VERSION}
2312
DESCRIPTION "Simple, convinient and thread safe logger for Qt-based C++ apps"
13+
HOMEPAGE_URL "https://github.com/linuxdeepin/dtklog"
2414
LANGUAGES CXX
2515
)
2616

17+
SET (BUILD_WITH_SYSTEMD OFF CACHE BOOL "Build with systemd")
18+
19+
# 引入 DTK5/DTK6 构建选项
20+
option(DTK5 "Build DTK5." ON)
21+
if(DTK5)
22+
set(DTK_VERSION_MAJOR "5")
23+
set(DTK_NAME_SUFFIX "") # DTK5 产品名称后缀为空
24+
else()
25+
set(DTK_VERSION_MAJOR "6")
26+
set(DTK_NAME_SUFFIX "6") # DTK6 产品名称后缀为 "6"
27+
endif()
28+
29+
set(DTK_VERSION_MINOR ${PROJECT_VERSION_MINOR})
30+
set(DTK_VERSION_PATCH ${PROJECT_VERSION_PATCH})
31+
set(DTK_VERSION "${DTK_VERSION_MAJOR}.${DTK_VERSION_MINOR}.${DTK_VERSION_PATCH}")
32+
# 官方约定:DTK5 使用 Qt5,DTK6 使用 Qt6
33+
set(QT_VERSION_MAJOR ${DTK_VERSION_MAJOR})
34+
35+
SET (DLog "Dtk${DTK_NAME_SUFFIX}Log")
36+
2737
INCLUDE(GNUInstallDirs)
2838
INCLUDE(CMakePackageConfigHelpers) # configure_package_config_file
29-
SET (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/dtk${QT_VERSION_MAJOR}/DLog")
39+
SET (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/dtk${DTK_VERSION_MAJOR}/DLog")
3040
SET (LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}")
3141
SET (CONFIG_CMAKE_INSTALL_DIR "${LIBRARY_INSTALL_DIR}/cmake/${DLog}" CACHE STRING "Install dir for cmake config files")
3242
SET (MKSPECS_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/qt${QT_VERSION_MAJOR}/mkspecs/modules" CACHE STRING "Install dir for qt pri files")
@@ -77,7 +87,7 @@ IF(BUILD_WITH_SYSTEMD)
7787
SET(includes ${includes} include/JournalAppender.h)
7888
ENDIF(BUILD_WITH_SYSTEMD)
7989

80-
SET(library_target dtk${DTK_VERSION_MAJOR}log)
90+
SET(library_target dtk${DTK_NAME_SUFFIX}log)
8191

8292
ADD_LIBRARY(${library_target} SHARED ${sources} ${includes})
8393

@@ -92,8 +102,8 @@ TARGET_LINK_DIRECTORIES(${library_target} INTERFACE
92102
)
93103

94104
SET_TARGET_PROPERTIES(${library_target} PROPERTIES
95-
VERSION ${CMAKE_PROJECT_VERSION}
96-
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR}
105+
VERSION ${DTK_VERSION}
106+
SOVERSION ${DTK_VERSION_MAJOR}
97107
EXPORT_NAME Log
98108
)
99109

@@ -142,7 +152,7 @@ CONFIGURE_PACKAGE_CONFIG_FILE(misc/DLogConfig.cmake.in
142152
)
143153
WRITE_BASIC_PACKAGE_VERSION_FILE(
144154
"${CMAKE_CURRENT_BINARY_DIR}/${DLog}ConfigVersion.cmake"
145-
VERSION ${DLOG_VERSION}
155+
VERSION ${DTK_VERSION}
146156
COMPATIBILITY SameMajorVersion
147157
)
148158

debian/control

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,46 @@
11
Source: dtklog
22
Section: libdevel
33
Priority: optional
4-
Maintainer: Deepin Packages Builder <packages@deepin.com>
5-
Build-Depends: debhelper-compat ( =12), pkg-config, qtbase5-private-dev, cmake, libspdlog-dev, libsystemd-dev
4+
Maintainer: Shanshan Ye <yeshanshan@uniontech.com>
5+
Build-Depends: debhelper-compat ( =12),
6+
cmake,
7+
pkg-config,
8+
libspdlog-dev,
9+
libsystemd-dev,
10+
qtbase5-dev <!nodtk5>,
11+
qtbase5-private-dev <!nodtk5>,
12+
qt6-base-dev <!nodtk6>,
13+
qt6-base-private-dev <!nodtk6>
614
Standards-Version: 3.9.8
715

16+
Package: libdtk6log
17+
Architecture: any
18+
Depends: ${shlibs:Depends}, ${misc:Depends}
19+
Multi-Arch: same
20+
Build-Profiles: <!nodtk6>
21+
Description: Simple, convinient and thread safe logger for Qt-based C++ apps (DTK6 with Qt6)
22+
This package contains the shared libraries.
23+
24+
Package: libdtk6log-dev
25+
Architecture: any
26+
Depends: ${shlibs:Depends}, ${misc:Depends},
27+
libdtk6log( =${binary:Version})
28+
Build-Profiles: <!nodtk6>
29+
Description: Simple, convinient and thread safe logger for Qt-based C++ apps (DTK6 with Qt6)
30+
This package contains the header files and static libraries of dlog
31+
832
Package: libdtklog
933
Architecture: any
1034
Depends: ${shlibs:Depends}, ${misc:Depends}
1135
Multi-Arch: same
12-
Description: Simple, convinient and thread safe logger for Qt-based C++ apps.
36+
Build-Profiles: <!nodtk5>
37+
Description: Simple, convinient and thread safe logger for Qt-based C++ apps (DTK5 with Qt5)
1338
This package contains the shared libraries.
1439

1540
Package: libdtklog-dev
1641
Architecture: any
17-
Depends: ${shlibs:Depends}, ${misc:Depends}, libdtklog( =${binary:Version})
18-
Description: Simple, convinient and thread safe logger for Qt-based C++ apps.
42+
Depends: ${shlibs:Depends}, ${misc:Depends},
43+
libdtklog( =${binary:Version})
44+
Build-Profiles: <!nodtk5>
45+
Description: Simple, convinient and thread safe logger for Qt-based C++ apps (DTK5 with Qt5)
1946
This package contains the header files and static libraries of dlog

debian/libdtk6log-dev.install

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
usr/include/dtk6/
2+
usr/lib/*/libdtk6log.so
3+
usr/lib/*/pkgconfig/dtk6log.pc
4+
usr/lib/*/qt6/mkspecs/
5+
usr/lib/*/cmake/Dtk6Log/

debian/libdtk6log.install

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
usr/lib/*/libdtk6log.so.6*

debian/libdtklog-dev.install

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
usr/include
2-
usr/lib/*/lib*.so
3-
usr/lib/*/pkgconfig/*.pc
4-
usr/lib/*/qt5/*
5-
usr/lib/*/cmake/*/*.cmake
1+
usr/include/dtk5/
2+
usr/lib/*/libdtklog.so
3+
usr/lib/*/pkgconfig/dtklog.pc
4+
usr/lib/*/qt5/mkspecs/
5+
usr/lib/*/cmake/DtkLog/

debian/libdtklog.install

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
usr/lib/*/lib*.so.*
1+
usr/lib/*/libdtklog.so.5*

debian/rules

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,74 @@
11
#!/usr/bin/make -f
22
DPKG_EXPORT_BUILDFLAGS = 1
33
include /usr/share/dpkg/default.mk
4-
export QT_SELECT = qt5
5-
export DEB_CXXFLAGS_MAINT_APPEND = -Ofast
64

75
# 安全编译参数
86
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
97
export DEB_CFLAGS_MAINT_APPEND = -Wall
108
export DEB_CXXFLAGS_MAINT_APPEND = -Wall
119
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wl,-E
1210

13-
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
11+
# reproducible 编译参数
12+
DEB_CMAKE_EXTRA_FLAGS += -DCMAKE_SKIP_BUILD_RPATH=ON
1413

15-
VERSION = $(DEB_VERSION_UPSTREAM)
16-
PACK_VER = $(shell echo $(VERSION) | awk -F'[+_~-]' '{print $$1}')
14+
# 版本映射:x.y.z -> 5.y.z 和 6.y.z
15+
DTK5_VERSION := $(shell echo $(DEB_VERSION_UPSTREAM) | sed -E 's/^[0-9]+(\.|[^0-9]|$$)/5\1/')
16+
DTK6_VERSION := $(shell echo $(DEB_VERSION_UPSTREAM) | sed -E 's/^[0-9]+(\.|[^0-9]|$$)/6\1/')
17+
DTK5_MAJOR_MINOR := $(shell echo $(DTK5_VERSION) | cut -d '.' -f 1,2)
1718

18-
# Calculate build version:
19-
# 5.6.8 -> 0; 5.6.8.7 -> 7; 5.6.8+u001 -> 1; 5.6.8.7+u001 -> 7; 5.6.8.0+u001 -> 0
20-
BUILD_VER = $(shell echo $(VERSION) | awk -F'[+_~-]' '{print $$1}' | awk -F'.' '{print $$4}' | sed 's/[^0-9]//g' | awk '{print int($$1)}')
21-
ifeq ($(BUILD_VER), 0)
22-
ifeq ($(shell expr $(shell echo "$(VERSION)" | awk -F. '{print NF-1}') '<' 3), 1)
23-
BUILD_VER=$(shell echo $(VERSION) | awk -F'[+_~-]' '{print $$2}' | sed 's/[^0-9]//g' | awk '{print int($$1)}')
24-
endif
25-
endif
19+
# Build-Profiles 控制
20+
BUILD_DTK5 := $(if $(filter nodtk5,$(DEB_BUILD_PROFILES)),OFF,ON)
21+
BUILD_DTK6 := $(if $(filter nodtk6,$(DEB_BUILD_PROFILES)),OFF,ON)
2622

2723
%:
2824
dh $@
2925

3026
override_dh_auto_configure:
31-
dh_auto_configure -- -DDLOG_VERSION=$(PACK_VER) -DBUILD_WITH_SYSTEMD=ON
27+
ifeq ($(BUILD_DTK5),ON)
28+
mkdir -p build-dtk5
29+
QT_SELECT=qt5 dh_auto_configure --builddirectory=build-dtk5 -- \
30+
$(DEB_CMAKE_EXTRA_FLAGS) \
31+
-DBUILD_TESTING=OFF \
32+
-DBUILD_WITH_SYSTEMD=ON \
33+
-DDTK5=ON
34+
endif
35+
ifeq ($(BUILD_DTK6),ON)
36+
mkdir -p build-dtk6
37+
dh_auto_configure --builddirectory=build-dtk6 -- \
38+
$(DEB_CMAKE_EXTRA_FLAGS) \
39+
-DBUILD_TESTING=OFF \
40+
-DBUILD_WITH_SYSTEMD=ON \
41+
-DDTK5=OFF
42+
endif
43+
44+
override_dh_auto_build:
45+
ifeq ($(BUILD_DTK5),ON)
46+
QT_SELECT=qt5 dh_auto_build --builddirectory=build-dtk5
47+
endif
48+
ifeq ($(BUILD_DTK6),ON)
49+
dh_auto_build --builddirectory=build-dtk6
50+
endif
51+
52+
override_dh_auto_install:
53+
ifeq ($(BUILD_DTK5),ON)
54+
QT_SELECT=qt5 dh_auto_install --builddirectory=build-dtk5
55+
endif
56+
ifeq ($(BUILD_DTK6),ON)
57+
dh_auto_install --builddirectory=build-dtk6
58+
endif
3259

3360
override_dh_makeshlibs:
34-
dh_makeshlibs -V "libdtklog (>= $(shell echo $(VERSION) | cut -d '.' -f 1,2))"
61+
ifeq ($(BUILD_DTK5),ON)
62+
dh_makeshlibs -V "libdtklog (>= $(DTK5_MAJOR_MINOR))" -plibdtklog
63+
endif
64+
ifeq ($(BUILD_DTK6),ON)
65+
dh_makeshlibs -V "libdtk6log (>= $(DTK6_VERSION))" -plibdtk6log
66+
endif
67+
68+
override_dh_auto_test:
69+
# 测试在 build 阶段已执行
70+
71+
override_dh_auto_clean:
72+
dh_auto_clean --builddirectory=build-dtk5
73+
dh_auto_clean --builddirectory=build-dtk6
74+
rm -rf build-dtk5 build-dtk6

misc/DLogConfig.cmake.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ include(CMakeFindDependencyMacro)
77

88
include(${CMAKE_CURRENT_LIST_DIR}/@DLog@Targets.cmake)
99

10-
get_target_property(Dtk@DTK_VERSION_MAJOR@Log_INCLUDE_DIRS Dtk@DTK_VERSION_MAJOR@::Log INTERFACE_INCLUDE_DIRECTORIES)
11-
get_target_property(Dtk@DTK_VERSION_MAJOR@Log_LIBRARY_DIRS Dtk@DTK_VERSION_MAJOR@::Log INTERFACE_LINK_DIRECTORIES)
10+
get_target_property(Dtk@DTK_NAME_SUFFIX@Log_INCLUDE_DIRS Dtk@DTK_NAME_SUFFIX@::Log INTERFACE_INCLUDE_DIRECTORIES)
11+
get_target_property(Dtk@DTK_NAME_SUFFIX@Log_LIBRARY_DIRS Dtk@DTK_NAME_SUFFIX@::Log INTERFACE_LINK_DIRECTORIES)
1212
check_required_components(@DLog@)
1313

misc/dtklog.pc.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ libdir=${prefix}/@LIBRARY_INSTALL_DIR@
44
includedir=${prefix}/@INCLUDE_INSTALL_DIR@
55

66
Name: @library_target@
7-
Description: @CMAKE_PROJECT_DESCRIPTION@
8-
Version: @CMAKE_PROJECT_VERSION@
7+
Description: @PROJECT_DESCRIPTION@
8+
Version: @DTK_VERSION@
99
Libs: -L${libdir} -l@library_target@
1010
Cflags: -I${includedir}
11+
Requires: Qt@QT_VERSION_MAJOR@Core

misc/qt_lib_dtklog.pri.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
QT.dtklog.VERSION = @CMAKE_PROJECT_VERSION@
2-
QT.dtklog.MAJOR_VERSION = @PROJECT_VERSION_MAJOR@
3-
QT.dtklog.MINOR_VERSION = @PROJECT_VERSION_MINOR@
4-
QT.dtklog.PATCH_VERSION = @PROJECT_VERSION_PATCH@
5-
QT.dtklog.name = dtklog
6-
QT.dtklog.module = dtk@DTK_VERSION_MAJOR@log
1+
QT.dtklog.VERSION = @DTK_VERSION@
2+
QT.dtklog.MAJOR_VERSION = @DTK_VERSION_MAJOR@
3+
QT.dtklog.MINOR_VERSION = @DTK_VERSION_MINOR@
4+
QT.dtklog.PATCH_VERSION = @DTK_VERSION_PATCH@
5+
QT.dtklog.name = dtk@DTK_NAME_SUFFIX@log
6+
QT.dtklog.module = dtk@DTK_NAME_SUFFIX@log
77
QT.dtklog.libs = @CMAKE_INSTALL_PREFIX@/@LIBRARY_INSTALL_DIR@
88
QT.dtklog.includes = @CMAKE_INSTALL_PREFIX@/@INCLUDE_INSTALL_DIR@
99
QT.dtklog.frameworks =

0 commit comments

Comments
 (0)