From 5fbb96618fb475a296e9f00f04b3bc79758efc4c Mon Sep 17 00:00:00 2001 From: shunf4 Date: Tue, 5 Oct 2021 12:49:06 +0800 Subject: [PATCH 1/4] adjust CMakeLists.txt, to prepare for win32 and macos builds --- CMakeLists.txt | 61 ++++++++++++++++++++++++++++++++++----- core/CMakeLists.txt | 22 +++++++++++++- signalcatcher_win32.cpp | 42 +++++++++++++++++++++++++++ squawk.rc | 1 + ui/CMakeLists.txt | 5 ++++ ui/widgets/CMakeLists.txt | 10 +++++++ 6 files changed, 132 insertions(+), 9 deletions(-) create mode 100644 signalcatcher_win32.cpp create mode 100644 squawk.rc diff --git a/CMakeLists.txt b/CMakeLists.txt index 771481f..194c88b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,15 +18,17 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) endif() -set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -Wextra") -set(CMAKE_CXX_FLAGS_RELEASE "-O3") +if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -Wextra") + set(CMAKE_CXX_FLAGS_RELEASE "-O3") +endif(CMAKE_COMPILER_IS_GNUCXX) + message("Build type: ${CMAKE_BUILD_TYPE}") set(squawk_SRC main.cpp exception.cpp - signalcatcher.cpp shared/global.cpp shared/utils.cpp shared/message.cpp @@ -34,6 +36,13 @@ set(squawk_SRC shared/icons.cpp ) +if (WIN32) + list(APPEND squawk_SRC signalcatcher_win32.cpp) +else (WIN32) + list(APPEND squawk_SRC signalcatcher.cpp) +endif (WIN32) + + set(squawk_HEAD exception.h signalcatcher.h @@ -47,10 +56,40 @@ set(squawk_HEAD ) configure_file(resources/images/logo.svg squawk.svg COPYONLY) -execute_process(COMMAND convert -background none -size 48x48 squawk.svg squawk48.png WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -execute_process(COMMAND convert -background none -size 64x64 squawk.svg squawk64.png WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -execute_process(COMMAND convert -background none -size 128x128 squawk.svg squawk128.png WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -execute_process(COMMAND convert -background none -size 256x256 squawk.svg squawk256.png WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +if (WIN32) + set(CONVERT_BIN magick convert) +else(WIN32) + set(CONVERT_BIN convert) +endif(WIN32) + +execute_process(COMMAND ${CONVERT_BIN} -background none -size 48x48 squawk.svg squawk48.png WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +execute_process(COMMAND ${CONVERT_BIN} -background none -size 64x64 squawk.svg squawk64.png WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +execute_process(COMMAND ${CONVERT_BIN} -background none -size 128x128 squawk.svg squawk128.png WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +execute_process(COMMAND ${CONVERT_BIN} -background none -size 256x256 squawk.svg squawk256.png WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + +if (WIN32) + execute_process(COMMAND ${CONVERT_BIN} squawk48.png squawk64.png squawk256.png squawk.ico WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set(SQUAWK_WIN_RC "${CMAKE_CURRENT_BINARY_DIR}/squawk.rc") +endif(WIN32) + +if (APPLE) + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/icns.iconset") + execute_process(COMMAND convert -background none -size 16x16 squawk.svg icns.iconset/icon_16x16.png WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + execute_process(COMMAND convert -background none -resize !32x32 squawk.svg "icns.iconset/icon_16x16@2x.png" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + execute_process(COMMAND convert -background none -resize !32x32 squawk.svg "icns.iconset/icon_32x32.png" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + execute_process(COMMAND convert -background none -resize !64x64 squawk.svg "icns.iconset/icon_32x32@2x.png" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + execute_process(COMMAND convert -background none -resize !128x128 squawk.svg "icns.iconset/icon_128x128.png" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + execute_process(COMMAND convert -background none -resize !256x256 squawk.svg "icns.iconset/icon_128x128@2x.png" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + execute_process(COMMAND convert -background none -resize !256x256 squawk.svg "icns.iconset/icon_256x256.png" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + execute_process(COMMAND convert -background none -resize !512x512 squawk.svg "icns.iconset/icon_256x256@2x.png" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + execute_process(COMMAND convert -background none -resize !512x512 squawk.svg "icns.iconset/icon_512x512.png" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + execute_process(COMMAND convert -background none -resize !1024x1024 squawk.svg "icns.iconset/icon_512x512@2x.png" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + execute_process(COMMAND iconutil -c icns "icns.iconset" -o "squawk.icns" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set(MACOSX_BUNDLE_ICON_FILE squawk.icns) + set(APP_ICON_MACOSX ${CMAKE_CURRENT_BINARY_DIR}/squawk.icns) + set_source_files_properties(${APP_ICON_MACOSX} PROPERTIES + MACOSX_PACKAGE_LOCATION "Resources") +endif (APPLE) configure_file(packaging/squawk.desktop squawk.desktop COPYONLY) @@ -92,7 +131,13 @@ if (WITH_KWALLET) endif() endif() -add_executable(squawk ${squawk_SRC} ${squawk_HEAD} ${RCC}) +set(WIN32_FLAG "") +if (WIN32) + if (CMAKE_BUILD_TYPE STREQUAL "Release") + set(WIN32_FLAG WIN32) + endif() +endif(WIN32) +add_executable(squawk ${WIN32_FLAG} ${squawk_SRC} ${squawk_HEAD} ${RCC} ${SQUAWK_WIN_RC} ${APP_ICON_MACOSX}) target_link_libraries(squawk Qt5::Widgets) add_subdirectory(ui) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index b74a055..0377620 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -8,6 +8,19 @@ find_package(Qt5Gui CONFIG REQUIRED) find_package(Qt5Network CONFIG REQUIRED) find_package(Qt5Xml CONFIG REQUIRED) +# Find LMDB from system or ${LMDB_DIR} +find_path(LMDB_INCLUDE_DIR NAMES lmdb.h PATHS "${LMDB_DIR}/include") + +if (UNIX AND NOT APPLE) + # Linux + find_library(LMDB_LIBRARIES NAMES liblmdb.a PATHS ${LMDB_DIR}) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) +else (UNIX AND NOT APPLE) + # Windows / macOS: LMDB_DIR has to be specified + set(LMDB_LIBRARIES "${LMDB_DIR}/lib/liblmdb.a") +endif (UNIX AND NOT APPLE) + set(squawkCORE_SRC squawk.cpp account.cpp @@ -27,6 +40,7 @@ add_subdirectory(passwordStorageEngines) # Tell CMake to create the helloworld executable add_library(squawkCORE ${squawkCORE_SRC}) +target_include_directories(squawkCORE PUBLIC ${LMDB_INCLUDE_DIR}) if(SYSTEM_QXMPP) get_target_property(QXMPP_INTERFACE_INCLUDE_DIRECTORIES QXmpp::QXmpp INTERFACE_INCLUDE_DIRECTORIES) @@ -39,7 +53,13 @@ target_link_libraries(squawkCORE Qt5::Network) target_link_libraries(squawkCORE Qt5::Gui) target_link_libraries(squawkCORE Qt5::Xml) target_link_libraries(squawkCORE qxmpp) -target_link_libraries(squawkCORE lmdb) + +target_link_libraries(squawkCORE ${LMDB_LIBRARIES}) +if (UNIX AND NOT APPLE) + # Linux + target_link_libraries(squawkCORE Threads::Threads) +endif (UNIX AND NOT APPLE) + target_link_libraries(squawkCORE simpleCrypt) if (WITH_KWALLET) target_link_libraries(squawkCORE kwalletPSE) diff --git a/signalcatcher_win32.cpp b/signalcatcher_win32.cpp new file mode 100644 index 0000000..ca7b5a2 --- /dev/null +++ b/signalcatcher_win32.cpp @@ -0,0 +1,42 @@ +/* + * Squawk messenger. + * Copyright (C) 2021 Shunf4 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "signalcatcher.h" +#include + +SignalCatcher::SignalCatcher(QCoreApplication *p_app, QObject *parent): + QObject(parent), + app(p_app) +{ +} + +SignalCatcher::~SignalCatcher() +{} + +void SignalCatcher::handleSigInt() +{ +} + +void SignalCatcher::intSignalHandler(int unused) +{ +} + +int SignalCatcher::setup_unix_signal_handlers() +{ + return 0; +} diff --git a/squawk.rc b/squawk.rc new file mode 100644 index 0000000..6061f20 --- /dev/null +++ b/squawk.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON "squawk.ico" diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index 52913a8..8fd04ff 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -36,6 +36,11 @@ set(squawkUI_SRC utils/dropshadoweffect.cpp ) +# Add squawk.ui to squawkUI_SRC so that the .ui files are displayed in Qt Creator +qt5_wrap_ui(squawkUI_SRC + squawk.ui +) + # Tell CMake to create the helloworld executable add_library(squawkUI ${squawkUI_SRC}) diff --git a/ui/widgets/CMakeLists.txt b/ui/widgets/CMakeLists.txt index 29e2dbc..ffd661e 100644 --- a/ui/widgets/CMakeLists.txt +++ b/ui/widgets/CMakeLists.txt @@ -21,6 +21,16 @@ set(squawkWidgets_SRC joinconference.cpp ) +# Add to squawkUI_SRC so that the .ui files are displayed in Qt Creator +qt5_wrap_ui(squawkWidgets_SRC + account.ui + accounts.ui + conversation.ui + joinconference.ui + newcontact.ui + vcard/vcard.ui +) + # Tell CMake to create the helloworld executable add_library(squawkWidgets ${squawkWidgets_SRC}) From 6764d8ea1104b8cd5787bb87ed3bdc8c5867edf2 Mon Sep 17 00:00:00 2001 From: shunf4 Date: Tue, 5 Oct 2021 12:56:36 +0800 Subject: [PATCH 2/4] remove dependency libuuid --- CMakeLists.txt | 1 - shared/utils.cpp | 8 ++------ shared/utils.h | 1 - 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 194c88b..290568f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,7 +147,6 @@ add_subdirectory(external/simpleCrypt) target_link_libraries(squawk squawkUI) target_link_libraries(squawk squawkCORE) -target_link_libraries(squawk uuid) add_dependencies(${CMAKE_PROJECT_NAME} translations) diff --git a/shared/utils.cpp b/shared/utils.cpp index 924be85..a7a4ecb 100644 --- a/shared/utils.cpp +++ b/shared/utils.cpp @@ -17,15 +17,11 @@ */ #include "utils.h" +#include QString Shared::generateUUID() { - uuid_t uuid; - uuid_generate(uuid); - - char uuid_str[36]; - uuid_unparse_lower(uuid, uuid_str); - return uuid_str; + return QUuid::createUuid().toString(); } diff --git a/shared/utils.h b/shared/utils.h index e9e3d29..8e1e6dd 100644 --- a/shared/utils.h +++ b/shared/utils.h @@ -23,7 +23,6 @@ #include #include -#include #include namespace Shared { From c55b7c6baf932c7f8ac82f2fa5f16658bf6889ea Mon Sep 17 00:00:00 2001 From: shunf4 Date: Tue, 5 Oct 2021 15:11:43 +0800 Subject: [PATCH 3/4] update docs for removed uuid dep and LMDB_DIR var --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 30c6473..987ca53 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ ### Prerequisites - QT 5.12 *(lower versions might work but it wasn't tested)* -- uuid _(usually included in some other package, for example it's ***libutil-linux*** in archlinux)_ - lmdb - CMake 3.0 or higher - qxmpp 1.1.0 or higher @@ -44,7 +43,7 @@ $ git clone https://git.macaw.me/blue/squawk $ cd squawk $ mkdir build $ cd build -$ cmake .. +$ cmake .. [-DLMDB_DIR:PATH=/path/to/lmdb] $ cmake --build . ``` @@ -57,7 +56,7 @@ $ git clone --recurse-submodules https://git.macaw.me/blue/squawk $ cd squawk $ mkdir build $ cd build -$ cmake .. -D SYSTEM_QXMPP=False +$ cmake .. -D SYSTEM_QXMPP=False [-DLMDB_DIR:PATH=/path/to/lmdb] $ cmake --build . ``` From faa7d396a5665e385470f15ebc7841bcabb03f11 Mon Sep 17 00:00:00 2001 From: shunf4 Date: Tue, 5 Oct 2021 16:09:31 +0800 Subject: [PATCH 4/4] add liblmdb.so as possible lmdb lib name --- core/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 0377620..306b4f5 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -13,7 +13,7 @@ find_path(LMDB_INCLUDE_DIR NAMES lmdb.h PATHS "${LMDB_DIR}/include") if (UNIX AND NOT APPLE) # Linux - find_library(LMDB_LIBRARIES NAMES liblmdb.a PATHS ${LMDB_DIR}) + find_library(sudo rLMDB_LIBRARIES NAMES liblmdb.a liblmdb.so PATHS ${LMDB_DIR}) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) else (UNIX AND NOT APPLE)