File 0001-Enable-building-with-Qt6.patch of Package avahi
From fdc30aff1e72ba22aff11e2d9c0ab486ba63d1a6 Mon Sep 17 00:00:00 2001
From: Antonio Larrosa <antonio.larrosa@gmail.com>
Date: Fri, 30 May 2025 11:42:02 +0200
Subject: [PATCH] Enable building with Qt6
---
Makefile.am | 10 ++++++++
acinclude.m4 | 2 +-
avahi-qt/Makefile.am | 22 +++++++++++++++++
avahi-qt/qt-watch.cpp | 10 ++++----
avahi-qt6.pc.in | 11 +++++++++
common/qt-pie.m4 | 55 +++++++++++++++++++++++++++++++++++++++++++
common/qt5-pie.m4 | 27 ---------------------
configure.ac | 31 +++++++++++++++++++++++-
8 files changed, 135 insertions(+), 33 deletions(-)
create mode 100644 avahi-qt6.pc.in
create mode 100644 common/qt-pie.m4
delete mode 100644 common/qt5-pie.m4
diff --git a/Makefile.am b/Makefile.am
index 352cdcf25..3df371ad3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -45,6 +45,7 @@ EXTRA_DIST = \
avahi-qt3.pc.in \
avahi-qt4.pc.in \
avahi-qt5.pc.in \
+ avahi-qt6.pc.in \
avahi-sharp.pc.in \
avahi-ui-sharp.pc.in \
avahi-compat-libdns_sd.pc.in \
@@ -108,6 +109,10 @@ if HAVE_QT5
DX_INPUT += \
$(srcdir)/avahi-qt/qt-watch.h
endif
+if HAVE_QT6
+DX_INPUT += \
+ $(srcdir)/avahi-qt/qt-watch.h
+endif
endif
if HAVE_GLIB
@@ -236,6 +241,11 @@ pkgconfig_DATA += avahi-qt5.pc
CLEANFILES += avahi-qt5.pc
endif
+if HAVE_QT6
+pkgconfig_DATA += avahi-qt6.pc
+CLEANFILES += avahi-qt6.pc
+endif
+
if HAVE_LIBEVENT
pkgconfig_DATA += avahi-libevent.pc
CLEANFILES += avahi-libevent.pc
diff --git a/acinclude.m4 b/acinclude.m4
index ccf2ac616..ac922456e 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -1,2 +1,2 @@
sinclude(common/doxygen.m4)
-sincldue(common/qt5-pie.m4)
+sincldue(common/qt-pie.m4)
diff --git a/avahi-qt/Makefile.am b/avahi-qt/Makefile.am
index b404810f7..78069b56c 100644
--- a/avahi-qt/Makefile.am
+++ b/avahi-qt/Makefile.am
@@ -87,4 +87,26 @@ libavahi_qt5_la_LIBADD = $(AM_LDADD) ../avahi-common/libavahi-common.la $(QT5_LI
libavahi_qt5_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LIBAVAHI_QT5_VERSION_INFO)
endif
+if HAVE_QT6
+
+avahiqt6includedir=$(includedir)/avahi-qt6
+avahiqt6include_HEADERS = \
+ qt-watch.h
+
+lib_LTLIBRARIES += \
+ libavahi-qt6.la
+
+BUILT_SOURCES += qt-watch.moc6
+
+libavahi_qt6_la_SOURCES = \
+ qt-watch.cpp
+
+qt-watch.moc6: qt-watch.cpp
+ $(AM_V_GEN)$(MOC_QT6) $^ > $@
+
+libavahi_qt6_la_CPPFLAGS = $(AM_CFLAGS) --std=gnu++17 $(QT6_CFLAGS) -DQT6 $(VISIBILITY_HIDDEN_CFLAGS)
+libavahi_qt6_la_LIBADD = $(AM_LDADD) ../avahi-common/libavahi-common.la $(QT6_LIBS)
+libavahi_qt6_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LIBAVAHI_QT6_VERSION_INFO)
+endif
+
CLEANFILES = $(BUILT_SOURCES)
diff --git a/avahi-qt/qt-watch.cpp b/avahi-qt/qt-watch.cpp
index 14e0c6e6a..cd18bee3d 100644
--- a/avahi-qt/qt-watch.cpp
+++ b/avahi-qt/qt-watch.cpp
@@ -18,7 +18,7 @@
***/
#include <sys/time.h>
-#if defined(QT5) || defined(QT4)
+#if defined(QT6) || defined(QT5) || defined(QT4)
#include <QSocketNotifier>
#include <QObject>
#include <QTimer>
@@ -114,7 +114,7 @@ AvahiTimeout::AvahiTimeout(const struct timeval* tv, AvahiTimeoutCallback callba
m_callback(callback), m_userdata(userdata)
{
connect(&m_timer, SIGNAL(timeout()), this, SLOT(timeout()));
-#if defined(QT5) || defined(QT4)
+#if defined(QT6) || defined(QT5) || defined(QT4)
m_timer.setSingleShot(true);
#endif
update(tv);
@@ -125,7 +125,7 @@ void AvahiTimeout::update(const struct timeval *tv)
m_timer.stop();
if (tv) {
AvahiUsec u = avahi_age(tv)/1000;
-#if defined(QT5) || defined(QT4)
+#if defined(QT6) || defined(QT5) || defined(QT4)
m_timer.start( (u>0) ? 0 : -u);
#else
m_timer.start( (u>0) ? 0 : -u,true);
@@ -191,7 +191,9 @@ const AvahiPoll* avahi_qt_poll_get(void)
return &qt_poll;
}
-#if defined(QT5)
+#if defined(QT6)
+#include "qt-watch.moc6"
+#elif defined(QT5)
#include "qt-watch.moc5"
#elif defined(QT4)
#include "qt-watch.moc4"
diff --git a/avahi-qt6.pc.in b/avahi-qt6.pc.in
new file mode 100644
index 000000000..ce9f13758
--- /dev/null
+++ b/avahi-qt6.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=${prefix}
+libdir=@libdir@
+includedir=${prefix}/include
+
+Name: avahi-qt6
+Description: Avahi Multicast DNS Responder (QT6 Support)
+Version: @PACKAGE_VERSION@
+Requires: Qt6Core >= 6.0.0
+Libs: -L${libdir} -lavahi-qt6
+Cflags: -D_REENTRANT -I${includedir}
diff --git a/common/qt-pie.m4 b/common/qt-pie.m4
new file mode 100644
index 000000000..8f35e548b
--- /dev/null
+++ b/common/qt-pie.m4
@@ -0,0 +1,55 @@
+AC_DEFUN([AC_AVAHI_QT5_ADD_PIC_IF_NEEDED],
+[
+ AC_LANG_PUSH([C++])
+ save_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $QT5_CFLAGS"
+ AC_MSG_CHECKING([whether Qt works without -fPIC])
+ AC_PREPROC_IFELSE(
+ [AC_LANG_SOURCE([[#include <QtCore>]])],
+ [AC_MSG_RESULT(yes)],
+ [
+ AC_MSG_RESULT(no)
+ AC_MSG_CHECKING([whether Qt works with -fPIC])
+ CPPFLAGS="$CPPFLAGS -fPIC"
+ AC_PREPROC_IFELSE(
+ [AC_LANG_SOURCE([[#include <QtCore>]])],
+ [
+ AC_MSG_RESULT(yes)
+ QT5_CFLAGS="$QT5_CFLAGS -fPIC"
+ ],
+ [
+ AC_MSG_RESULT(no)
+ AC_MSG_ERROR(Couldn't compile Qt without -fPIC nor with -fPIC)
+ ])
+ ])
+ CPPFLAGS="$save_CPPFLAGS"
+ AC_LANG_POP([C++])
+])
+
+AC_DEFUN([AC_AVAHI_QT6_ADD_PIC_IF_NEEDED],
+[
+ AC_LANG_PUSH([C++])
+ save_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $QT6_CFLAGS"
+ AC_MSG_CHECKING([whether Qt works without -fPIC])
+ AC_PREPROC_IFELSE(
+ [AC_LANG_SOURCE([[#include <QtCore>]])],
+ [AC_MSG_RESULT(yes)],
+ [
+ AC_MSG_RESULT(no)
+ AC_MSG_CHECKING([whether Qt works with -fPIC])
+ CPPFLAGS="$CPPFLAGS -fPIC"
+ AC_PREPROC_IFELSE(
+ [AC_LANG_SOURCE([[#include <QtCore>]])],
+ [
+ AC_MSG_RESULT(yes)
+ QT6_CFLAGS="$QT6_CFLAGS -fPIC"
+ ],
+ [
+ AC_MSG_RESULT(no)
+ AC_MSG_ERROR(Couldn't compile Qt without -fPIC nor with -fPIC)
+ ])
+ ])
+ CPPFLAGS="$save_CPPFLAGS"
+ AC_LANG_POP([C++])
+])
diff --git a/common/qt5-pie.m4 b/common/qt5-pie.m4
deleted file mode 100644
index 10d564c8f..000000000
--- a/common/qt5-pie.m4
+++ /dev/null
@@ -1,27 +0,0 @@
-AC_DEFUN([AC_AVAHI_QT_ADD_PIC_IF_NEEDED],
-[
- AC_LANG_PUSH([C++])
- save_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="$CPPFLAGS $QT5_CFLAGS"
- AC_MSG_CHECKING([whether Qt works without -fPIC])
- AC_PREPROC_IFELSE(
- [AC_LANG_SOURCE([[#include <QtCore>]])],
- [AC_MSG_RESULT(yes)],
- [
- AC_MSG_RESULT(no)
- AC_MSG_CHECKING([whether Qt works with -fPIC])
- CPPFLAGS="$CPPFLAGS -fPIC"
- AC_PREPROC_IFELSE(
- [AC_LANG_SOURCE([[#include <QtCore>]])],
- [
- AC_MSG_RESULT(yes)
- QT5_CFLAGS="$QT5_CFLAGS -fPIC"
- ],
- [
- AC_MSG_RESULT(no)
- AC_MSG_ERROR(Couldn't compile Qt without -fPIC nor with -fPIC)
- ])
- ])
- CPPFLAGS="$save_CPPFLAGS"
- AC_LANG_POP([C++])
-])
diff --git a/configure.ac b/configure.ac
index 31bce3d76..5959df14e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,6 +36,7 @@ AC_SUBST(LIBAVAHI_GOBJECT_VERSION_INFO, [0:5:0])
AC_SUBST(LIBAVAHI_QT3_VERSION_INFO, [1:2:0])
AC_SUBST(LIBAVAHI_QT4_VERSION_INFO, [1:2:0])
AC_SUBST(LIBAVAHI_QT5_VERSION_INFO, [1:2:0])
+AC_SUBST(LIBAVAHI_QT6_VERSION_INFO, [1:2:0])
AC_SUBST(LIBAVAHI_UI_VERSION_INFO, [1:4:1])
# Do not touch these, since they we took this version-info from upstream HOWL/Bonjour
@@ -557,7 +558,7 @@ AC_ARG_ENABLE(qt5,
if test "x$HAVE_QT5" = "xyes" ; then
PKG_CHECK_MODULES( QT5, [ Qt5Core >= 5.0.0 ])
- AC_AVAHI_QT_ADD_PIC_IF_NEEDED
+ AC_AVAHI_QT5_ADD_PIC_IF_NEEDED
AC_SUBST(QT5_CFLAGS)
AC_SUBST(QT5_LIBS)
QT5_PREFIX="`$PKG_CONFIG --variable=host_bins Qt5Core`"
@@ -569,6 +570,32 @@ if test "x$HAVE_QT5" = "xyes" ; then
fi
AM_CONDITIONAL(HAVE_QT5, test "x$HAVE_QT5" = "xyes")
+#
+# Check for Qt 6
+#
+AC_ARG_ENABLE(qt6,
+ AS_HELP_STRING([--disable-qt6],[Disable building of Qt6Core mainloop integration]),
+ [case "${enableval}" in
+ yes) HAVE_QT6=yes ;;
+ no) HAVE_QT6=no ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --enable-qt6) ;;
+ esac],
+ [HAVE_QT6=yes])
+
+if test "x$HAVE_QT6" = "xyes" ; then
+ PKG_CHECK_MODULES( QT6, [ Qt6Core >= 6.0.0 ])
+ AC_AVAHI_QT6_ADD_PIC_IF_NEEDED
+ AC_SUBST(QT6_CFLAGS)
+ AC_SUBST(QT6_LIBS)
+ QT6_PREFIX="`$PKG_CONFIG --variable=libexecdir Qt6Core`"
+ AC_PATH_PROGS(MOC_QT6, [moc-qt6 moc], no, [$QT6_PREFIX])
+ if test "$MOC_QT6" = no; then
+ AC_MSG_ERROR([Could not find QT6 moc])
+ fi
+ AC_SUBST(MOC_QT6)
+fi
+AM_CONDITIONAL(HAVE_QT6, test "x$HAVE_QT6" = "xyes")
+
#
# Check for GTK+ 2.0
#
@@ -1222,6 +1249,7 @@ echo "
Enable QT3: ${HAVE_QT3}
Enable QT4: ${HAVE_QT4}
Enable QT5: ${HAVE_QT5}
+ Enable QT6: ${HAVE_QT6}
Enable Mono: ${HAVE_MONO}
Enable Monodoc: ${HAVE_MONODOC}
Distribution/OS: ${with_distro}
@@ -1292,6 +1320,7 @@ echo "\
Building libavahi-qt3: ${HAVE_QT3}
Building libavahi-qt4: ${HAVE_QT4}
Building libavahi-qt5: ${HAVE_QT5}
+ Building libavahi-qt6: ${HAVE_QT6}
Building avahi-sharp: ${HAVE_MONO}
Building avahi-compat-libdns_sd: ${ENABLE_COMPAT_LIBDNS_SD}
Building avahi-compat-howl: ${ENABLE_COMPAT_HOWL}