feat: add support for Qt6

use both Qt6 and Qt5 to compile, generate gio-qt6 for Qt6

Log: add support for Qt6
This commit is contained in:
zty199 2024-06-04 16:35:59 +08:00 committed by Gary Wang
parent 779ec19a9d
commit 3ef249a410
13 changed files with 183 additions and 62 deletions

67
.gitignore vendored
View file

@ -1,5 +1,64 @@
# User
*.user
# C++ objects and libs
*.slo
*.lo
*.o
*.a
*.la
*.lai
*.so
*.so.*
*.dll
*.dylib
# Build directory
build/
# Qt-es
object_script.*.Release
object_script.*.Debug
*_plugin_import.cpp
/.qmake.cache
/.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
*.qbs.user.*
*.moc
moc_*.cpp
moc_*.h
qrc_*.cpp
ui_*.h
*.qmlc
*.jsc
Makefile*
*build-*
*.qm
*.prl
# Qt unit tests
target_wrapper.*
# QtCreator
*.autosave
# QtCreator Qml
*.qmlproject.user
*.qmlproject.user.*
# QtCreator CMake
CMakeLists.txt.user*
# QtCreator 4.8< compilation database
compile_commands.json
# QtCreator local machine specific files for imported projects
*creator.user*
*_qmlcache.qrc
# debian
debian/*debhelper*
debian/files
debian/libgio-qt/
debian/libgio-qt-dev/
debian/libgio-qt-doc/
debian/tmp/
debian/*.substvars
obj-*

View file

@ -1,7 +1,7 @@
project(gio-qt)
cmake_minimum_required(VERSION 3.12.4)
project(gio-qt)
option(BUILD_TESTS "Build tests" OFF)
option(BUILD_UTILS "Build utilities" ON)
option(BUILD_DOCS "Build documentation" ON)
@ -29,17 +29,9 @@ endif ()
include(GNUInstallDirs)
# Find the QtWidgets library
find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Core)
find_package(PkgConfig REQUIRED)
find_package(Doxygen)
pkg_check_modules(GIOMM giomm-2.4) # look into FindPkgConfig.cmake
add_subdirectory (gio-qt)
add_subdirectory(gio-qt)
if (BUILD_TESTS)
find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Test)
add_subdirectory(test)
endif ()
@ -48,6 +40,7 @@ if (BUILD_UTILS)
endif ()
if (BUILD_DOCS)
find_package(Doxygen)
if (NOT DOXYGEN_FOUND)
message(FATAL_ERROR "Doxygen is required to build the documentation.")
endif ()
@ -70,7 +63,6 @@ if (BUILD_DOCS)
)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/docs/gio-qt.qch DESTINATION share/qt5/doc)
else ()
message (STATUS "")
message (STATUS "To build docs, please use -DBUILD_DOCS=Yes")

2
debian/compat vendored
View file

@ -1 +1 @@
9
11

15
debian/control vendored
View file

@ -3,14 +3,15 @@ Section: libs
Priority: optional
Maintainer: Gary Wang <wzc782970009@gmail.com>
Build-Depends:
debhelper (>= 9),
debhelper (>= 11),
cmake,
pkg-config,
qtbase5-dev,
qt5-qmake,
qttools5-dev-tools,
qt6-base-dev,
qt6-tools-dev-tools,
libglibmm-2.4-dev,
doxygen,
qttools5-dev-tools
doxygen
Standards-Version: 3.9.8
Homepage: https://github.com/linuxdeepin/gio-qt
@ -20,18 +21,18 @@ Conflicts: libgio-qt0
Replaces: libgio-qt0
Depends: ${shlibs:Depends}, ${misc:Depends}, libglibmm-2.4-1v5
Description: Gio wrapper for Qt.
A convenient way to bind gio with Qt5.
A convenient way to bind gio with either Qt5 or Qt6.
Package: libgio-qt-dev
Architecture: any
Section: libdevel
Depends: libgio-qt, ${misc:Depends}, libglibmm-2.4-dev
Description: Development package for libgio-qt.
A convenient way to bind gio with Qt5.
A convenient way to bind gio with either Qt5 or Qt6.
Package: libgio-qt-doc
Architecture: any
Section: doc
Depends: ${misc:Depends}
Description: Gio wrapper for Qt (documentation)
A convenient way to bind gio with Qt5.
A convenient way to bind gio with either Qt5 or Qt6.

View file

@ -1,7 +1,9 @@
# Populate a CMake variable with the sources
# TODO: portable headers?
configure_file ("gio-qt.pc.in" "gio-qt.pc" @ONLY)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GIOMM giomm-2.4) # look into FindPkgConfig.cmake
set (QGIO_PUBLIC_HEADER_FILES
include/dglibutils.h
@ -34,40 +36,9 @@ set (QGIO_PRIVATE_CPP_FILES
private/dgiohelper.cpp
)
# Library
add_library (gio-qt SHARED
${QGIO_PUBLIC_HEADER_FILES}
${QGIO_PRIVATE_HEADER_FILES}
${QGIO_PRIVATE_CPP_FILES}
)
include(qt6.cmake)
include(qt5.cmake)
set_target_properties(
gio-qt PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)
target_include_directories(gio-qt
PRIVATE
${GIOMM_INCLUDE_DIRS}
${CMAKE_CURRENT_LIST_DIR}/private
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
)
target_link_libraries (gio-qt Qt5::Core ${GIOMM_LIBRARIES})
target_compile_definitions(gio-qt PRIVATE
QT_NO_KEYWORDS
)
## dev files
install (FILES ${QGIO_PUBLIC_HEADER_FILES}
DESTINATION include/gio-qt
)
install_targets ("/${CMAKE_INSTALL_LIBDIR}" gio-qt)
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/gio-qt.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)

12
gio-qt/gio-qt6.pc.in Normal file
View file

@ -0,0 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/include
Name: gio-qt6
Description: Qt wrapper library for GIO.
Version: @PROJECT_VERSION@
Requires: glibmm-2.4, Qt6Core
Libs: -L${libdir} -lgio-qt6
Cflags: -I${includedir} -I${includedir}/gio-qt

View file

@ -8,6 +8,8 @@
#include <QObject>
#include <QSharedData>
#include <limits.h>
namespace Gio {
class File;
}

39
gio-qt/qt5.cmake Normal file
View file

@ -0,0 +1,39 @@
# Find the QtWidgets library
find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Core)
# Library
add_library(${PROJECT_NAME}_qt5 SHARED
${QGIO_PUBLIC_HEADER_FILES}
${QGIO_PRIVATE_HEADER_FILES}
${QGIO_PRIVATE_CPP_FILES}
)
set_target_properties(
${PROJECT_NAME}_qt5 PROPERTIES
OUTPUT_NAME gio-qt
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)
target_include_directories(${PROJECT_NAME}_qt5
PRIVATE
${GIOMM_INCLUDE_DIRS}
${CMAKE_CURRENT_LIST_DIR}/private
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
Qt5::Core
)
target_link_libraries(${PROJECT_NAME}_qt5 Qt5::Core ${GIOMM_LIBRARIES})
target_compile_definitions(${PROJECT_NAME}_qt5 PRIVATE
QT_NO_KEYWORDS
)
install(TARGETS ${PROJECT_NAME}_qt5 DESTINATION ${CMAKE_INSTALL_LIBDIR})
## dev files
configure_file("gio-qt.pc.in" "gio-qt.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/gio-qt.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)

39
gio-qt/qt6.cmake Normal file
View file

@ -0,0 +1,39 @@
# Find the QtWidgets library
find_package(Qt6 REQUIRED COMPONENTS Core)
# Library
add_library(${PROJECT_NAME}_qt6 SHARED
${QGIO_PUBLIC_HEADER_FILES}
${QGIO_PRIVATE_HEADER_FILES}
${QGIO_PRIVATE_CPP_FILES}
)
set_target_properties(
${PROJECT_NAME}_qt6 PROPERTIES
OUTPUT_NAME gio-qt6
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)
target_include_directories(${PROJECT_NAME}_qt6
PRIVATE
${GIOMM_INCLUDE_DIRS}
${CMAKE_CURRENT_LIST_DIR}/private
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
Qt6::Core
)
target_link_libraries(${PROJECT_NAME}_qt6 Qt6::Core ${GIOMM_LIBRARIES})
target_compile_definitions(${PROJECT_NAME}_qt6 PRIVATE
QT_NO_KEYWORDS
)
install(TARGETS ${PROJECT_NAME}_qt6 DESTINATION ${CMAKE_INSTALL_LIBDIR})
## dev files
configure_file("gio-qt6.pc.in" "gio-qt6.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/gio-qt6.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)

View file

@ -1,6 +1,4 @@
# QXdgDesktopEntryTest
add_executable (qgio-tools
main.cpp
)
target_link_libraries (qgio-tools gio-qt)
include(qt6.cmake)
include(qt5.cmake)

3
qgio-tools/qt5.cmake Normal file
View file

@ -0,0 +1,3 @@
add_executable (qgio-tools main.cpp)
target_link_libraries (qgio-tools gio-qt_qt5)

3
qgio-tools/qt6.cmake Normal file
View file

@ -0,0 +1,3 @@
add_executable(qgio-tools-qt6 main.cpp)
target_link_libraries(qgio-tools-qt6 gio-qt_qt6)

View file

@ -1,3 +1,5 @@
find_package(Qt6 REQUIRED COMPONENTS Test)
enable_testing ()
function(DGIO_CREATE_TEST _generated_target_name _input_file_name _use_giomm)