diff --git a/CMakeLists.txt b/CMakeLists.txt index b978c33..da89682 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,18 @@ set(CMAKE_AUTORCC ON) include(GNUInstallDirs) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") -add_executable(squawk) +set(WIN32_FLAG "") +set(MACOSX_BUNDLE_FLAG "") +if (CMAKE_BUILD_TYPE STREQUAL "Release") + if (WIN32) + set(WIN32_FLAG WIN32) + endif(WIN32) + if (APPLE) + set(MACOSX_BUNDLE_FLAG MACOSX_BUNDLE) + endif(APPLE) +endif() + +add_executable(squawk ${WIN32_FLAG} ${MACOSX_BUNDLE_FLAG}) target_include_directories(squawk PRIVATE ${CMAKE_SOURCE_DIR}) option(SYSTEM_QXMPP "Use system qxmpp lib" ON) @@ -88,7 +99,12 @@ find_package(LMDB REQUIRED) target_link_libraries(squawk PRIVATE Qt5::Core Qt5::Widgets Qt5::DBus Qt5::Network Qt5::Gui Qt5::Xml) target_link_libraries(squawk PRIVATE lmdb) target_link_libraries(squawk PRIVATE simpleCrypt) -target_link_libraries(squawk PRIVATE uuid) +# Link thread libraries on Linux +if(UNIX AND NOT APPLE) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) + target_link_libraries(squawk PRIVATE Threads::Threads) +endif() # Build type if (NOT CMAKE_BUILD_TYPE) @@ -97,11 +113,14 @@ endif () message("Build type: ${CMAKE_BUILD_TYPE}") +if(CMAKE_COMPILER_IS_GNUCXX) target_compile_options(squawk PRIVATE "-Wall;-Wextra" "$<$:-g>" "$<$:-O3>" + "-fno-sized-deallocation" # for eliminating _ZdlPvm ) +endif(CMAKE_COMPILER_IS_GNUCXX) add_subdirectory(core) add_subdirectory(external/simpleCrypt) @@ -114,3 +133,12 @@ add_subdirectory(ui) # Install the executable install(TARGETS squawk DESTINATION ${CMAKE_INSTALL_BINDIR}) + +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" + ) + endif(APPLE) +endif() + diff --git a/README.md b/README.md index f2101d6..e94972f 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,12 @@ ### 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 - KDE Frameworks: kwallet (optional) - KDE Frameworks: KIO (optional) +- Boost ### Getting @@ -34,6 +34,26 @@ You can also clone the repo and build it from source Squawk requires Qt with SSL enabled. It uses CMake as build system. +Please check the prerequisites and install them before installation. + +#### For Windows (Mingw-w64) build + +You need Qt for mingw64 (MinGW 64-bit) platform when installing Qt. + +The best way to acquire library `lmdb` and `boost` is through Msys2. + +First install Msys2, and then install `mingw-w64-x86_64-lmdb` and `mingw-w64-x86_64-boost` by pacman. + +Then you need to provide the cmake cache entry when calling cmake for configuration: + +``` +cmake .. -D LMDB_ROOT_DIR:PATH= -D BOOST_ROOT:PATH= +``` + +``: e.g. `C:/msys64/mingw64`. + +--- + There are two ways to build, it depends whether you have qxmpp installed in your system #### Building with system qxmpp @@ -45,7 +65,7 @@ $ git clone https://git.macaw.me/blue/squawk $ cd squawk $ mkdir build $ cd build -$ cmake .. +$ cmake .. [-D LMDB_ROOT_DIR:PATH=...] [-D BOOST_ROOT:PATH=...] $ cmake --build . ``` @@ -58,10 +78,12 @@ $ 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 [-D LMDB_ROOT_DIR:PATH=...] [-D BOOST_ROOT:PATH=...] $ cmake --build . ``` +You can always refer to `appveyor.yml` to see how AppVeyor build squawk. + ### List of keys Here is the list of keys you can pass to configuration phase of `cmake ..`. diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..30a8125 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,117 @@ +image: + - Visual Studio 2019 + - "Previous Ubuntu1804" + - macOS-Mojave + +branches: + except: + - gh-pages + +for: +- + matrix: + only: + - image: Visual Studio 2019 + + environment: + QTDIR: C:\Qt\5.15.2\mingw81_64 + QTTOOLDIR: C:\Qt\Tools\mingw810_64\bin + QTNINJADIR: C:\Qt\Tools\Ninja + + install: + - set PATH=%QTTOOLDIR%;%QTNINJADIR%;%QTDIR%\bin;%PATH% + - git submodule update --init --recursive + + before_build: + - choco install --yes zstandard + - choco install --yes --version=7.1.0.2 imagemagick.app + - set PATH=C:\Program Files\ImageMagick-7.1.0-Q16-HDRI;%PATH% + + - mkdir lmdb + - cd lmdb + - curl -OL https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-lmdb-0.9.27-1-any.pkg.tar.zst + - zstd -d ./mingw-w64-x86_64-lmdb-0.9.27-1-any.pkg.tar.zst + - tar -xvf ./mingw-w64-x86_64-lmdb-0.9.27-1-any.pkg.tar + - cd .. + + - mkdir boost + - cd boost + - curl -OL https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-boost-1.77.0-2-any.pkg.tar.zst + - zstd -d ./mingw-w64-x86_64-boost-1.77.0-2-any.pkg.tar.zst + - tar -xvf ./mingw-w64-x86_64-boost-1.77.0-2-any.pkg.tar + - cd .. + + - mkdir build + - cd build + - cmake -GNinja -DCMAKE_BUILD_TYPE:String=Release -DCMAKE_PREFIX_PATH:STRING=%QTDIR% -DLMDB_ROOT_DIR:PATH=C:/projects/squawk/lmdb/mingw64 -DBOOST_ROOT:PATH=C:/projects/squawk/boost/mingw64 .. + + build_script: + - cmake --build . + - mkdir deploy + - cd deploy + - copy ..\squawk.exe .\ + - copy ..\external\qxmpp\src\libqxmpp.dll .\ + - windeployqt .\squawk.exe + - windeployqt .\libqxmpp.dll + - cd ..\.. + + artifacts: + - path: build/deploy/squawk.exe + name: Squawk executable (Qt 5.15.2) + + - path: build/deploy + name: Squawk deployment with Qt Framework + +- + matrix: + only: + - image: macOS-Mojave + + install: + - brew install lmdb imagemagick boost + - git submodule update --init --recursive + + before_build: + - mkdir build + - cd build + - cmake -DCMAKE_BUILD_TYPE:String=Release -DCMAKE_PREFIX_PATH:STRING=$HOME/Qt/5.15.2/clang_64 .. + + build_script: + - cmake --build . + + after_build: + - zip -r squawk.app.zip squawk.app + + artifacts: + - path: build/squawk.app/Contents/MacOS/squawk + name: Squawk executable (Qt 5.15.2) + - path: build/external/qxmpp/src/ + name: QXMPP + - path: build/squawk.app.zip + name: Squawk Bundle with Qt Framework (Qt 5.15.2) + +- + matrix: + only: + - image: "Previous Ubuntu1804" + + install: + - ls $HOME/Qt + - sudo apt update + - sudo apt install -y liblmdb-dev liblmdb0 imagemagick mesa-common-dev libglu1-mesa-dev libboost-all-dev + - git submodule update --init --recursive + + before_build: + - mkdir build + - cd build + - cmake -DCMAKE_BUILD_TYPE:String=Release -DCMAKE_PREFIX_PATH:STRING=$HOME/Qt/5.12.10/gcc_64 -DCMAKE_BUILD_RPATH="\$ORIGIN" .. + + build_script: + - cmake --build . + + after_build: + - zip -r squawk.zip squawk -j external/qxmpp/src/libqxmpp* + + artifacts: + - path: build/squawk.zip + name: Squawk executable and libraries (Qt 5.12) diff --git a/cmake/FindLMDB.cmake b/cmake/FindLMDB.cmake index 79788f1..d6f2cd3 100644 --- a/cmake/FindLMDB.cmake +++ b/cmake/FindLMDB.cmake @@ -25,10 +25,15 @@ find_path(LMDB_ROOT_DIR ) find_library(LMDB_LIBRARIES - NAMES lmdb + NAMES liblmdb.a liblmdb.so liblmdb.so.a liblmdb.dll.a # We want lmdb to be static, if possible HINTS ${LMDB_ROOT_DIR}/lib ) +add_library(lmdb UNKNOWN IMPORTED) +set_target_properties(lmdb PROPERTIES + IMPORTED_LOCATION ${LMDB_LIBRARIES} + ) + find_path(LMDB_INCLUDE_DIRS NAMES lmdb.h HINTS ${LMDB_ROOT_DIR}/include diff --git a/cmake/MacOSXBundleInfo.plist.in b/cmake/MacOSXBundleInfo.plist.in new file mode 100644 index 0000000..ac4bbec --- /dev/null +++ b/cmake/MacOSXBundleInfo.plist.in @@ -0,0 +1,41 @@ + + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${MACOSX_BUNDLE_EXECUTABLE_NAME} + CFBundleGetInfoString + ${MACOSX_BUNDLE_INFO_STRING} + CFBundleIconFile + ${MACOSX_BUNDLE_ICON_FILE} + CFBundleIdentifier + ${MACOSX_BUNDLE_GUI_IDENTIFIER} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleLongVersionString + ${MACOSX_BUNDLE_LONG_VERSION_STRING} + CFBundleName + ${MACOSX_BUNDLE_BUNDLE_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + ${MACOSX_BUNDLE_SHORT_VERSION_STRING} + CFBundleSignature + ???? + CFBundleVersion + ${MACOSX_BUNDLE_BUNDLE_VERSION} + CSResourcesFileMapped + + NSHumanReadableCopyright + ${MACOSX_BUNDLE_COPYRIGHT} + + NSPrincipalClass + NSApplication + NSHighResolutionCapable + True + + + diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 3b160e2..9369cb7 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -1,3 +1,8 @@ +set(SIGNALCATCHER_SOURCE signalcatcher.cpp) +if(WIN32) + set(SIGNALCATCHER_SOURCE signalcatcher_win32.cpp) +endif(WIN32) + target_sources(squawk PRIVATE account.cpp account.h @@ -13,7 +18,7 @@ target_sources(squawk PRIVATE networkaccess.h rosteritem.cpp rosteritem.h - signalcatcher.cpp + ${SIGNALCATCHER_SOURCE} signalcatcher.h squawk.cpp squawk.h @@ -23,5 +28,7 @@ target_sources(squawk PRIVATE urlstorage.h ) +target_include_directories(squawk PRIVATE ${LMDB_INCLUDE_DIRS}) + add_subdirectory(handlers) add_subdirectory(passwordStorageEngines) diff --git a/core/signalcatcher_win32.cpp b/core/signalcatcher_win32.cpp new file mode 100644 index 0000000..ca7b5a2 --- /dev/null +++ b/core/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/resources/CMakeLists.txt b/resources/CMakeLists.txt index 86433f3..9288650 100644 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -1,14 +1,59 @@ target_sources(squawk PRIVATE resources.qrc) configure_file(images/logo.svg squawk.svg COPYONLY) +configure_file(squawk.rc squawk.rc 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") + set(SQUAWK_WIN_RC "${SQUAWK_WIN_RC}" PARENT_SCOPE) + target_sources(squawk PRIVATE ${SQUAWK_WIN_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(MACOSX_BUNDLE_ICON_FILE ${MACOSX_BUNDLE_ICON_FILE} PARENT_SCOPE) + set(APP_ICON_MACOSX ${CMAKE_CURRENT_BINARY_DIR}/squawk.icns) + set(APP_ICON_MACOSX ${APP_ICON_MACOSX} PARENT_SCOPE) + target_sources(squawk PRIVATE ${APP_ICON_MACOSX}) + set_source_files_properties(${APP_ICON_MACOSX} TARGET_DIRECTORY squawk PROPERTIES + MACOSX_PACKAGE_LOCATION "Resources") + if (CMAKE_BUILD_TYPE STREQUAL "Release") + if (APPLE) + set_target_properties(squawk PROPERTIES + MACOSX_BUNDLE_EXECUTABLE_NAME "Squawk" + MACOSX_BUNDLE_ICON_FILE "${MACOSX_BUNDLE_ICON_FILE}" # TODO + MACOSX_BUNDLE_BUNDLE_NAME "Squawk" + MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/cmake/MacOSXBundleInfo.plist.in) + endif(APPLE) + endif() +endif (APPLE) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/squawk.svg DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/squawk48.png DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/48x48/apps RENAME squawk.png) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/squawk64.png DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/64x64/apps RENAME squawk.png) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/squawk128.png DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/128x128/apps RENAME squawk.png) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/squawk256.png DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/256x256/apps RENAME squawk.png) + diff --git a/resources/squawk.rc b/resources/squawk.rc new file mode 100644 index 0000000..6061f20 --- /dev/null +++ b/resources/squawk.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON "squawk.ico" 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 a8a17d5..6dcb141 100644 --- a/shared/utils.h +++ b/shared/utils.h @@ -24,9 +24,8 @@ #include #include -//#include "KIO/OpenFileManagerWindowJob" +// #include "KIO/OpenFileManagerWindowJob" -#include #include namespace Shared { 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; +}