Skip to content

Commit

Permalink
[cmake] Add optional Qt6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
gempa-jabe committed Sep 12, 2024
1 parent 3848491 commit 05fe0a4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
19 changes: 15 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
52 changes: 39 additions & 13 deletions cmake/SeisComP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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})
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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})
Expand All @@ -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)
Expand Down Expand Up @@ -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})
Expand All @@ -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)
Expand Down

0 comments on commit 05fe0a4

Please sign in to comment.