Skip to content

Commit a863385

Browse files
jcfrkislinskjporcherhjmjohnson
committed
COMP: Add support for Qt 6
This change updates various CMake scripts to support both Qt 5 and Qt 6. It modifies version checks and adds necessary components for Qt 6. Co-authored-by: Stefan Dinkelacker <s.dinkelacker@dkfz-heidelberg.de> Co-authored-by: jporcher <jean.porcherot@cea.fr> Co-authored-by: Hans Johnson <hans-johnson@uiowa.edu>
1 parent 8d7f06b commit a863385

File tree

11 files changed

+100
-14
lines changed

11 files changed

+100
-14
lines changed

CMake/ctkFunctionGeneratePluginManifest.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function(ctkFunctionGeneratePluginManifest MANIFEST_QRC_FILEPATH_VAR)
104104
if(MY_SKIP_QT5_ADD_RESOURCES)
105105
set(${MANIFEST_QRC_FILEPATH_VAR} ${_manifest_qrc_filepath} PARENT_SCOPE)
106106
else()
107-
if(CTK_QT_VERSION VERSION_EQUAL "5")
107+
if(CTK_QT_VERSION MATCHES "^(5|6)$")
108108
qt_add_resources(_qrc_src ${_manifest_qrc_filepath})
109109
else()
110110
message(FATAL_ERROR "Support for Qt${CTK_QT_VERSION} is not implemented")

CMake/ctkMacroBuildPlugin.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ macro(ctkMacroBuildPlugin)
193193
if(MY_TRANSLATIONS)
194194
set_source_files_properties(${MY_TRANSLATIONS}
195195
PROPERTIES OUTPUT_LOCATION ${_translations_dir})
196-
if(CTK_QT_VERSION VERSION_EQUAL "5")
196+
if(CTK_QT_VERSION MATCHES "^(5|6)$")
197197
qt_create_translation(_plugin_qm_files ${MY_SRCS} ${MY_UI_FORMS} ${MY_TRANSLATIONS})
198198
else()
199199
message(FATAL_ERROR "Support for Qt${CTK_QT_VERSION} is not implemented")

CMake/ctkMacroBuildQtPlugin.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ macro(ctkMacroBuildQtPlugin)
119119
set(compile_flags "-DQT_PLUGIN")
120120
if(CTK_QT_VERSION VERSION_EQUAL "5")
121121
set(compile_flags "${compile_flags} -DHAVE_QT5")
122+
elseif(CTK_QT_VERSION VERSION_EQUAL "6")
123+
set(compile_flags "${compile_flags} -DHAVE_QT6")
122124
else()
123125
message(FATAL_ERROR "Support for Qt${CTK_QT_VERSION} is not implemented")
124126
endif()

CMake/ctkMacroSetupPlugins.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ macro(ctkMacroSetupPlugins )
103103

104104
# Set the variable QT_INSTALLED_LIBRARY_DIR that contains all
105105
# Qt shared libraries
106-
if(CTK_QT_VERSION VERSION_EQUAL "5")
106+
if(CTK_QT_VERSION MATCHES "^(5|6)$")
107107
if(WIN32)
108108
get_target_property(_qt_moc_executable Qt${CTK_QT_VERSION}::moc LOCATION)
109109
get_filename_component(QT_INSTALLED_LIBRARY_DIR ${_qt_moc_executable} PATH)

CMake/ctkMacroSetupQt.cmake

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,19 @@
2121
#! \ingroup CMakeUtilities
2222
macro(ctkMacroSetupQt)
2323

24-
if(CTK_QT_VERSION VERSION_EQUAL "5")
24+
if(CTK_QT_VERSION MATCHES "^(5|6)$")
2525
cmake_minimum_required(VERSION 3.20.6)
2626
find_package(Qt${CTK_QT_VERSION} COMPONENTS Core)
2727

2828
set(CTK_QT_COMPONENTS Core)
2929

30+
if(CTK_QT_VERSION VERSION_GREATER "5")
31+
list(APPEND CTK_QT_COMPONENTS
32+
Core5Compat # For QRegExp used in "ctkCommandLineParser.cpp"
33+
StateMachine # For QAbstractTransition used in "ctkWorkflowTransitions.h"
34+
)
35+
endif()
36+
3037
# See https://github.com/commontk/CTK/wiki/Maintenance#updates-of-required-qt-components
3138

3239
if(CTK_LIB_Widgets
@@ -46,7 +53,9 @@ macro(ctkMacroSetupQt)
4653
OR CTK_LIB_CommandLineModules/Core
4754
OR CTK_LIB_Scripting/Python/Core_PYTHONQT_WRAP_QTXMLPATTERNS
4855
)
49-
list(APPEND CTK_QT_COMPONENTS XmlPatterns)
56+
if(CTK_QT_VERSION VERSION_EQUAL "5")
57+
list(APPEND CTK_QT_COMPONENTS XmlPatterns)
58+
endif()
5059
endif()
5160

5261
if(CTK_APP_ctkCommandLineModuleExplorer
@@ -82,6 +91,10 @@ macro(ctkMacroSetupQt)
8291

8392
if(CTK_LIB_Widgets)
8493
list(APPEND CTK_QT_COMPONENTS OpenGL)
94+
95+
if(CTK_QT_VERSION VERSION_GREATER "5")
96+
list(APPEND CTK_QT_COMPONENTS OpenGLWidgets)
97+
endif()
8598
endif()
8699

87100
if(CTK_APP_ctkCommandLineModuleExplorer
@@ -108,6 +121,10 @@ macro(ctkMacroSetupQt)
108121

109122
if(CTK_BUILD_QTDESIGNER_PLUGINS)
110123
list(APPEND CTK_QT_COMPONENTS Designer)
124+
125+
if(CTK_QT_VERSION VERSION_GREATER "5")
126+
list(APPEND CTK_QT_COMPONENTS DesignerComponentsPrivate)
127+
endif()
111128
endif()
112129

113130
if(CTK_LIB_XNAT/Core
@@ -118,18 +135,28 @@ macro(ctkMacroSetupQt)
118135
list(APPEND CTK_QT_COMPONENTS Network)
119136
endif()
120137

121-
find_package(Qt5 COMPONENTS ${CTK_QT_COMPONENTS} REQUIRED)
138+
if(CTK_QT_VERSION VERSION_EQUAL "5")
139+
find_package(Qt5 COMPONENTS ${CTK_QT_COMPONENTS} REQUIRED)
140+
mark_as_superbuild(Qt5_DIR) # Qt 5
141+
142+
set(_major ${Qt5_VERSION_MAJOR})
143+
set(_minor ${Qt5_VERSION_MINOR})
144+
set(_patch ${Qt5_VERSION_PATCH})
122145

123-
mark_as_superbuild(Qt5_DIR) # Qt 5
146+
elseif(CTK_QT_VERSION VERSION_EQUAL "6")
147+
find_package(Qt6 COMPONENTS ${CTK_QT_COMPONENTS} REQUIRED)
148+
mark_as_superbuild(Qt6_DIR) # Qt 6
149+
150+
set(_major ${Qt6_VERSION_MAJOR})
151+
set(_minor ${Qt6_VERSION_MINOR})
152+
set(_patch ${Qt6_VERSION_PATCH})
153+
endif()
124154

125155
# XXX Backward compatible way
126156
if(DEFINED CMAKE_PREFIX_PATH)
127157
mark_as_superbuild(CMAKE_PREFIX_PATH) # Qt 5
128158
endif()
129159

130-
set(_major ${Qt5_VERSION_MAJOR})
131-
set(_minor ${Qt5_VERSION_MINOR})
132-
set(_patch ${Qt5_VERSION_PATCH})
133160

134161
ctk_list_to_string(", " "${CTK_QT_COMPONENTS}" comma_separated_module_list)
135162
message(STATUS "Configuring CTK with Qt ${_major}.${_minor}.${_patch} (using modules: ${comma_separated_module_list})")

CMakeLists.txt

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,18 @@ mark_as_advanced(CTK_SUPERBUILD)
105105
#-----------------------------------------------------------------------------
106106
# Qt version
107107
#
108-
set(CTK_QT_VERSION "5" CACHE STRING "Expected Qt version")
108+
if(DEFINED Qt6_DIR)
109+
set(_default_qt_major_version "6")
110+
else()
111+
set(_default_qt_major_version "5")
112+
endif()
113+
set(CTK_QT_VERSION "${_default_qt_major_version}" CACHE STRING "Expected major Qt version")
109114
mark_as_advanced(CTK_QT_VERSION)
110-
set_property(CACHE CTK_QT_VERSION PROPERTY STRINGS 5)
115+
set_property(CACHE CTK_QT_VERSION PROPERTY STRINGS 5 6)
111116
mark_as_superbuild(CTK_QT_VERSION)
117+
if(NOT "${CTK_QT_VERSION}" MATCHES "^(5|6)$")
118+
message(FATAL_ERROR "error: CTK_QT_VERSION must be 5 or 6.")
119+
endif()
112120

113121
#-----------------------------------------------------------------------------
114122
# Output directories.
@@ -319,8 +327,17 @@ endif()
319327
#-----------------------------------------------------------------------------
320328
# QtTesting
321329
#
330+
if(CTK_QT_VERSION VERSION_EQUAL "5")
322331
option(CTK_USE_QTTESTING "Enable/Disable QtTesting" OFF)
323332
mark_as_advanced(CTK_USE_QTTESTING)
333+
else()
334+
# Forcing to OFF as "QtTesting" depends on XmlPatterns Qt component not available with Qt 6
335+
if(DEFINED CTK_USE_QTTESTING AND CTK_USE_QTTESTING)
336+
unset(CTK_USE_QTTESTING CACHE)
337+
set(CTK_USE_QTTESTING OFF)
338+
message(WARNING "Forcing option [CTK_USE_QTTESTING] to OFF as QtTesting depends on XmlPatterns Qt component not available with Qt ${CTK_QT_VERSION}")
339+
endif()
340+
endif()
324341
mark_as_superbuild(CTK_USE_QTTESTING)
325342

326343
#-----------------------------------------------------------------------------
@@ -503,6 +520,7 @@ ctk_lib_option(Visualization/VTK/Core
503520
ctk_lib_option(Visualization/VTK/Widgets
504521
"Build the VTK Widgets library" OFF)
505522

523+
if(CTK_QT_VERSION VERSION_EQUAL "5")
506524
ctk_lib_option(CommandLineModules/Core
507525
"Build the Command Line Module core library" OFF)
508526

@@ -521,6 +539,10 @@ ctk_lib_option(CommandLineModules/Backend/LocalProcess
521539
ctk_lib_option(CommandLineModules/Backend/FunctionPointer
522540
"Build the Command Line Module back-end for function pointers" OFF)
523541

542+
else()
543+
# "CommandLineModules/Core" depends on XmlPatterns Qt component not available with Qt 6
544+
endif()
545+
524546
ctk_lib_option(XNAT/Core
525547
"Build the XNAT Core library" OFF)
526548

@@ -574,6 +596,7 @@ ctk_app_option(ctkDICOMQueryRetrieve
574596
"Build the DICOM example application" OFF
575597
CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
576598

599+
if(CTK_QT_VERSION VERSION_EQUAL "5")
577600
ctk_app_option(ctkDICOMHost
578601
"Build the DICOM application host example application" OFF
579602
CTK_ENABLE_DICOMApplicationHosting AND CTK_BUILD_EXAMPLES)
@@ -585,6 +608,9 @@ ctk_app_option(ctkExampleHost
585608
ctk_app_option(ctkExampleHostedApp
586609
"Build the DICOM example application" OFF
587610
CTK_ENABLE_DICOMApplicationHosting AND CTK_BUILD_EXAMPLES)
611+
else()
612+
# "org.commontk.dah.core" depends on QtSOAP not available with Qt 6
613+
endif()
588614

589615
if(FALSE)
590616
# Since EventBusDemo depends on qxmlrpc that is lacking Qt5 support, it is excluded.
@@ -593,9 +619,15 @@ ctk_app_option(ctkEventBusDemo
593619
CTK_ENABLE_PluginFramework AND CTK_BUILD_EXAMPLES)
594620
endif()
595621

622+
if(CTK_QT_VERSION VERSION_EQUAL "5")
596623
ctk_app_option(ctkCommandLineModuleExplorer
597624
"Build the Command Line Module Explorer" OFF
598625
CTK_BUILD_EXAMPLES)
626+
else()
627+
# Forcing to OFF as XmlPatterns Qt component is not available with Qt 6
628+
unset(CTK_APP_ctkCommandLineModuleExplorer CACHE)
629+
set(CTK_APP_ctkCommandLineModuleExplorer OFF)
630+
endif()
599631

600632
# We use the CTKWidgets library together with the Qt Designer plug-in
601633
# in ctkCommandLineModuleExplorer, so enabling the options here.
@@ -672,6 +704,7 @@ ctk_plugin_option(org.commontk.plugingenerator.ui
672704
CTK_APP_ctkPluginGenerator)
673705

674706
# Plug-ins related to DICOM WG23 (Application Hosting)
707+
if(CTK_QT_VERSION VERSION_EQUAL "5")
675708
ctk_plugin_option(org.commontk.dah.core "Build the org.commontk.dah.core plugin." OFF)
676709
ctk_plugin_option(org.commontk.dah.hostedapp "Build the org.commontk.dah.hostedapp plugin." OFF
677710
CTK_ENABLE_DICOMApplicationHosting)
@@ -681,14 +714,25 @@ ctk_plugin_option(org.commontk.dah.host "Build the org.commontk.dah.host plugin.
681714
ctk_plugin_option(org.commontk.dah.exampleapp
682715
"Build the org.commontk.dah.exampleapp plugin." OFF
683716
CTK_APP_ctkExampleHostedApp)
717+
else()
718+
# "org.commontk.dah.core" depends on QtSOAP not available with Qt 6
719+
endif()
684720

721+
if(CTK_QT_VERSION VERSION_EQUAL "5")
685722
ctk_plugin_option(org.commontk.dah.cmdlinemoduleapp
686723
"Build the org.commontk.dah.cmdlinemoduleapp plugin." OFF
687724
CTK_APP_ctkCommandLineModuleApp)
725+
else()
726+
# "CommandLineModules/Core" depends on XmlPatterns Qt component not available with Qt 6
727+
endif()
688728

729+
if(CTK_QT_VERSION VERSION_EQUAL "5")
689730
ctk_plugin_option(org.commontk.dah.examplehost
690731
"Build the org.commontk.dah.examplehost plugin." OFF
691732
CTK_APP_ctkExampleHost)
733+
else()
734+
# "org.commontk.dah.core" depends on QtSOAP not available with Qt 6
735+
endif()
692736

693737
# Plug-ins related to the EventBus demo application
694738
if(FALSE)

Libs/Core/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ set(KIT_target_libraries)
129129
ctkFunctionGetTargetLibraries(KIT_target_libraries)
130130

131131
list(APPEND KIT_target_libraries Qt${CTK_QT_VERSION}::Core)
132+
if(CTK_QT_VERSION VERSION_GREATER "5")
133+
list(APPEND KIT_target_libraries
134+
Qt${CTK_QT_VERSION}::Core5Compat # For QRegExp
135+
Qt${CTK_QT_VERSION}::StateMachine # For QAbstractTransition used in "ctkWorkflow" classes
136+
)
137+
endif()
132138

133139
ctkMacroBuildLib(
134140
NAME ${PROJECT_NAME}

Libs/PluginFramework/Documentation/Snippets/EventAdmin-Intro/files.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set(_moc_files
88
)
99

1010
foreach(_moc_file ${_moc_files})
11-
if(CTK_QT_VERSION VERSION_EQUAL "5")
11+
if(CTK_QT_VERSION MATCHES "^(5|6)$")
1212
qt_wrap_cpp(snippet_src_files EventAdmin-Intro/${_moc_file}
1313
OPTIONS -f${CMAKE_CURRENT_SOURCE_DIR}/EventAdmin-Intro/${_moc_file})
1414
else()

Libs/Visualization/VTK/Widgets/target_libraries.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ set(target_libraries
1111
)
1212
if(CTK_QT_VERSION VERSION_EQUAL "5")
1313
list(APPEND target_libraries Qt5Network_LIBRARIES Qt5WebKit_LIBRARIES)
14+
elseif(CTK_QT_VERSION VERSION_EQUAL "6")
15+
list(APPEND target_libraries Qt6Network_LIBRARIES Qt6WebKit_LIBRARIES)
1416
else()
1517
message(FATAL_ERROR "Support for this Qt is not implemented")
1618
endif()

Libs/Widgets/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ list(APPEND KIT_target_libraries
247247
Qt${CTK_QT_VERSION}::Xml
248248
Qt${CTK_QT_VERSION}::OpenGL
249249
)
250+
if(CTK_QT_VERSION VERSION_GREATER "5")
251+
list(APPEND KIT_target_libraries
252+
Qt${CTK_QT_VERSION}::OpenGLWidgets
253+
)
254+
endif()
250255

251256
# A player and a translator must be added for custom Qt widgets
252257
if(CTK_USE_QTTESTING)

0 commit comments

Comments
 (0)