From aed93910dbe6baa89c3c5edcd73dca2fbb12bcf1 Mon Sep 17 00:00:00 2001 From: Frederik Seiffert Date: Mon, 11 Sep 2023 16:39:04 +0200 Subject: [PATCH 01/14] Improve Windows link library dependency Fixes an error when building with CMAKE_LINK_LIBRARIES_ONLY_TARGETS enabled. --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 174d56c..c9771e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,9 @@ endif() target_link_libraries(${PROJECT_NAME} PUBLIC ${QT_LIBRARIES}) if(WIN32) - target_link_libraries(${PROJECT_NAME} PRIVATE advapi32) + find_library(advapi32_LIBRARY advapi32 REQUIRED) + mark_as_advanced(advapi32_LIBRARY) + target_link_libraries(${PROJECT_NAME} PRIVATE ${advapi32_LIBRARY}) endif() target_compile_definitions(${PROJECT_NAME} PUBLIC QAPPLICATION_CLASS=${QAPPLICATION_CLASS}) From 1b9526428695932687e3461c803e978f23a2e716 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Mon, 11 Sep 2023 17:58:53 +0300 Subject: [PATCH 02/14] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f8b70a..42752ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 3.4.1 + +* Improved Windows link library dependency. - _Frederik Seiffert_ + ## 3.4.0 * Provide API for blocking sendMessage. - _Christoph Cullmann_ From 1e3cb7776d4797be891db3981d0ca06b167e687f Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Mon, 11 Sep 2023 18:00:49 +0300 Subject: [PATCH 03/14] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42752ea..b9e6efb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 3.4.1 -* Improved Windows link library dependency. - _Frederik Seiffert_ +* Improved Windows advapi32 link library dependency. - _Frederik Seiffert_ ## 3.4.0 From 0d0666f72845791ff32e3ddb06af2ce7a99cc1a5 Mon Sep 17 00:00:00 2001 From: Frederik Seiffert Date: Mon, 11 Sep 2023 20:25:27 +0200 Subject: [PATCH 04/14] CI: set up MSVC environment before running CMake --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ebefd1d..0713a02 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -54,6 +54,9 @@ jobs: 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 }} @@ -83,9 +86,6 @@ jobs: cmake . ${{ matrix.additional_arguments }} cmake --build . - - name: Setup MSVC environment for QMake - uses: ilammy/msvc-dev-cmd@v1 - - name: Build basic example with QMake working-directory: examples/basic/ run: | From 730caedd4870a70aa932df1ba3646eccc969e0d8 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Fri, 22 Sep 2023 12:23:03 +0300 Subject: [PATCH 05/14] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 242aa1f..8031a9c 100644 --- a/README.md +++ b/README.md @@ -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/classSingleApplication.html) -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 From eed383f297be807bb52b1130cb81380f870e0482 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Fri, 22 Sep 2023 12:26:16 +0300 Subject: [PATCH 06/14] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8031a9c..3abe1bd 100644 --- a/README.md +++ b/README.md @@ -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](https://itay-grudev.github.io/SingleApplication/classSingleApplication.html) +## [Documentation](https://itay-grudev.github.io/SingleApplication/) -You can find the full usage reference and examples [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 From 88ba6a82a49cf3fb3599415ad64c6380ae4becf0 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Fri, 22 Sep 2023 12:26:32 +0300 Subject: [PATCH 07/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3abe1bd..515cdb5 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ instances and can send data to the primary instance from secondary instances. ## [Documentation](https://itay-grudev.github.io/SingleApplication/) -You can find the full usage reference and examples [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 From c5f97ceaa566807c1079910e8f1afa12b37ac482 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Fri, 22 Sep 2023 12:28:08 +0300 Subject: [PATCH 08/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 515cdb5..ece4de7 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ 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](https://itay-grudev.github.io/SingleApplication/) +# [Documentation](https://itay-grudev.github.io/SingleApplication/) You can find the full usage reference and examples [here](https://itay-grudev.github.io/SingleApplication/classSingleApplication.html). From 2678b4dcf53e5a9cb1cf074950d90bd15f0b21e4 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Thu, 28 Sep 2023 18:30:56 +0200 Subject: [PATCH 09/14] Use new QNativeIpcKey based QSharedMemory constructor with Qt 6.6 and higher Switch to the new QNativeIpcKey based QSharedMemory constructor with Qt 6.6 and higher, the old constructor will be deprecated. This also makes the library work again with the upcoming Qt 6.6 release and higher. However, there are still issues with releasing the existing memory in cases where the application is forcefully quit or crashed. --- singleapplication.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/singleapplication.cpp b/singleapplication.cpp index 3e8fcb5..95c4d18 100644 --- a/singleapplication.cpp +++ b/singleapplication.cpp @@ -67,12 +67,20 @@ SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSeconda #ifdef Q_OS_UNIX // By explicitly attaching it and then deleting it we make sure that the // memory is deleted even after the process has crashed on Unix. +#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0) + d->memory = new QSharedMemory( QNativeIpcKey( d->blockServerName ) ); +#else d->memory = new QSharedMemory( d->blockServerName ); +#endif d->memory->attach(); delete d->memory; #endif // Guarantee thread safe behaviour with a shared memory block. +#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0) + d->memory = new QSharedMemory( QNativeIpcKey( d->blockServerName ) ); +#else d->memory = new QSharedMemory( d->blockServerName ); +#endif // Create a shared memory block if( d->memory->create( sizeof( InstancesInfo ) )){ From ca8b561502613086ab0e90170f4e444b6c75650e Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Thu, 28 Sep 2023 20:21:47 +0300 Subject: [PATCH 10/14] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9e6efb..2bc4a8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 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_ From f6375b10d04346d0fb5846cf27ad1a99a1b65e2f Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Thu, 12 Oct 2023 23:41:05 +0200 Subject: [PATCH 11/14] SingleApplicationPrivate: Use MD5 on macOS for block server name Maximum key size on macOS is PSHMNAMLEN (31). Fixes #178 --- singleapplication_p.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/singleapplication_p.cpp b/singleapplication_p.cpp index 5499203..3709022 100644 --- a/singleapplication_p.cpp +++ b/singleapplication_p.cpp @@ -131,7 +131,12 @@ QString SingleApplicationPrivate::getUsername() void SingleApplicationPrivate::genBlockServerName() { +#ifdef Q_OS_MACOS + // Maximum key size on macOS is PSHMNAMLEN (31). + QCryptographicHash appData( QCryptographicHash::Md5 ); +#else QCryptographicHash appData( QCryptographicHash::Sha256 ); +#endif #if QT_VERSION < QT_VERSION_CHECK(6, 3, 0) appData.addData( "SingleApplication", 17 ); #else From 7332ec4bd776e8f1025ee8a75a41c6abea2d6cf5 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Fri, 13 Oct 2023 00:57:59 +0300 Subject: [PATCH 12/14] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bc4a8a..1044c4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 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_ From af2f7a2cfd5ea812501269a7422c87bd66c9ffa5 Mon Sep 17 00:00:00 2001 From: Diego Schulz Date: Fri, 13 Oct 2023 21:07:08 -0300 Subject: [PATCH 13/14] Add an example using CMakes FetchContent module --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/README.md b/README.md index ece4de7..7971b5e 100644 --- a/README.md +++ b/README.md @@ -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 From 934e8d34cdc41100b40db74b3563dffe96713232 Mon Sep 17 00:00:00 2001 From: SZinedine Date: Sun, 4 Feb 2024 12:04:38 +0100 Subject: [PATCH 14/14] fix Could not find advapi32_LIBRARY (#183) --- CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c9771e1..174d56c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,9 +38,7 @@ endif() target_link_libraries(${PROJECT_NAME} PUBLIC ${QT_LIBRARIES}) if(WIN32) - find_library(advapi32_LIBRARY advapi32 REQUIRED) - mark_as_advanced(advapi32_LIBRARY) - target_link_libraries(${PROJECT_NAME} PRIVATE ${advapi32_LIBRARY}) + target_link_libraries(${PROJECT_NAME} PRIVATE advapi32) endif() target_compile_definitions(${PROJECT_NAME} PUBLIC QAPPLICATION_CLASS=${QAPPLICATION_CLASS})