mirror of
https://github.com/ckb-next/ckb-next.git
synced 2026-10-10 12:27:21 -04:00
cmake: Make build system Qt version agnostic
This commit is contained in:
+1
-1
@@ -27,7 +27,7 @@
|
||||
|
||||
# Lower it _only_ if tested to work correctly with that version!
|
||||
# Might be as low as 3.3, but again, use at your own risk
|
||||
cmake_minimum_required(VERSION 3.5.1 FATAL_ERROR)
|
||||
cmake_minimum_required(VERSION 3.13.4 FATAL_ERROR)
|
||||
|
||||
project(ckb-next LANGUAGES C CXX)
|
||||
include(VERSION.cmake)
|
||||
|
||||
@@ -21,19 +21,19 @@
|
||||
# QuaZip_ZLIB_INCLUDE_DIR - The include dir of zlib headers
|
||||
|
||||
# First try to find QuaZip 1.0
|
||||
find_package(QuaZip-Qt5 QUIET)
|
||||
find_package(QuaZip-Qt${QT_VERSION_MAJOR} QUIET)
|
||||
|
||||
IF (QuaZip_LIBRARIES)
|
||||
# in cache already
|
||||
SET(QuaZip_FOUND TRUE)
|
||||
ELSE ()
|
||||
IF(QuaZip-Qt5_FOUND)
|
||||
IF(QuaZip-Qt${QT_VERSION_MAJOR}_FOUND)
|
||||
message("-- Found QuaZip: QuaZip::QuaZip")
|
||||
SET(QuaZip_FOUND TRUE)
|
||||
SET(QuaZip_LIBRARIES "QuaZip::QuaZip" CACHE INTERNAL "")
|
||||
SET(QuaZip_INCLUDE_DIR "QuaZip::QuaZip" CACHE INTERNAL "")
|
||||
ELSE ()
|
||||
set(QuaZip_LIB_VERSION_SUFFIX 5)
|
||||
set(QuaZip_LIB_VERSION_SUFFIX ${QT_VERSION_MAJOR})
|
||||
FIND_LIBRARY(QuaZip_LIBRARIES
|
||||
WIN32_DEBUG_POSTFIX d
|
||||
NAMES quazip${QuaZip_LIB_VERSION_SUFFIX} libquazip.dylib
|
||||
|
||||
+57
-28
@@ -70,7 +70,8 @@ endif ()
|
||||
if (MACOS OR LINUX)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
find_package(Qt5 5.6.0 COMPONENTS Core Widgets Network Gui REQUIRED)
|
||||
find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core Widgets Network Gui)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Gui)
|
||||
find_package(ZLIB REQUIRED)
|
||||
find_package(QuaZip REQUIRED)
|
||||
endif ()
|
||||
@@ -90,7 +91,14 @@ AudioToolbox: ${AUDIOTOOLBOX_LIBRARY}")
|
||||
endif ()
|
||||
mark_as_advanced(FOUNDATION_LIBRARY COREAUDIO_LIBRARY AUDIOTOOLBOX_LIBRARY)
|
||||
elseif (LINUX)
|
||||
find_package(Qt5 5.2.0 COMPONENTS X11Extras DBus)
|
||||
if (QT_VERSION VERSION_LESS "5.12")
|
||||
message(FATAL "ckb-next requires Qt >= 5.12")
|
||||
endif ()
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS DBus)
|
||||
if (QT_VERSION VERSION_LESS "6")
|
||||
find_package(Qt5 REQUIRED COMPONENTS X11Extras)
|
||||
endif ()
|
||||
message(STATUS "Using Qt${QT_VERSION_MAJOR}")
|
||||
endif ()
|
||||
|
||||
# Automatically handle MOC, UIC and RCC
|
||||
@@ -312,27 +320,36 @@ elseif (LINUX)
|
||||
media_linux.cpp)
|
||||
|
||||
if(USE_DBUS_MENU)
|
||||
find_package(dbusmenu-qt5 CONFIG)
|
||||
if(NOT dbusmenu-qt5_FOUND)
|
||||
message(FATAL_ERROR "dbusmenu-qt5 was not found. Either install it or pass -DUSE_DBUS_MENU=0 to fall back to the default Qt tray icon.")
|
||||
if(QT_VERSION VERSION_LESS "6")
|
||||
find_package(dbusmenu-qt5 CONFIG)
|
||||
if(NOT dbusmenu-qt5_FOUND)
|
||||
message(FATAL_ERROR "dbusmenu-qt5 was not found. Either install it or pass -DUSE_DBUS_MENU=0 to fall back to the default Qt tray icon.")
|
||||
endif()
|
||||
target_link_libraries(
|
||||
ckb-next
|
||||
PRIVATE
|
||||
dbusmenu-qt${QT_VERSION_MAJOR}
|
||||
)
|
||||
include_directories(${dbusmenu-qt5_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
target_link_libraries(
|
||||
ckb-next
|
||||
PRIVATE
|
||||
Qt5::DBus
|
||||
dbusmenu-qt5
|
||||
Qt${QT_VERSION_MAJOR}::DBus
|
||||
)
|
||||
target_compile_definitions(
|
||||
ckb-next
|
||||
PRIVATE
|
||||
USE_DBUS_MENU)
|
||||
|
||||
include_directories(${dbusmenu-qt5_INCLUDE_DIRS})
|
||||
qt5_add_dbus_adaptor(statusNotifierAutogen "kstatusnotifier/org.kde.StatusNotifierItem.xml"
|
||||
"kstatusnotifier/kstatusnotifieritemdbus_p.h" KStatusNotifierItemDBus)
|
||||
qt5_add_dbus_interface(statusNotifierAutogen "kstatusnotifier/org.freedesktop.Notifications.xml" notifications_interface)
|
||||
qt5_add_dbus_interface(statusNotifierAutogen "kstatusnotifier/org.kde.StatusNotifierWatcher.xml" statusnotifierwatcher_interface)
|
||||
set_property(SOURCE ${statusNotifierAutogen} PROPERTY SKIP_AUTOGEN ON)
|
||||
cmake_language(EVAL CODE
|
||||
"qt${QT_VERSION_MAJOR}_add_dbus_adaptor(statusNotifierAutogen \"kstatusnotifier/org.kde.StatusNotifierItem.xml\"
|
||||
\"kstatusnotifier/kstatusnotifieritemdbus_p.h\" KStatusNotifierItemDBus)
|
||||
qt${QT_VERSION_MAJOR}_add_dbus_interface(statusNotifierAutogen \"kstatusnotifier/org.kde.StatusNotifierWatcher.xml\" statusnotifierwatcher_interface)
|
||||
qt${QT_VERSION_MAJOR}_add_dbus_interface(statusNotifierAutogen \"kstatusnotifier/org.freedesktop.Notifications.xml\" notifications_interface)"
|
||||
)
|
||||
#set_property(SOURCE ${statusNotifierAutogen} PROPERTY SKIP_AUTOGEN ON)
|
||||
target_sources(
|
||||
ckb-next
|
||||
PRIVATE
|
||||
@@ -386,7 +403,7 @@ if (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/image.qrc")
|
||||
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/image.qrc" "</qresource>\n</RCC>\n")
|
||||
endif ()
|
||||
|
||||
find_package(Qt5LinguistTools CONFIG REQUIRED)
|
||||
find_package(Qt${QT_VERSION_MAJOR}LinguistTools CONFIG REQUIRED)
|
||||
|
||||
# Generate translation.qrc
|
||||
# Note that the qm files haven't been generated yet
|
||||
@@ -404,7 +421,11 @@ endif ()
|
||||
|
||||
# Generate binary translations and update ts files if needed
|
||||
file(GLOB qt_translations_rel RELATIVE "${CMAKE_CURRENT_LIST_DIR}" "${CMAKE_CURRENT_LIST_DIR}/resources/translations/*.ts")
|
||||
qt5_add_translation(QM_FILES "${qt_translations_rel}")
|
||||
if (QT_VERSION VERSION_GREATER_EQUAL "5.15")
|
||||
qt_add_translation(QM_FILES "${qt_translations_rel}")
|
||||
else ()
|
||||
qt5_add_translation(QM_FILES "${qt_translations_rel}")
|
||||
endif ()
|
||||
add_custom_target(ckb-next-lrelease SOURCES "${QM_FILES}")
|
||||
|
||||
# Simple target to call lupdate on demand
|
||||
@@ -515,13 +536,14 @@ if (MACOS OR LINUX)
|
||||
target_link_libraries(
|
||||
ckb-next
|
||||
PRIVATE
|
||||
m
|
||||
Threads::Threads
|
||||
Qt5::Core
|
||||
Qt5::Network
|
||||
Qt5::Widgets
|
||||
Qt5::Gui
|
||||
ZLIB::ZLIB)
|
||||
m
|
||||
Threads::Threads
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
Qt${QT_VERSION_MAJOR}::Network
|
||||
Qt${QT_VERSION_MAJOR}::Widgets
|
||||
Qt${QT_VERSION_MAJOR}::Gui
|
||||
ZLIB::ZLIB)
|
||||
|
||||
endif ()
|
||||
if(MACOS)
|
||||
target_link_libraries(
|
||||
@@ -531,17 +553,24 @@ if(MACOS)
|
||||
"${FOUNDATION_LIBRARY}"
|
||||
"${AUDIOTOOLBOX_LIBRARY}")
|
||||
elseif (LINUX)
|
||||
if (QT_VERSION_MAJOR VERSION_EQUAL "5")
|
||||
target_link_libraries(
|
||||
ckb-next
|
||||
PRIVATE
|
||||
Qt5::X11Extras)
|
||||
endif ()
|
||||
|
||||
target_link_libraries(
|
||||
ckb-next
|
||||
PRIVATE
|
||||
"${XCB_EWMH_LIBRARIES}"
|
||||
"${XCB_SCREENSAVER_LIBRARIES}"
|
||||
Qt5::X11Extras)
|
||||
"${XCB_SCREENSAVER_LIBRARIES}")
|
||||
|
||||
if (PULSEAUDIO_FOUND)
|
||||
target_link_libraries(
|
||||
ckb-next
|
||||
PRIVATE
|
||||
"${PULSEAUDIO_LIBRARIES}")
|
||||
target_link_libraries(
|
||||
ckb-next
|
||||
PRIVATE
|
||||
"${PULSEAUDIO_LIBRARIES}")
|
||||
else()
|
||||
message(WARNING "PulseAudio not found. Mute indicator will not function.")
|
||||
endif ()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
find_package(Qt5 COMPONENTS Widgets REQUIRED)
|
||||
find_package(QT NAMES Qt5 COMPONENTS Widgets REQUIRED)
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
|
||||
|
||||
add_executable(ckb-next-sinfo sinfo.cpp)
|
||||
target_link_libraries(ckb-next-sinfo PRIVATE Qt5::Widgets)
|
||||
target_link_libraries(ckb-next-sinfo PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
|
||||
install(TARGETS ckb-next-sinfo DESTINATION "${INSTALL_DIR_UTILITIES}")
|
||||
|
||||
Reference in New Issue
Block a user