From d6ce5a19332909ebae01760ca3b4793a273adb73 Mon Sep 17 00:00:00 2001 From: re2zero Date: Tue, 27 Jan 2026 20:08:40 +0800 Subject: [PATCH] build(cmake): refactor Qt version compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add Qt auto-detection using find_package(QT NAMES Qt6 Qt5) - Separate debian/control files: * control: V25 (Qt6) with explicit qt6-base-dev, libdtk6*-dev deps * control.1: V20 (Qt5) with explicit qtbase5-dev, libdtk*-dev deps This enables seamless building on both V25 (Qt6) and V20 (Qt5) systems without version-specific conditional dependencies. Log: 分离Qt5/Qt6构建配置,支持V25/V20双版本 PMS: https://pms.uniontech.com/task-view-386321.html --- CMakeLists.txt | 30 ++++++++++++++++++------------ debian/control | 4 ++-- debian/control.1 | 31 +++++++++++++++++++++++++++++++ deepin-pdfium.pc.in | 5 +++-- target.cmake | 8 ++++---- 5 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 debian/control.1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 78d0a7b..e52867b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,18 @@ cmake_minimum_required(VERSION 3.15) set(VERSION "1.0.0" CACHE STRING "PDF rendering library based on PDFium") +# Normalize VERSION format to handle irregular inputs +if(DEFINED VERSION) + # Extract major.minor.patch from VERSION string (e.g., from "1.5.8+u001" to "1.5.8") + if(VERSION MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)") + set(VERSION "${CMAKE_MATCH_1}") + else() + # If no valid semver found, default to "1.0.0" + set(VERSION "1.0.0") + message(WARNING "VERSION does not match semver format, defaulted to ${VERSION}") + endif() +endif() + project(deepin-pdfium VERSION ${VERSION} DESCRIPTION "PDF rendering library based on PDFium" @@ -39,13 +51,13 @@ execute_process( ) add_definitions(-DSYSTEMPAGESIZE=${SYSTEM_PAGE_SIZE}) -# Qt6必须放前面,否则高版本cmake存在问题 -find_package(Qt6 COMPONENTS Core Gui QUIET) -find_package(Qt5 COMPONENTS Core Gui QUIET) +# Auto-detect Qt version (tries Qt6 first, falls back to Qt5) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) +message(STATUS "Found Qt version: ${QT_VERSION_MAJOR}") + +# Find Qt with the detected version +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui) -if(NOT Qt5_FOUND AND NOT Qt6_FOUND) - message(FATAL_ERROR "Neither Qt5 nor Qt6 found - please install at least one") -endif() find_package(PkgConfig REQUIRED) pkg_check_modules(DEPS REQUIRED chardet @@ -79,11 +91,5 @@ include(CMakePackageConfigHelpers) set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/deepin-pdfium) set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}) -if(Qt6_FOUND) - set(QT_DESIRED_VERSION 6) -else() - set(QT_DESIRED_VERSION 5) -endif() - set(TARGET_NAME ${PROJECT_NAME}) include(target.cmake) diff --git a/debian/control b/debian/control index 0e6c0f5..1550ae6 100644 --- a/debian/control +++ b/debian/control @@ -4,8 +4,8 @@ Priority: optional Maintainer: deepin Build-Depends: debhelper (>= 11), cmake, - qt6-base-dev | qtbase5-dev, - qt6-tools-dev-tools | qttools5-dev-tools, + qt6-base-dev, + qt6-tools-dev-tools, pkg-config, libjpeg-dev, libicu-dev, diff --git a/debian/control.1 b/debian/control.1 new file mode 100644 index 0000000..ba90379 --- /dev/null +++ b/debian/control.1 @@ -0,0 +1,31 @@ +Source: deepin-pdfium +Section: libdevel +Priority: optional +Maintainer: deepin +Build-Depends: debhelper (>= 11), + cmake, + qtbase5-dev, + qttools5-dev-tools, + pkg-config, + libjpeg-dev, + libicu-dev, + libpng-dev, + zlib1g-dev, + liblcms2-dev, + libopenjp2-7-dev, + libfreetype6-dev, + libgtest-dev, + libchardet-dev +Standards-Version: 4.3.0 + +Package: libdeepin-pdfium +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: A libaray about PDF. + A library for parsing and editing and displaying PDF. + +Package: libdeepin-pdfium-dev +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, libdeepin-pdfium +Description: A libaray about PDF dev. + A libaray that provides for parsing and editing and displaying PDF interface dev. diff --git a/deepin-pdfium.pc.in b/deepin-pdfium.pc.in index ec21d88..f0e52b5 100644 --- a/deepin-pdfium.pc.in +++ b/deepin-pdfium.pc.in @@ -1,10 +1,11 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} -libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ +libdir=@CMAKE_INSTALL_LIBDIR@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@TARGET_NAME@ Name: @TARGET_NAME@ -Description: @PROJECT_DESCRIPTION@ (Qt@QT_DESIRED_VERSION@ version) +Description: @PROJECT_DESCRIPTION@ (Qt@QT_VERSION_MAJOR@ version) Version: @PROJECT_VERSION@ Libs: -L${libdir} -l@TARGET_NAME@ Cflags: -I${includedir} +Requires: Qt@QT_VERSION_MAJOR@Core Qt@QT_VERSION_MAJOR@Gui diff --git a/target.cmake b/target.cmake index b6f78fb..ecd5e0d 100644 --- a/target.cmake +++ b/target.cmake @@ -17,15 +17,15 @@ target_include_directories(${TARGET_NAME} target_link_libraries(${TARGET_NAME} PRIVATE pdfium - Qt${QT_DESIRED_VERSION}::Core - Qt${QT_DESIRED_VERSION}::Gui + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Gui ${DEPS_LIBRARIES} z jpeg icuuc ) -# 安装Qt6版本 +# Install library install(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) @@ -39,7 +39,7 @@ install(FILES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${TARGET_NAME} ) -# 生成Qt6版本的pkg-config文件 +# Generate pkg-config file configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/deepin-pdfium.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}.pc