From 05fe0a44045686cfaaca6634de255a89444d454e Mon Sep 17 00:00:00 2001 From: Jan Becker Date: Wed, 14 Aug 2024 12:08:50 +0200 Subject: [PATCH] [cmake] Add optional Qt6 support --- CMakeLists.txt | 19 ++++++++++++---- cmake/SeisComP.cmake | 52 +++++++++++++++++++++++++++++++++----------- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0f446a6..e294239d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,13 +59,24 @@ SET(PYTHON_LIBRARY_SUFFIX /python) SET(PYTHON_LIBRARY_PATH lib${PYTHON_LIBRARY_SUFFIX}) OPTION(SC_GLOBAL_GUI "Build graphical user interfaces (requires Qt5)" ON) -SET(SC_GLOBAL_GUI_QT5 ON) +OPTION(SC_GLOBAL_GUI_QT5 "Build graphical user interfaces with Qt5" ON) +OPTION(SC_GLOBAL_GUI_QT6 "Build graphical user interfaces with Qt6" OFF) IF(SC_GLOBAL_GUI) - IF(NOT SC_GLOBAL_GUI_QT5) - MESSAGE(FATAL_ERROR "Qt5 must be enabled, other versions are not supported") + IF((NOT SC_GLOBAL_GUI_QT5) AND (NOT SC_GLOBAL_GUI_QT6)) + MESSAGE(FATAL_ERROR "Either Qt5 or Qt6 must be enabled, other versions are not supported") + ENDIF() + IF((SC_GLOBAL_GUI_QT5) AND (SC_GLOBAL_GUI_QT6)) + MESSAGE(FATAL_ERROR "Qt5 and Qt6 are enabled, please decide for one of them") + ENDIF() + IF(SC_GLOBAL_GUI_QT5) + FIND_PACKAGE(Qt5 REQUIRED COMPONENTS Core Widgets) + MESSAGE(STATUS "Use Qt5") + ENDIF() + IF(SC_GLOBAL_GUI_QT6) + FIND_PACKAGE(Qt6 REQUIRED COMPONENTS Core Widgets) + MESSAGE(STATUS "Use Qt6") ENDIF() - FIND_PACKAGE(Qt5 REQUIRED COMPONENTS Core Widgets) ENDIF() INCLUDE(AddFileDependencies) diff --git a/cmake/SeisComP.cmake b/cmake/SeisComP.cmake index 116b7beb..2b2bccd5 100644 --- a/cmake/SeisComP.cmake +++ b/cmake/SeisComP.cmake @@ -164,7 +164,9 @@ ENDMACRO () MACRO(SC_QT_WRAP_UI outfiles) QT_EXTRACT_OPTIONS_COMPAT(ui_files ui_options ${ARGN}) - IF (SC_GLOBAL_GUI_QT5) + IF (SC_GLOBAL_GUI_QT6) + get_target_property(QT_UIC_EXECUTABLE Qt6::uic LOCATION) + ELSEIF (SC_GLOBAL_GUI_QT5) get_target_property(QT_UIC_EXECUTABLE Qt5::uic LOCATION) ENDIF () @@ -385,7 +387,9 @@ MACRO (SC_ADD_GUI_PLUGIN_LIBRARY _library_package _library_name _plugin_app) # Create MOC Files IF (${_library_package}_MOC_HEADERS) - IF (SC_GLOBAL_GUI_QT5) + IF (SC_GLOBAL_GUI_QT6) + QT6_WRAP_CPP(${_library_package}_MOC_SOURCES ${${_library_package}_MOC_HEADERS} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED) + ELSEIF (SC_GLOBAL_GUI_QT5) QT5_WRAP_CPP(${_library_package}_MOC_SOURCES ${${_library_package}_MOC_HEADERS} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED) ENDIF () ENDIF (${_library_package}_MOC_HEADERS) @@ -399,7 +403,9 @@ MACRO (SC_ADD_GUI_PLUGIN_LIBRARY _library_package _library_name _plugin_app) # Add resources IF (${_library_package}_RESOURCES) - IF (SC_GLOBAL_GUI_QT5) + IF (SC_GLOBAL_GUI_QT6) + QT6_ADD_RESOURCES(${_library_package}_RESOURCE_SOURCES ${${_library_package}_RESOURCES}) + ELSEIF (SC_GLOBAL_GUI_QT5) QT5_ADD_RESOURCES(${_library_package}_RESOURCE_SOURCES ${${_library_package}_RESOURCES}) ENDIF() ENDIF (${_library_package}_RESOURCES) @@ -414,7 +420,9 @@ MACRO (SC_ADD_GUI_PLUGIN_LIBRARY _library_package _library_name _plugin_app) ADD_LIBRARY(${_library_name} MODULE ${${_library_package}_FILES}) SET_TARGET_PROPERTIES(${_library_name} PROPERTIES PREFIX "") - IF (SC_GLOBAL_GUI_QT5) + IF (SC_GLOBAL_GUI_QT6) + TARGET_LINK_LIBRARIES(${_library_name} Qt6::Widgets) + ELSEIF (SC_GLOBAL_GUI_QT5) TARGET_LINK_LIBRARIES(${_library_name} Qt5::Widgets) ELSE () TARGET_LINK_LIBRARIES(${_library_name} ${QT_LIBRARIES}) @@ -442,7 +450,9 @@ MACRO (SC_ADD_GUI_LIBRARY_CUSTOM_INSTALL _library_package _library_name) # Create MOC Files IF (${_library_package}_MOC_HEADERS) - IF (SC_GLOBAL_GUI_QT5) + IF (SC_GLOBAL_GUI_QT6) + QT6_WRAP_CPP(${_library_package}_MOC_SOURCES ${${_library_package}_MOC_HEADERS} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED) + ELSEIF (SC_GLOBAL_GUI_QT5) QT5_WRAP_CPP(${_library_package}_MOC_SOURCES ${${_library_package}_MOC_HEADERS} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED) ENDIF () ENDIF (${_library_package}_MOC_HEADERS) @@ -456,7 +466,9 @@ MACRO (SC_ADD_GUI_LIBRARY_CUSTOM_INSTALL _library_package _library_name) # Add resources IF (${_library_package}_RESOURCES) - IF (SC_GLOBAL_GUI_QT5) + IF (SC_GLOBAL_GUI_QT6) + QT6_ADD_RESOURCES(${_library_package}_RESOURCE_SOURCES ${${_library_package}_RESOURCES}) + ELSEIF (SC_GLOBAL_GUI_QT5) QT5_ADD_RESOURCES(${_library_package}_RESOURCE_SOURCES ${${_library_package}_RESOURCES}) ENDIF() ENDIF (${_library_package}_RESOURCES) @@ -492,7 +504,9 @@ MACRO (SC_ADD_GUI_LIBRARY_CUSTOM_INSTALL _library_package _library_name) ) ADD_LIBRARY(seiscomp_${_library_name} ${${_library_package}_TYPE} ${${_library_package}_FILES_}) - IF (SC_GLOBAL_GUI_QT5) + IF (SC_GLOBAL_GUI_QT6) + TARGET_LINK_LIBRARIES(seiscomp_${_library_name} Qt6::Widgets) + ELSEIF (SC_GLOBAL_GUI_QT5) TARGET_LINK_LIBRARIES(seiscomp_${_library_name} Qt5::Widgets) ELSE () TARGET_LINK_LIBRARIES(seiscomp_${_library_name} ${QT_LIBRARIES}) @@ -591,14 +605,18 @@ ENDMACRO () MACRO (SC_ADD_GUI_EXECUTABLE _package _name) # Create MOC Files IF (${_package}_MOC_HEADERS) - IF (SC_GLOBAL_GUI_QT5) + IF (SC_GLOBAL_GUI_QT6) + QT6_WRAP_CPP(${_package}_MOC_SOURCES ${${_package}_MOC_HEADERS} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED) + ELSEIF (SC_GLOBAL_GUI_QT5) QT5_WRAP_CPP(${_package}_MOC_SOURCES ${${_package}_MOC_HEADERS} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED) ENDIF () ENDIF (${_package}_MOC_HEADERS) # Create UI Headers IF (${_package}_UI) - IF (SC_GLOBAL_GUI_QT5) + IF (SC_GLOBAL_GUI_QT6) + QT6_WRAP_UI(${_package}_UI_HEADERS ${${_package}_UI}) + ELSEIF (SC_GLOBAL_GUI_QT5) QT5_WRAP_UI(${_package}_UI_HEADERS ${${_package}_UI}) ENDIF () INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) @@ -607,7 +625,9 @@ MACRO (SC_ADD_GUI_EXECUTABLE _package _name) # Add resources IF (${_package}_RESOURCES) - IF (SC_GLOBAL_GUI_QT5) + IF (SC_GLOBAL_GUI_QT6) + QT6_ADD_RESOURCES(${_package}_RESOURCE_SOURCES ${${_package}_RESOURCES}) + ELSEIF (SC_GLOBAL_GUI_QT5) QT5_ADD_RESOURCES(${_package}_RESOURCE_SOURCES ${${_package}_RESOURCES}) ENDIF () ENDIF (${_package}_RESOURCES) @@ -653,14 +673,18 @@ MACRO (SC_ADD_GUI_TEST_EXECUTABLE _package _name) # Create MOC Files IF (${_package}_MOC_HEADERS) - IF (SC_GLOBAL_GUI_QT5) + IF (SC_GLOBAL_GUI_QT6) + QT6_WRAP_CPP(${_package}_MOC_SOURCES ${${_package}_MOC_HEADERS} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED) + ELSEIF (SC_GLOBAL_GUI_QT5) QT5_WRAP_CPP(${_package}_MOC_SOURCES ${${_package}_MOC_HEADERS} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED) ENDIF () ENDIF (${_package}_MOC_HEADERS) # Create UI Headers IF (${_package}_UI) - IF (SC_GLOBAL_GUI_QT5) + IF (SC_GLOBAL_GUI_QT6) + QT6_WRAP_UI(${_package}_UI_HEADERS ${${_package}_UI}) + ELSEIF (SC_GLOBAL_GUI_QT5) QT5_WRAP_UI(${_package}_UI_HEADERS ${${_package}_UI}) ENDIF () INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) @@ -669,7 +693,9 @@ MACRO (SC_ADD_GUI_TEST_EXECUTABLE _package _name) # Add resources IF (${_package}_RESOURCES) - IF (SC_GLOBAL_GUI_QT5) + IF (SC_GLOBAL_GUI_QT6) + QT6_ADD_RESOURCES(${_package}_RESOURCE_SOURCES ${${_package}_RESOURCES}) + ELSEIF (SC_GLOBAL_GUI_QT5) QT5_ADD_RESOURCES(${_package}_RESOURCE_SOURCES ${${_package}_RESOURCES}) ENDIF () ENDIF (${_package}_RESOURCES)