From 87973b3b67fc87174333f906a119af49cad91e93 Mon Sep 17 00:00:00 2001 From: blue Date: Mon, 29 Aug 2022 21:34:25 +0300 Subject: [PATCH] first attempts to build against upstream qxmpp --- CMakeLists.txt | 83 ++++++++++++++++++++++-------- core/account.cpp | 11 ++++ core/account.h | 6 +++ core/handlers/discoveryhandler.cpp | 5 ++ 4 files changed, 84 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bbae079..d9d0dab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,11 @@ -cmake_minimum_required(VERSION 3.4) +cmake_minimum_required(VERSION 3.5) project(squawk VERSION 0.2.3 LANGUAGES CXX) cmake_policy(SET CMP0076 NEW) cmake_policy(SET CMP0079 NEW) set(CMAKE_CXX_STANDARD 17) +set(QT_VERSION_MAJOR 5) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) @@ -30,21 +31,44 @@ option(SYSTEM_QXMPP "Use system qxmpp lib" ON) option(WITH_KWALLET "Build KWallet support module" ON) option(WITH_KIO "Build KIO support module" ON) option(WITH_KCONFIG "Build KConfig support module" ON) +option(WITH_OMEMO "Build OMEMO support module" ON) # Dependencies ## Qt -set(QT_VERSION_MAJOR 5) -find_package(Qt5 COMPONENTS Widgets DBus Gui Xml Network Core REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets DBus Gui Xml Network Core) find_package(Boost COMPONENTS) target_include_directories(squawk PRIVATE ${Boost_INCLUDE_DIRS}) -target_include_directories(squawk PRIVATE ${Qt5_INCLUDE_DIRS}) -target_include_directories(squawk PRIVATE ${Qt5Widgets_INCLUDE_DIRS}) -target_include_directories(squawk PRIVATE ${Qt5DBus_INCLUDE_DIRS}) -target_include_directories(squawk PRIVATE ${Qt5Gui_INCLUDE_DIRS}) -target_include_directories(squawk PRIVATE ${Qt5Xml_INCLUDE_DIRS}) -target_include_directories(squawk PRIVATE ${Qt5Network_INCLUDE_DIRS}) -target_include_directories(squawk PRIVATE ${Qt5Core_INCLUDE_DIRS}) +target_include_directories(squawk PRIVATE ${Qt${QT_VERSION_MAJOR}_INCLUDE_DIRS}) +target_include_directories(squawk PRIVATE ${Qt${QT_VERSION_MAJOR}Widgets_INCLUDE_DIRS}) +target_include_directories(squawk PRIVATE ${Qt${QT_VERSION_MAJOR}DBus_INCLUDE_DIRS}) +target_include_directories(squawk PRIVATE ${Qt${QT_VERSION_MAJOR}Gui_INCLUDE_DIRS}) +target_include_directories(squawk PRIVATE ${Qt${QT_VERSION_MAJOR}Xml_INCLUDE_DIRS}) +target_include_directories(squawk PRIVATE ${Qt${QT_VERSION_MAJOR}Network_INCLUDE_DIRS}) +target_include_directories(squawk PRIVATE ${Qt${QT_VERSION_MAJOR}Core_INCLUDE_DIRS}) + +#OMEMO +if (WITH_OMEMO) + find_package(PkgConfig) + if (PKG_CONFIG_FOUND) + pkg_check_modules(OMEMO libomemo) + if (OMEMO_FOUND) + pkg_check_modules(SIGNAL libsignal-protocol-c) + if (SIGNAL_FOUND) + message("Building with support of OMEMO") + else () + message("signal-protocol package wasn't found, trying to build without OMEMO support") + set(WITH_OMEMO OFF) + endif() + else () + message("libomemo package wasn't found, trying to build without OMEMO support") + set(WITH_OMEMO OFF) + endif () + else () + message("PKG_CONFIG module wasn't found, can not check libomemo and libsignal-protocol support, trying to build without OMEMO support") + set(WITH_OMEMO OFF) + endif () +endif () ## QXmpp if (SYSTEM_QXMPP) @@ -58,13 +82,6 @@ if (SYSTEM_QXMPP) endif () endif () -if (NOT SYSTEM_QXMPP) - target_link_libraries(squawk PRIVATE qxmpp) - add_subdirectory(external/qxmpp) -else () - target_link_libraries(squawk PRIVATE QXmpp::QXmpp) -endif () - ## KIO if (WITH_KIO) find_package(KF5KIO CONFIG) @@ -109,14 +126,38 @@ if (WITH_KCONFIG) endif() endif() -## Signal (TODO) -# find_package(Signal REQUIRED) +if (NOT SYSTEM_QXMPP) + message("Building with bundled QXmpp") + + if (WITH_OMEMO) + set(BUILD_OMEMO ON) + else () + set(BUILD_OMEMO OFF) + endif () + add_subdirectory(external/qxmpp) + if (WITH_OMEMO) + target_include_directories(QXmppOmemo PRIVATE ${SIGNAL_INCLUDE_DIRS}) + target_include_directories(QXmppOmemo PRIVATE ${OMEMO_INCLUDE_DIRS}) + endif () + + target_link_libraries(squawk PRIVATE qxmpp) +else () + target_link_libraries(squawk PRIVATE QXmpp::QXmpp) +endif () ## LMDB find_package(LMDB REQUIRED) # Linking -target_link_libraries(squawk PRIVATE Qt5::Core Qt5::Widgets Qt5::DBus Qt5::Network Qt5::Gui Qt5::Xml) +target_link_libraries(squawk + PRIVATE + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::DBus + Qt${QT_VERSION_MAJOR}::Network + Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::Xml +) target_link_libraries(squawk PRIVATE lmdb) target_link_libraries(squawk PRIVATE simpleCrypt) # Link thread libraries on Linux @@ -166,7 +207,7 @@ install(FILES LICENSE.md DESTINATION ${CMAKE_INSTALL_DATADIR}/macaw.me/squawk) if (CMAKE_BUILD_TYPE STREQUAL "Release") if (APPLE) add_custom_command(TARGET squawk POST_BUILD COMMENT "Running macdeployqt..." - COMMAND "${Qt5Widgets_DIR}/../../../bin/macdeployqt" "${CMAKE_CURRENT_BINARY_DIR}/squawk.app" + COMMAND "${Qt${QT_VERSION_MAJOR}Widgets_DIR}/../../../bin/macdeployqt" "${CMAKE_CURRENT_BINARY_DIR}/squawk.app" ) endif(APPLE) endif() diff --git a/core/account.cpp b/core/account.cpp index 1c3314f..a523554 100644 --- a/core/account.cpp +++ b/core/account.cpp @@ -40,6 +40,9 @@ Account::Account(const QString& p_login, const QString& p_server, const QString& um(new QXmppUploadRequestManager()), dm(client.findExtension()), rcpm(new QXmppMessageReceiptManager()), +#ifdef WITH_OMEMO + om(new QXmppOmemoManager()), +#endif reconnectScheduled(false), reconnectTimer(new QTimer), network(p_net), @@ -87,6 +90,11 @@ Account::Account(const QString& p_login, const QString& p_server, const QString& client.addExtension(rcpm); QObject::connect(rcpm, &QXmppMessageReceiptManager::messageDelivered, mh, &MessageHandler::onReceiptReceived); + +#ifdef WITH_OMEMO + client.addExtension(om); + qDebug("Added OMEMO manager"); +#endif reconnectTimer->setSingleShot(true); QObject::connect(reconnectTimer, &QTimer::timeout, this, &Account::onReconnectTimer); @@ -118,6 +126,9 @@ Account::~Account() delete rh; delete reconnectTimer; +#ifdef WITH_OMEMO + delete om; +#endif delete rcpm; delete dm; delete um; diff --git a/core/account.h b/core/account.h index 0ce39e5..1c5d14a 100644 --- a/core/account.h +++ b/core/account.h @@ -42,6 +42,9 @@ #include #include #include +#ifdef WITH_OMEMO +#include +#endif #include #include @@ -176,6 +179,9 @@ private: QXmppUploadRequestManager* um; QXmppDiscoveryManager* dm; QXmppMessageReceiptManager* rcpm; +#ifdef WITH_OMEMO + QXmppOmemoManager* om; +#endif bool reconnectScheduled; QTimer* reconnectTimer; diff --git a/core/handlers/discoveryhandler.cpp b/core/handlers/discoveryhandler.cpp index e562e68..e17c072 100644 --- a/core/handlers/discoveryhandler.cpp +++ b/core/handlers/discoveryhandler.cpp @@ -32,6 +32,11 @@ Core::DiscoveryHandler::DiscoveryHandler(Core::Account* account): acc->dm->setClientCapabilitiesNode("https://git.macaw.me/blue/squawk"); } +Core::DiscoveryHandler::~DiscoveryHandler() +{ +} + + void Core::DiscoveryHandler::onItemsReceived(const QXmppDiscoveryIq& items) { QString server = acc->getServer();