Skip to content

Commit

Permalink
Update SingleApplication.
Browse files Browse the repository at this point in the history
  • Loading branch information
punesemu committed Feb 14, 2024
1 parent f2a29ac commit 95effaf
Show file tree
Hide file tree
Showing 33 changed files with 1,430 additions and 50 deletions.
1 change: 1 addition & 0 deletions src/extra/singleapplication/.github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: itay-grudev
34 changes: 34 additions & 0 deletions src/extra/singleapplication/.github/workflows/doxygen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "Documentation"

on:
push:
branches:
- 'master'

jobs:
doxygen:
name: Doxygen
runs-on: ubuntu-22.04
steps:
- name: Clone repo
uses: actions/checkout@v3

- name: Install doxygen and pre-requsites packages
run: |
sudo apt-get update
sudo apt-get install doxygen qtbase5-dev
- name: Generate documentation
run: |
cmake -B build -D SINGLEAPPLICATION_DOCUMENTATION=ON -D DOXYGEN_WARN_AS_ERROR=YES
cmake --build build --target SingleApplicationDocumentation
find build/html/ -name *.html -type f -exec sed -i 's+https://github.com/jothepro/doxygen-awesome-css+https://github.com/itay-grudev/SingleApplication+g' {} \;
- name: Deploy to GitHub pages
uses: crazy-max/ghaction-github-pages@v3
with:
target_branch: gh-pages
build_dir: build/html
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

111 changes: 111 additions & 0 deletions src/extra/singleapplication/.github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: "CI: Build Test"

on:
push:
branches-ignore:
- "releases/**"
paths-ignore:
- "**.md"
pull_request:
paths-ignore:
- "**.md"

jobs:
build:
name: Build
strategy:
matrix:
qt_version:
- 5.15.0
- 6.2.4
- 6.5.0
platform:
- ubuntu-20.04
- windows-latest
- macos-latest
include:
- qt_version: 6.2.4
additional_arguments: -D QT_DEFAULT_MAJOR_VERSION=6
- qt_version: 6.5.0
additional_arguments: -D QT_DEFAULT_MAJOR_VERSION=6
- platform: ubuntu-20.04
make: make
CXXFLAGS: -Wall -Wextra -pedantic -Werror
MAKEFLAGS: -j2
- platform: macos-latest
make: make
CXXFLAGS: -Wall -Wextra -pedantic -Werror
MAKEFLAGS: -j3
- platform: windows-latest
make: nmake
CXXFLAGS: /W4 /WX /MP

runs-on: ${{ matrix.platform }}
env:
CXXFLAGS: ${{ matrix.CXXFLAGS }}
MAKEFLAGS: ${{ matrix.MAKEFLAGS }}

steps:
- name: Clone repo
uses: actions/checkout@v3

- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: ${{ matrix.qt_version }}

- name: Setup MSVC environment for QMake
uses: ilammy/msvc-dev-cmd@v1

- name: Build library with CMake
run: |
cmake . ${{ matrix.additional_arguments }}
cmake --build .
- name: Build basic example with CMake
working-directory: examples/basic/
run: |
cmake . ${{ matrix.additional_arguments }}
cmake --build .
- name: Build calculator example with CMake
working-directory: examples/calculator/
run: |
cmake . ${{ matrix.additional_arguments }}
cmake --build .
- name: Build sending_arguments example with CMake
working-directory: examples/sending_arguments/
run: |
cmake . ${{ matrix.additional_arguments }}
cmake --build .
- name: Build windows_raise_widget example with CMake
working-directory: examples/windows_raise_widget/
run: |
cmake . ${{ matrix.additional_arguments }}
cmake --build .
- name: Build basic example with QMake
working-directory: examples/basic/
run: |
qmake
${{ matrix.make }}
- name: Build calculator example with QMake
working-directory: examples/calculator/
run: |
qmake
${{ matrix.make }}
- name: Build sending_arguments example with QMake
working-directory: examples/sending_arguments/
run: |
qmake
${{ matrix.make }}
- name: Build windows_raise_widget example with QMake
working-directory: examples/windows_raise_widget/
run: |
qmake
${{ matrix.make }}
17 changes: 17 additions & 0 deletions src/extra/singleapplication/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/.idea
/examples/*/*.o
/examples/*/Makefile
/examples/*/moc_*.cpp
/examples/*/moc_predefs.h
/examples/*/*.qmake.stash
/examples/basic/basic
/examples/calculator/calculator
/examples/sending_arguments/sending_arguments
/**/CMakeLists.txt.user
/**/CMakeCache.txt
/**/CMakeCache/*
/**/CMakeFiles/*
/**/Makefile
/**/cmake_install.cmake
/**/*_autogen/
libSingleApplication.a
16 changes: 15 additions & 1 deletion src/extra/singleapplication/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
# Changelog

## 3.5.1

* Bug Fix: Maximum QNativeIpcKey key size on macOS. - _Jonas Kvinge_

## 3.5.0

* Switch to the new QNativeIpcKey based QSharedMemory constructor with Qt 6.6 and higher. - _Jonas Kvinge_

## 3.4.1

* Improved Windows advapi32 link library dependency. - _Frederik Seiffert_

## 3.4.0

* Provide API for blocking sendMessage. - _Christoph Cullmann_

* New documentation generation using Doxygen
* Improved Windows basic widget example
* Updated Project License

## 3.3.4

Expand Down
83 changes: 83 additions & 0 deletions src/extra/singleapplication/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
cmake_minimum_required(VERSION 3.12.0)

project(SingleApplication LANGUAGES CXX DESCRIPTION "Replacement for QtSingleApplication")

set(CMAKE_AUTOMOC ON)

add_library(${PROJECT_NAME} STATIC
singleapplication.cpp
singleapplication_p.cpp
)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

if(NOT QT_DEFAULT_MAJOR_VERSION)
set(QT_DEFAULT_MAJOR_VERSION 5 CACHE STRING "Qt version to use (5 or 6), defaults to 5")
endif()

# Find dependencies
set(QT_COMPONENTS Core Network)
set(QT_LIBRARIES Qt${QT_DEFAULT_MAJOR_VERSION}::Core Qt${QT_DEFAULT_MAJOR_VERSION}::Network)

if(QAPPLICATION_CLASS STREQUAL QApplication)
list(APPEND QT_COMPONENTS Widgets)
list(APPEND QT_LIBRARIES Qt${QT_DEFAULT_MAJOR_VERSION}::Widgets)
elseif(QAPPLICATION_CLASS STREQUAL QGuiApplication)
list(APPEND QT_COMPONENTS Gui)
list(APPEND QT_LIBRARIES Qt${QT_DEFAULT_MAJOR_VERSION}::Gui)
else()
set(QAPPLICATION_CLASS QCoreApplication)
endif()

find_package(Qt${QT_DEFAULT_MAJOR_VERSION} COMPONENTS ${QT_COMPONENTS} REQUIRED)

option(SINGLEAPPLICATION_DOCUMENTATION "Generate Doxygen documentation" OFF)
if(SINGLEAPPLICATION_DOCUMENTATION)
find_package(Doxygen)
endif()

target_link_libraries(${PROJECT_NAME} PUBLIC ${QT_LIBRARIES})

if(WIN32)
target_link_libraries(${PROJECT_NAME} PRIVATE advapi32)
endif()

target_compile_definitions(${PROJECT_NAME} PUBLIC QAPPLICATION_CLASS=${QAPPLICATION_CLASS})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(${PROJECT_NAME} PRIVATE
QT_NO_CAST_TO_ASCII
QT_NO_CAST_FROM_ASCII
QT_NO_URL_CAST_FROM_STRING
QT_NO_CAST_FROM_BYTEARRAY
QT_USE_QSTRINGBUILDER
QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
QT_NO_KEYWORDS
QT_NO_FOREACH
)

if(DOXYGEN_FOUND)
# Doxygen theme
include(FetchContent)
FetchContent_Declare(DoxygenAwesome
GIT_REPOSITORY https://github.com/jothepro/doxygen-awesome-css
GIT_TAG 4cd62308d825fe0396d2f66ffbab45d0e247724c # 2.0.3
)
FetchContent_MakeAvailable(DoxygenAwesome)
FetchContent_GetProperties(DoxygenAwesome SOURCE_DIR DoxygenAwesome_SOURCE_DIR)

set(DOXYGEN_USE_MDFILE_AS_MAINPAGE README.md)
set(DOXYGEN_GENERATE_TREEVIEW YES)
set(DOXYGEN_HTML_HEADER ${DoxygenAwesome_SOURCE_DIR}/doxygen-custom/header.html)
set(DOXYGEN_HTML_EXTRA_STYLESHEET ${DoxygenAwesome_SOURCE_DIR}/doxygen-awesome.css)
set(DOXYGEN_HTML_EXTRA_FILES
${DoxygenAwesome_SOURCE_DIR}/doxygen-awesome-fragment-copy-button.js
${DoxygenAwesome_SOURCE_DIR}/doxygen-awesome-paragraph-link.js
${DoxygenAwesome_SOURCE_DIR}/doxygen-awesome-darkmode-toggle.js
)

doxygen_add_docs(${PROJECT_NAME}Documentation
singleapplication.h
CHANGELOG.md
Windows.md
README.md
)
endif()
7 changes: 4 additions & 3 deletions src/extra/singleapplication/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
The MIT License (MIT)

Copyright (c) Itay Grudev 2015 - 2020
Copyright (c) Itay Grudev 2015 - 2023

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -9,6 +7,9 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

Permission is not granted to use this software or any of the associated files
as sample data for the purposes of building machine learning models.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

Expand Down
59 changes: 54 additions & 5 deletions src/extra/singleapplication/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Keeps the Primary Instance of your Application and kills each subsequent
instances. It can (if enabled) spawn secondary (non-related to the primary)
instances and can send data to the primary instance from secondary instances.

## Documentation
# [Documentation](https://itay-grudev.github.io/SingleApplication/)

You can find the full usage reference [here](https://itay-grudev.github.io/SingleApplication/classSingleApplication.html).
You can find the full usage reference and examples [here](https://itay-grudev.github.io/SingleApplication/classSingleApplication.html).

## Usage

Expand Down Expand Up @@ -60,6 +60,50 @@ add_subdirectory(src/third-party/singleapplication)
target_link_libraries(${PROJECT_NAME} SingleApplication::SingleApplication)
```

Directly including this repository as a Git submodule, or even just a shallow copy of the
source code into new projects might not be ideal when using CMake.
Another option is using CMake's `FetchContent` module, available since version `3.11`.
```cmake
# Define the minumun CMake version, as an example 3.24
cmake_minimum_required(VERSION 3.24)
# Include the module
include(FetchContent)
# If using Qt6, override DEFAULT_MAJOR_VERSION
set(QT_DEFAULT_MAJOR_VERSION 6 CACHE STRING "Qt version to use, defaults to 6")
# Set QAPPLICATION_CLASS
set(QAPPLICATION_CLASS QApplication CACHE STRING "Inheritance class for SingleApplication")
# Declare how is the source going to be obtained
FetchContent_Declare(
SingleApplication
GIT_REPOSITORY https://github.com/itay-grudev/SingleApplication
GIT_TAG master
#GIT_TAG e22a6bc235281152b0041ce39d4827b961b66ea6
)
# Fetch the repository and make it available to the build
FetchContent_MakeAvailable(SingleApplication)
# Then simply use find_package as usual
find_package(SingleApplication)
# Finally add it to the target_link_libraries() section
target_link_libraries(ClientePOS PRIVATE
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Sql
SingleApplication::SingleApplication
)
```


The library sets up a `QLocalServer` and a `QSharedMemory` block. The first
instance of your Application is your Primary Instance. It would check if the
shared memory block exists and if not it will start a `QLocalServer` and listen
Expand Down Expand Up @@ -168,6 +212,11 @@ instances running.

## License

This library and it's supporting documentation are released under
`The MIT License (MIT)` with the exception of the Qt calculator examples which
is distributed under the BSD license.
This library and it's supporting documentation, with the exception of the Qt
calculator examples which is distributed under the BSD license, are released
under the terms of `The MIT License (MIT)` with an extra condition, that:

```txt
Permission is not granted to use this software or any of the associated files
as sample data for the purposes of building machine learning models.
```
1 change: 1 addition & 0 deletions src/extra/singleapplication/SingleApplication
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "singleapplication.h"
Loading

0 comments on commit 95effaf

Please sign in to comment.