-
-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add CMake support * Remove unused 'tr()' * Add option to specify a class for inheritance * Use modern syntax * Rework CMakeLists.txt Thanks to @akallabeth * Add CMake build rules for examples
- Loading branch information
1 parent
196bb34
commit 81465e1
Showing
7 changed files
with
145 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
cmake_minimum_required(VERSION 3.1.0) | ||
|
||
project(SingleApplication) | ||
|
||
set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
set(CMAKE_AUTOMOC ON) | ||
|
||
# SingleApplication base class | ||
set(QAPPLICATION_CLASS QCoreApplication CACHE STRING "Inheritance class for SingleApplication") | ||
set_property(CACHE QAPPLICATION_CLASS PROPERTY STRINGS QApplication QGuiApplication QCoreApplication) | ||
|
||
# Libary target | ||
add_library(${PROJECT_NAME} STATIC | ||
singleapplication.cpp | ||
singleapplication_p.cpp | ||
) | ||
|
||
# Find dependencies | ||
find_package(Qt5Network) | ||
if(QAPPLICATION_CLASS STREQUAL QApplication) | ||
find_package(Qt5 COMPONENTS Widgets REQUIRED) | ||
elseif(QAPPLICATION_CLASS STREQUAL QGuiApplication) | ||
find_package(Qt5 COMPONENTS Gui REQUIRED) | ||
else() | ||
find_package(Qt5 COMPONENTS Core REQUIRED) | ||
endif() | ||
add_compile_definitions(QAPPLICATION_CLASS=${QAPPLICATION_CLASS}) | ||
|
||
# Link dependencies | ||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Network) | ||
if(QAPPLICATION_CLASS STREQUAL QApplication) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Widgets) | ||
elseif(QAPPLICATION_CLASS STREQUAL QGuiApplication) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Gui) | ||
else() | ||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core) | ||
endif() | ||
|
||
if(WIN32) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE advapi32) | ||
endif() | ||
|
||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,15 +50,27 @@ how: | |
git submodule add [email protected]:itay-grudev/SingleApplication.git singleapplication | ||
``` | ||
|
||
Then include the `singleapplication.pri` file in your `.pro` project file. Also | ||
don't forget to specify which `QCoreApplication` class your app is using if it | ||
is not `QCoreApplication`. | ||
**Qmake:** | ||
|
||
Then include the `singleapplication.pri` file in your `.pro` project file. | ||
|
||
```qmake | ||
include(singleapplication/singleapplication.pri) | ||
DEFINES += QAPPLICATION_CLASS=QApplication | ||
``` | ||
|
||
**CMake:** | ||
|
||
Then include the subdirectory in your `CMakeLists.txt` project file. | ||
|
||
```cmake | ||
set(QAPPLICATION_CLASS QApplication CACHE STRING "Inheritance class for SingleApplication") | ||
add_subdirectory(src/third-party/singleapplication) | ||
``` | ||
|
||
Also don't forget to specify which `QCoreApplication` class your app is using if it | ||
is not `QCoreApplication` as in examples above. | ||
|
||
The `Instance Started` signal | ||
------------------------ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
cmake_minimum_required(VERSION 3.1.0) | ||
|
||
project(basic) | ||
|
||
# SingleApplication base class | ||
set(QAPPLICATION_CLASS QCoreApplication CACHE STRING "Inheritance class for SingleApplication") | ||
|
||
add_executable(basic | ||
main.cpp | ||
) | ||
|
||
find_package(Qt5 COMPONENTS Core REQUIRED) | ||
add_subdirectory(../.. SingleApplication) | ||
target_link_libraries(${PROJECT_NAME} Qt5::Core SingleApplication) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
cmake_minimum_required(VERSION 3.1.0) | ||
|
||
project(calculator) | ||
|
||
set(CMAKE_AUTOMOC ON) | ||
|
||
# SingleApplication base class | ||
set(QAPPLICATION_CLASS QApplication CACHE STRING "Inheritance class for SingleApplication") | ||
|
||
add_executable(${PROJECT_NAME} | ||
button.h | ||
calculator.h | ||
button.cpp | ||
calculator.cpp | ||
main.cpp | ||
) | ||
|
||
find_package(Qt5 COMPONENTS Widgets REQUIRED) | ||
add_subdirectory(../.. SingleApplication) | ||
target_link_libraries(${PROJECT_NAME} Qt5::Widgets SingleApplication) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
cmake_minimum_required(VERSION 3.1.0) | ||
|
||
project(sending_arguments) | ||
|
||
set(CMAKE_AUTOMOC ON) | ||
|
||
# SingleApplication base class | ||
set(QAPPLICATION_CLASS QCoreApplication CACHE STRING "Inheritance class for SingleApplication") | ||
|
||
add_executable(${PROJECT_NAME} | ||
main.cpp | ||
messagereceiver.cpp | ||
messagereceiver.h | ||
main.cpp | ||
) | ||
|
||
find_package(Qt5 COMPONENTS Core REQUIRED) | ||
add_subdirectory(../.. SingleApplication) | ||
target_link_libraries(${PROJECT_NAME} Qt5::Core SingleApplication) |