Skip to content

Commit abb6606

Browse files
jcfrkislinskjporcherhjmjohnson
committed
COMP: Add CMake configuration for Qt6 alongside Qt5
Enable building CTK with either Qt 5 or Qt 6 by updating CMake configuration and Qt component selection: * Allow `CTK_QT_VERSION` to be 5 or 6 (defaulting to 6 when `Qt6_DIR` is defined, otherwise 5), and validate its value. * Use common Qt APIs for both Qt 5 and Qt 6 where available (e.g. `qt_add_resources`, `qt_create_translation`, `qt_wrap_cpp`, plugin setup helpers). * Add required Qt 6 components when building with Qt 6, including `Core5Compat`, `StateMachine`, and `OpenGLWidgets`, while preserving existing Qt 5 behavior. * Restrict use of deprecated or Qt 5–only components: * Require `XmlPatterns` only with Qt 5. * Force `CTK_USE_QTTESTING` OFF with Qt 6, since QtTesting depends on `XmlPatterns`. * Disable CommandLine Modules components and applications that depend on `XmlPatterns` for Qt 6 builds. * Disable DICOM Application Hosting plug-ins and example applications that depend on QtSOAP for Qt 6 builds. * Update core, widgets, VTK widgets, and test CMakeLists to link against the appropriate Qt 5/Qt 6 targets based on `CTK_QT_VERSION`. 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 fa31210 commit abb6606

File tree

11 files changed

+120
-15
lines changed

11 files changed

+120
-15
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: 59 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 "CTK_QT_VERSION must be 5 or 6.")
119+
endif()
112120

113121
#-----------------------------------------------------------------------------
114122
# Output directories.
@@ -321,6 +329,14 @@ endif()
321329
#
322330
option(CTK_USE_QTTESTING "Enable/Disable QtTesting" OFF)
323331
mark_as_advanced(CTK_USE_QTTESTING)
332+
if(NOT CTK_QT_VERSION VERSION_EQUAL "5")
333+
# Forcing to OFF as "QtTesting" depends on XmlPatterns Qt component not available with Qt 6
334+
if(DEFINED CTK_USE_QTTESTING AND CTK_USE_QTTESTING)
335+
unset(CTK_USE_QTTESTING CACHE)
336+
set(CTK_USE_QTTESTING OFF)
337+
message(WARNING "Forcing option [CTK_USE_QTTESTING] to OFF as QtTesting depends on XmlPatterns Qt component not available with Qt ${CTK_QT_VERSION}")
338+
endif()
339+
endif()
324340
mark_as_superbuild(CTK_USE_QTTESTING)
325341

326342
#-----------------------------------------------------------------------------
@@ -503,6 +519,7 @@ ctk_lib_option(Visualization/VTK/Core
503519
ctk_lib_option(Visualization/VTK/Widgets
504520
"Build the VTK Widgets library" OFF)
505521

522+
if(CTK_QT_VERSION VERSION_EQUAL "5")
506523
ctk_lib_option(CommandLineModules/Core
507524
"Build the Command Line Module core library" OFF)
508525

@@ -521,6 +538,16 @@ ctk_lib_option(CommandLineModules/Backend/LocalProcess
521538
ctk_lib_option(CommandLineModules/Backend/FunctionPointer
522539
"Build the Command Line Module back-end for function pointers" OFF)
523540

541+
else()
542+
# "CommandLineModules/Core" depends on XmlPatterns Qt component not available with Qt 6
543+
set(CTK_LIB_CommandLineModules/Core OFF)
544+
set(CTK_LIB_CommandLineModules/Frontend/QtWebKit OFF)
545+
set(CTK_LIB_CommandLineModules/Frontend/QtGui OFF)
546+
set(CTK_LIB_CommandLineModules/Backend/XMLChecker OFF)
547+
set(CTK_LIB_CommandLineModules/Backend/LocalProcess OFF)
548+
set(CTK_LIB_CommandLineModules/Backend/FunctionPointer OFF)
549+
endif()
550+
524551
ctk_lib_option(XNAT/Core
525552
"Build the XNAT Core library" OFF)
526553

@@ -574,6 +601,7 @@ ctk_app_option(ctkDICOMQueryRetrieve
574601
"Build the DICOM example application" OFF
575602
CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
576603

604+
if(CTK_QT_VERSION VERSION_EQUAL "5")
577605
ctk_app_option(ctkDICOMHost
578606
"Build the DICOM application host example application" OFF
579607
CTK_ENABLE_DICOMApplicationHosting AND CTK_BUILD_EXAMPLES)
@@ -585,6 +613,12 @@ ctk_app_option(ctkExampleHost
585613
ctk_app_option(ctkExampleHostedApp
586614
"Build the DICOM example application" OFF
587615
CTK_ENABLE_DICOMApplicationHosting AND CTK_BUILD_EXAMPLES)
616+
else()
617+
# Host apps depends on "org.commontk.dah.core" which depends on QtSOAP not available with Qt 6
618+
set(CTK_APP_ctkDICOMHost OFF)
619+
set(CTK_APP_ctkExampleHost OFF)
620+
set(CTK_APP_ctkExampleHostedApp OFF)
621+
endif()
588622

589623
if(FALSE)
590624
# Since EventBusDemo depends on qxmlrpc that is lacking Qt5 support, it is excluded.
@@ -593,9 +627,14 @@ ctk_app_option(ctkEventBusDemo
593627
CTK_ENABLE_PluginFramework AND CTK_BUILD_EXAMPLES)
594628
endif()
595629

630+
if(CTK_QT_VERSION VERSION_EQUAL "5")
596631
ctk_app_option(ctkCommandLineModuleExplorer
597632
"Build the Command Line Module Explorer" OFF
598633
CTK_BUILD_EXAMPLES)
634+
else()
635+
# "ctkCommandLineModuleExplorer" depends on "CommandLineModules/Core" which depends on XmlPatterns Qt component not available with Qt 6
636+
set(CTK_APP_ctkCommandLineModuleExplorer OFF)
637+
endif()
599638

600639
# We use the CTKWidgets library together with the Qt Designer plug-in
601640
# in ctkCommandLineModuleExplorer, so enabling the options here.
@@ -672,6 +711,7 @@ ctk_plugin_option(org.commontk.plugingenerator.ui
672711
CTK_APP_ctkPluginGenerator)
673712

674713
# Plug-ins related to DICOM WG23 (Application Hosting)
714+
if(CTK_QT_VERSION VERSION_EQUAL "5")
675715
ctk_plugin_option(org.commontk.dah.core "Build the org.commontk.dah.core plugin." OFF)
676716
ctk_plugin_option(org.commontk.dah.hostedapp "Build the org.commontk.dah.hostedapp plugin." OFF
677717
CTK_ENABLE_DICOMApplicationHosting)
@@ -681,14 +721,31 @@ ctk_plugin_option(org.commontk.dah.host "Build the org.commontk.dah.host plugin.
681721
ctk_plugin_option(org.commontk.dah.exampleapp
682722
"Build the org.commontk.dah.exampleapp plugin." OFF
683723
CTK_APP_ctkExampleHostedApp)
724+
else()
725+
# "org.commontk.dah.core" and its dependent plugins depend on QtSOAP not available with Qt 6
726+
set(CTK_PLUGIN_org.commontk.dah.core OFF)
727+
set(CTK_PLUGIN_org.commontk.dah.hostedapp OFF)
728+
set(CTK_PLUGIN_org.commontk.dah.host OFF)
729+
set(CTK_PLUGIN_org.commontk.dah.exampleapp OFF)
730+
endif()
684731

732+
if(CTK_QT_VERSION VERSION_EQUAL "5")
685733
ctk_plugin_option(org.commontk.dah.cmdlinemoduleapp
686734
"Build the org.commontk.dah.cmdlinemoduleapp plugin." OFF
687735
CTK_APP_ctkCommandLineModuleApp)
736+
else()
737+
# "org.commontk.dah.cmdlinemoduleapp" depends on "CommandLineModules/Core" which depends on XmlPatterns Qt component not available with Qt 6
738+
set(CTK_PLUGIN_org.commontk.dah.cmdlinemoduleapp OFF)
739+
endif()
688740

741+
if(CTK_QT_VERSION VERSION_EQUAL "5")
689742
ctk_plugin_option(org.commontk.dah.examplehost
690743
"Build the org.commontk.dah.examplehost plugin." OFF
691744
CTK_APP_ctkExampleHost)
745+
else()
746+
# "org.commontk.dah.examplehost" depends on "org.commontk.dah.core" which depends on QtSOAP not available with Qt 6
747+
set(CTK_PLUGIN_org.commontk.dah.examplehost OFF)
748+
endif()
692749

693750
# Plug-ins related to the EventBus demo application
694751
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ 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+
# Skip workaround originally introduced to support Qt5.
16+
# See 47b34216 ("Add support for Qt5", 2013-09-20)
1417
else()
1518
message(FATAL_ERROR "Support for this Qt is not implemented")
1619
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)