Skip to content

Commit

Permalink
Find Qt5 or Qt6 based on availability
Browse files Browse the repository at this point in the history
  • Loading branch information
probonopd authored Sep 23, 2023
1 parent 846b6a1 commit af0157e
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions styleplugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,27 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(ECM REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

set(QT Core Gui Widgets DBus Multimedia)
find_package(Qt5 REQUIRED ${QT})
# Find Qt5 or Qt6 based on availability
find_package(Qt5 QUIET COMPONENTS Core Gui Widgets DBus Multimedia)
find_package(Qt6 QUIET COMPONENTS Core Gui Widgets DBus Multimedia)

# Choose the Qt version to use
if(Qt6_FOUND)
set(QT_VERSION 6)
set(QT Core Gui Widgets DBus Multimedia)
elseif(Qt5_FOUND)
set(QT_VERSION 5)
set(QT Core Gui Widgets DBus Multimedia)
else()
message(FATAL_ERROR "Qt not found on the system.")
endif()

find_package(PkgConfig REQUIRED)
find_package(KF5 REQUIRED WindowSystem)

include(GNUInstallDirs)

set (SRCS
set(SRCS
pstyleplugin.cpp
pstyleplugin.h
basestyle.h
Expand All @@ -35,20 +48,20 @@ set (SRCS

add_library(${TARGET} MODULE ${SRCS})
target_link_libraries(${TARGET}
Qt5::GuiPrivate
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::DBus
PRIVATE
Qt${QT_VERSION}::Core
Qt${QT_VERSION}::Gui
Qt${QT_VERSION}::Widgets
Qt${QT_VERSION}::DBus
Qt${QT_VERSION}::Multimedia
KF5::WindowSystem
Qt5::Multimedia
)
)

set(SOUND_FILES
../sounds/ping.wav
)

get_target_property(QT_QMAKE_EXECUTABLE ${Qt5Core_QMAKE_EXECUTABLE} IMPORTED_LOCATION)
get_target_property(QT_QMAKE_EXECUTABLE Qt${QT_VERSION}::Core_QMAKE_EXECUTABLE IMPORTED_LOCATION)
if(NOT QT_QMAKE_EXECUTABLE)
message(FATAL_ERROR "qmake is not found.")
endif()
Expand All @@ -58,9 +71,9 @@ execute_process(COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_INSTALL_PLUGINS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(QT_PLUGINS_DIR)
message(STATUS "Qt5 plugin directory:" "${QT_PLUGINS_DIR}")
message(STATUS "Qt plugin directory: ${QT_PLUGINS_DIR}")
else()
message(FATAL_ERROR "Qt5 plugin directory cannot be detected.")
message(FATAL_ERROR "Qt plugin directory cannot be detected.")
endif()

install(TARGETS ${TARGET} DESTINATION ${QT_PLUGINS_DIR}/styles/)
Expand Down

0 comments on commit af0157e

Please sign in to comment.