Skip to content

Commit

Permalink
Improve cmake by setting common variables and generating artifacts in…
Browse files Browse the repository at this point in the history
…to build directory
  • Loading branch information
xeco23 committed Apr 8, 2022
1 parent b76bc0e commit 58ff7a6
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set Version
run: |
version=$(cat "src/VERSION")
version=$(cat "build/release/generated/VERSION")
echo "RELEASE_NAME=${version}" >> "$GITHUB_ENV"
echo "RELEASE_TAG=v${version}" >> "$GITHUB_ENV"
Expand Down
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
# Common build directory
build/

# Build artifacts
src/VERSION
src/Version.hpp
src/Resources.c

# IDE folders
.idea/
.vscode/
24 changes: 14 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
cmake_minimum_required(VERSION 3.8)
project(whatsapp-for-linux VERSION 1.4.2)
project(
whatsapp-for-linux
VERSION 1.4.2
DESCRIPTION "An unofficial WhatsApp desktop application for Linux"
LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(WFL_VERSION ${CMAKE_PROJECT_VERSION})
set(WFL_APP_ID "com.github.eneshecan.WhatsAppForLinux")

include(GNUInstallDirs)

file(WRITE "${CMAKE_SOURCE_DIR}/src/VERSION" ${PROJECT_VERSION})
file(WRITE "${CMAKE_SOURCE_DIR}/src/Version.hpp" "constexpr auto const VERSION = \"${PROJECT_VERSION}\";\n")

add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/src/Resources.c
COMMAND glib-compile-resources --target=${CMAKE_SOURCE_DIR}/src/Resources.c --generate-source gresource.xml
message(STATUS "${CMAKE_PROJECT_NAME} version: ${WFL_VERSION}")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/generated/VERSION" ${WFL_VERSION})
configure_file(${CMAKE_SOURCE_DIR}/src/Config.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/generated/Config.hpp)
execute_process(
COMMAND glib-compile-resources --target=${CMAKE_CURRENT_BINARY_DIR}/generated/Resources.c --generate-source gresource.xml
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/resource
COMMENT "Compiling ui resources"
)

FIND_PACKAGE(PkgConfig REQUIRED)
PKG_CHECK_MODULES(GTKMM gtkmm-3.0 REQUIRED)
PKG_CHECK_MODULES(WEBKIT webkit2gtk-4.0 REQUIRED)
PKG_CHECK_MODULES(APPINDICATOR ayatana-appindicator3-0.1 REQUIRED)
include_directories(${GTKMM_INCLUDE_DIRS} ${WEBKIT_INCLUDE_DIRS} ${APPINDICATOR_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR}/generated/)

add_executable(whatsapp-for-linux
src/main.cpp
src/Version.hpp
src/Resources.c
${CMAKE_CURRENT_BINARY_DIR}/generated/Resources.c
src/util/Settings.cpp
src/ui/Application.cpp
src/ui/MainWindow.cpp
Expand Down
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
mkdir -p build/release && cd build/release && rm -f CMakeCache.txt
echo "Configuring cmake to generate the version information"
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_DIR=/usr ../..
version=$(cat "generated/VERSION")
cd ../..

version=$(cat "src/VERSION")
echo "Setting version to ${version}"
sed -i -E "s/\((.*?)\)/($version)/g" debian/changelog

Expand Down
6 changes: 3 additions & 3 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ parts:
mkdir -p build/release && cd build/release && rm -f CMakeCache.txt
echo "Configuring cmake to generate the version information"
cmake -DCMAKE_BUILD_TYPE=Release ../..
cd ../..
sed -i.bak -e 's|Icon=com.github.eneshecan.WhatsAppForLinux|Icon=share/icons/hicolor/256x256/apps/com.github.eneshecan.WhatsAppForLinux.png|g' resource/desktop/com.github.eneshecan.WhatsAppForLinux.desktop
version=$(cat "src/VERSION")
version=$(cat "generated/VERSION")
echo "Setting version to ${version}"
snapcraftctl set-version $version
cd ../..
sed -i.bak -e 's|Icon=com.github.eneshecan.WhatsAppForLinux|Icon=share/icons/hicolor/256x256/apps/com.github.eneshecan.WhatsAppForLinux.png|g' resource/desktop/com.github.eneshecan.WhatsAppForLinux.desktop
configflags:
- -DCMAKE_BUILD_TYPE=Release
build-packages:
Expand Down
4 changes: 4 additions & 0 deletions src/Config.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

#define WFL_VERSION "${WFL_VERSION}"
#define WFL_APP_ID "${WFL_APP_ID}"
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <clocale>
#include <unistd.h>
#include <iostream>
#include "Config.hpp"
#include "ui/Application.hpp"
#include "ui/MainWindow.hpp"
#include "util/Settings.hpp"
Expand Down Expand Up @@ -34,7 +35,7 @@ int main(int argc, char** argv)

redirectOutputToLogger();

auto app = wfl::ui::Application{argc, argv, "com.github.eneshecan.WhatsAppForLinux", Gio::APPLICATION_HANDLES_OPEN};
auto app = wfl::ui::Application{argc, argv, WFL_APP_ID, Gio::APPLICATION_HANDLES_OPEN};

signal(SIGINT, sigterm);
signal(SIGTERM, sigterm);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <gtkmm/aboutdialog.h>
#include <gtkmm/shortcutswindow.h>
#include "Application.hpp"
#include "../Version.hpp"
#include "Config.hpp"
#include "../util/Settings.hpp"

namespace wfl::ui
Expand Down Expand Up @@ -306,7 +306,7 @@ namespace wfl::ui
auto aboutDialog = Gtk::AboutDialog{};

aboutDialog.set_title("About");
aboutDialog.set_version(VERSION);
aboutDialog.set_version(WFL_VERSION);
aboutDialog.set_program_name("Whatsapp for Linux");
aboutDialog.set_comments("An unofficial WhatsApp desktop application for linux.");
aboutDialog.set_website("https://github.com/eneshecan/whatsapp-for-linux");
Expand Down
3 changes: 2 additions & 1 deletion src/ui/TrayIcon.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "TrayIcon.hpp"
#include <utility>
#include <gtkmm/icontheme.h>
#include "Config.hpp"

namespace wfl::ui
{
Expand Down Expand Up @@ -30,7 +31,7 @@ namespace wfl::ui
}

TrayIcon::TrayIcon()
: m_appIndicator{app_indicator_new("com.github.eneshecan.WhatsAppForLinux.Tray", "", APP_INDICATOR_CATEGORY_COMMUNICATIONS)}
: m_appIndicator{app_indicator_new(WFL_APP_ID ".Tray", "", APP_INDICATOR_CATEGORY_COMMUNICATIONS)}
, m_popupMenu{}
, m_signalShow{}
, m_signalAbout{}
Expand Down
18 changes: 10 additions & 8 deletions src/util/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ namespace wfl::util
namespace
{
auto const CONFIG_DIR = std::string{g_get_user_config_dir()};
auto const CONFIG_APP_DIR = CONFIG_DIR + "/whatsapp-for-linux";
auto const CONFIG_APP_DIR = CONFIG_DIR + "/whatsapp-for-linux";
auto const CONFIG_FILE_PATH = CONFIG_APP_DIR + "/settings.conf";
auto const AUTOSTART_DESKTOP_FILE_PATH = CONFIG_DIR + "/autostart/com.github.eneshecan.WhatsAppForLinux.desktop";

constexpr auto const GROUP_GENERAL = "General";
constexpr auto const GROUP_NETWORK = "Network";
constexpr auto const POSSIBLE_DESKTOP_FILE_PATHS = {
"/usr/local/share/applications/com.github.eneshecan.WhatsAppForLinux.desktop",
"/usr/share/applications/com.github.eneshecan.WhatsAppForLinux.desktop",
"/snap/whatsapp-for-linux/current/share/applications/com.github.eneshecan.WhatsAppForLinux.desktop"
};
}


Expand Down Expand Up @@ -109,13 +105,19 @@ namespace wfl::util
auto destFile = Gio::File::create_for_path(AUTOSTART_DESKTOP_FILE_PATH);
if (autostart)
{
auto const it = std::find_if(POSSIBLE_DESKTOP_FILE_PATHS.begin(), POSSIBLE_DESKTOP_FILE_PATHS.end(),[](auto const& elem)
constexpr auto const possible_desktop_file_paths = std::array<char const*, 3>{
"/usr/local/share/applications/com.github.eneshecan.WhatsAppForLinux.desktop",
"/usr/share/applications/com.github.eneshecan.WhatsAppForLinux.desktop",
"/snap/whatsapp-for-linux/current/share/applications/com.github.eneshecan.WhatsAppForLinux.desktop"
};

auto const it = std::find_if(possible_desktop_file_paths.begin(), possible_desktop_file_paths.end(),[](auto const& elem)
{
auto const file = Gio::File::create_for_path(elem);
return file->query_exists();
});

if (it == POSSIBLE_DESKTOP_FILE_PATHS.end())
if (it == possible_desktop_file_paths.end())
{
std::cerr << "Settings: Failed to find desktop file" << std::endl;
return;
Expand Down

0 comments on commit 58ff7a6

Please sign in to comment.