From bb8e67efc9907da68ef6140d40ff6c9a70e35b39 Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Mon, 10 Jul 2023 18:40:57 +0200 Subject: [PATCH] Add CMake flag to enable MDNS (off by default) --- CMakeLists.txt | 2 +- core/CMakeLists.txt | 11 ++++++++++- core/backends/lan/CMakeLists.txt | 12 ++++++++++-- core/backends/lan/lanlinkprovider.cpp | 9 +++++++++ core/backends/lan/lanlinkprovider.h | 6 +++++- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 372b12ab4..94c6bed23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,7 +65,7 @@ else() find_package(Qca-qt${QT_MAJOR_VERSION} ${QCA_MIN_VERSION} REQUIRED) set(Qca_LIBRARY qca-qt${QT_MAJOR_VERSION}) - set(KF5_REQUIRED_COMPONENTS I18n ConfigWidgets DBusAddons IconThemes Notifications KIO KCMUtils Service Solid Kirigami2 People WindowSystem GuiAddons DNSSD) + set(KF5_REQUIRED_COMPONENTS I18n ConfigWidgets DBusAddons IconThemes Notifications KIO KCMUtils Service Solid Kirigami2 People WindowSystem GuiAddons) set(KF5_OPTIONAL_COMPONENTS DocTools) set_package_properties(KF5Kirigami2 PROPERTIES diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index b5de85d6e..0ebfa8737 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -18,6 +18,11 @@ configure_file(dbushelper.h.in ${CMAKE_CURRENT_BINARY_DIR}/dbushelper.h) add_subdirectory(backends/lan) add_subdirectory(backends/loopback) +option(MDNS_ENABLED "Use MDNS for device discovery" OFF) +if (MDNS_ENABLED) + find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS DNSSD) +endif() + option(BLUETOOTH_ENABLED "Bluetooth support for kdeconnect" OFF) if(BLUETOOTH_ENABLED) find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Bluetooth) @@ -63,7 +68,6 @@ PRIVATE Qt${QT_MAJOR_VERSION}::DBus KF5::I18n KF5::ConfigCore - KF5::DNSSD ) if(WIN32) @@ -83,6 +87,11 @@ if (LOOPBACK_ENABLED) target_compile_definitions(kdeconnectcore PRIVATE -DKDECONNECT_LOOPBACK) endif() +if (MDNS_ENABLED) + target_compile_definitions(kdeconnectcore PRIVATE -DKDECONNECT_MDNS) + target_link_libraries(kdeconnectcore PRIVATE KF5::DNSSD) +endif() + set_target_properties(kdeconnectcore PROPERTIES VERSION ${KDECONNECT_VERSION} SOVERSION ${KDECONNECT_VERSION_MAJOR} diff --git a/core/backends/lan/CMakeLists.txt b/core/backends/lan/CMakeLists.txt index 042581cdd..a915e6716 100644 --- a/core/backends/lan/CMakeLists.txt +++ b/core/backends/lan/CMakeLists.txt @@ -1,13 +1,21 @@ set(backends_kdeconnect_SRCS ${backends_kdeconnect_SRCS} - backends/lan/server.cpp backends/lan/lanlinkprovider.cpp backends/lan/landevicelink.cpp backends/lan/compositeuploadjob.cpp backends/lan/uploadjob.cpp - backends/lan/mdnsdiscovery.cpp +) +if (MDNS_ENABLED) + set(backends_kdeconnect_SRCS + ${backends_kdeconnect_SRCS} + backends/lan/mdnsdiscovery.cpp + ) +endif() + +set(backends_kdeconnect_SRCS + ${backends_kdeconnect_SRCS} PARENT_SCOPE ) diff --git a/core/backends/lan/lanlinkprovider.cpp b/core/backends/lan/lanlinkprovider.cpp index 3af19cdbd..741b3fde0 100644 --- a/core/backends/lan/lanlinkprovider.cpp +++ b/core/backends/lan/lanlinkprovider.cpp @@ -46,7 +46,9 @@ LanLinkProvider::LanLinkProvider(bool testMode, quint16 udpBroadcastPort, quint1 , m_udpListenPort(udpListenPort) , m_testMode(testMode) , m_combineBroadcastsTimer(this) +#ifdef KDECONNET_MDNS , m_mdnsDiscovery(this) +#endif { m_combineBroadcastsTimer.setInterval(0); // increase this if waiting a single event-loop iteration is not enough m_combineBroadcastsTimer.setSingleShot(true); @@ -104,16 +106,21 @@ void LanLinkProvider::onStart() } broadcastUdpIdentityPacket(); + +#ifdef KDECONNET_MDNS m_mdnsDiscovery.startAnnouncing(); m_mdnsDiscovery.startDiscovering(); +#endif qCDebug(KDECONNECT_CORE) << "LanLinkProvider started"; } void LanLinkProvider::onStop() { +#ifdef KDECONNET_MDNS m_mdnsDiscovery.stopAnnouncing(); m_mdnsDiscovery.stopDiscovering(); +#endif m_udpSocket.close(); m_server->close(); qCDebug(KDECONNECT_CORE) << "LanLinkProvider stopped"; @@ -139,8 +146,10 @@ void LanLinkProvider::broadcastToNetwork() Q_ASSERT(m_tcpPort != 0); broadcastUdpIdentityPacket(); +#ifdef KDECONNET_MDNS m_mdnsDiscovery.stopDiscovering(); m_mdnsDiscovery.startDiscovering(); +#endif } void LanLinkProvider::broadcastUdpIdentityPacket() diff --git a/core/backends/lan/lanlinkprovider.h b/core/backends/lan/lanlinkprovider.h index 8089146b0..ce54af16c 100644 --- a/core/backends/lan/lanlinkprovider.h +++ b/core/backends/lan/lanlinkprovider.h @@ -17,8 +17,10 @@ #include "backends/linkprovider.h" #include "kdeconnectcore_export.h" #include "landevicelink.h" -#include "mdnsdiscovery.h" #include "server.h" +#ifdef KDECONNET_MDNS +#include "mdnsdiscovery.h" +#endif class KDECONNECTCORE_EXPORT LanLinkProvider : public LinkProvider { @@ -91,7 +93,9 @@ private: const bool m_testMode; QTimer m_combineBroadcastsTimer; +#ifdef KDECONNET_MDNS MdnsDiscovery m_mdnsDiscovery; +#endif }; #endif