CMakeLists.txt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. cmake_minimum_required(VERSION 3.7.0)
  2. project(SingleApplication LANGUAGES CXX)
  3. set(CMAKE_AUTOMOC ON)
  4. add_library(${PROJECT_NAME} STATIC
  5. singleapplication.cpp
  6. singleapplication_p.cpp
  7. )
  8. add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
  9. if(NOT QT_DEFAULT_MAJOR_VERSION)
  10. set(QT_DEFAULT_MAJOR_VERSION 5 CACHE STRING "Qt version to use (5 or 6), defaults to 5")
  11. endif()
  12. # Find dependencies
  13. set(QT_COMPONENTS Core Network)
  14. set(QT_LIBRARIES Qt${QT_DEFAULT_MAJOR_VERSION}::Core Qt${QT_DEFAULT_MAJOR_VERSION}::Network)
  15. if(QAPPLICATION_CLASS STREQUAL QApplication)
  16. list(APPEND QT_COMPONENTS Widgets)
  17. list(APPEND QT_LIBRARIES Qt${QT_DEFAULT_MAJOR_VERSION}::Widgets)
  18. elseif(QAPPLICATION_CLASS STREQUAL QGuiApplication)
  19. list(APPEND QT_COMPONENTS Gui)
  20. list(APPEND QT_LIBRARIES Qt${QT_DEFAULT_MAJOR_VERSION}::Gui)
  21. else()
  22. set(QAPPLICATION_CLASS QCoreApplication)
  23. endif()
  24. find_package(Qt${QT_DEFAULT_MAJOR_VERSION} COMPONENTS ${QT_COMPONENTS} REQUIRED)
  25. target_link_libraries(${PROJECT_NAME} PUBLIC ${QT_LIBRARIES})
  26. if(WIN32)
  27. target_link_libraries(${PROJECT_NAME} PRIVATE advapi32)
  28. endif()
  29. target_compile_definitions(${PROJECT_NAME} PUBLIC QAPPLICATION_CLASS=${QAPPLICATION_CLASS})
  30. target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})