Skip to content

Commit 771c14b

Browse files
committed
COMP: Generalize macros to support Qt6 based on CTK_QT_VERSION
This change updates various CMake macros to handle Qt6 by using CTK_QT_VERSION. It replaces hardcoded Qt5 references with version-agnostic code where possible.
1 parent 52ee397 commit 771c14b

8 files changed

Lines changed: 23 additions & 23 deletions

File tree

CMake/ctkFunctionGeneratePluginManifest.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function(ctkFunctionGeneratePluginManifest MANIFEST_QRC_FILEPATH_VAR)
105105
set(${MANIFEST_QRC_FILEPATH_VAR} ${_manifest_qrc_filepath} PARENT_SCOPE)
106106
else()
107107
if(CTK_QT_VERSION VERSION_EQUAL "5")
108-
QT5_ADD_RESOURCES(_qrc_src ${_manifest_qrc_filepath})
108+
qt_add_resources(_qrc_src ${_manifest_qrc_filepath})
109109
else()
110110
message(FATAL_ERROR "Support for Qt${CTK_QT_VERSION} is not implemented")
111111
endif()

CMake/ctkMacroBuildPlugin.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ macro(ctkMacroBuildPlugin)
194194
set_source_files_properties(${MY_TRANSLATIONS}
195195
PROPERTIES OUTPUT_LOCATION ${_translations_dir})
196196
if(CTK_QT_VERSION VERSION_EQUAL "5")
197-
qt5_create_translation(_plugin_qm_files ${MY_SRCS} ${MY_UI_FORMS} ${MY_TRANSLATIONS})
197+
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")
200200
endif()

CMake/ctkMacroBuildQtPlugin.cmake

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ macro(ctkMacroBuildQtPlugin)
172172
endmacro()
173173

174174
macro(ctkMacroBuildQtDesignerPlugin)
175+
find_package(Qt${CTK_QT_VERSION} COMPONENTS Designer REQUIRED)
175176
if(CTK_QT_VERSION VERSION_EQUAL "5")
176-
find_package(Qt5 COMPONENTS Designer REQUIRED)
177177
add_definitions(${Qt5Designer_DEFINITIONS})
178178
include_directories(${Qt5Designer_INCLUDE_DIRS})
179179
else()
@@ -182,17 +182,13 @@ macro(ctkMacroBuildQtDesignerPlugin)
182182
ctkMacroBuildQtPlugin(
183183
PLUGIN_DIR designer
184184
${ARGN})
185-
if(CTK_QT_VERSION VERSION_EQUAL "5")
186-
cmake_parse_arguments(MY
187-
"" # no options
188-
"NAME;EXPORT_DIRECTIVE;FOLDER;PLUGIN_DIR" # one value args
189-
"SRCS;MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES" # multi value args
190-
${ARGN}
191-
)
192-
target_link_libraries(${MY_NAME} Qt5::Designer)
193-
else()
194-
message(FATAL_ERROR "Support for Qt${CTK_QT_VERSION} is not implemented")
195-
endif()
185+
cmake_parse_arguments(MY
186+
"" # no options
187+
"NAME;EXPORT_DIRECTIVE;FOLDER;PLUGIN_DIR" # one value args
188+
"SRCS;MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES" # multi value args
189+
${ARGN}
190+
)
191+
target_link_libraries(${MY_NAME} Qt${CTK_QT_VERSION}::Designer)
196192
endmacro()
197193

198194
macro(ctkMacroBuildQtIconEnginesPlugin)

CMake/ctkMacroSetupPlugins.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ macro(ctkMacroSetupPlugins )
105105
# Qt shared libraries
106106
if(CTK_QT_VERSION VERSION_EQUAL "5")
107107
if(WIN32)
108-
get_target_property(_qt5_moc_executable Qt5::moc LOCATION)
109-
get_filename_component(QT_INSTALLED_LIBRARY_DIR ${_qt5_moc_executable} PATH)
108+
get_target_property(_qt_moc_executable Qt${CTK_QT_VERSION}::moc LOCATION)
109+
get_filename_component(QT_INSTALLED_LIBRARY_DIR ${_qt_moc_executable} PATH)
110110
else()
111-
get_target_property(_qt5_core_lib Qt5::Core LOCATION)
112-
get_filename_component(QT_INSTALLED_LIBRARY_DIR ${_qt5_core_lib} PATH)
111+
get_target_property(_qt_core_lib Qt${CTK_QT_VERSION}::Core LOCATION)
112+
get_filename_component(QT_INSTALLED_LIBRARY_DIR ${_qt_core_lib} PATH)
113113
endif()
114114
else()
115115
message(FATAL_ERROR "Support for Qt${CTK_QT_VERSION} is not implemented")

CMake/ctkMacroSetupQt.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ macro(ctkMacroSetupQt)
2323

2424
if(CTK_QT_VERSION VERSION_EQUAL "5")
2525
cmake_minimum_required(VERSION 3.20.6)
26-
find_package(Qt5 COMPONENTS Core)
26+
find_package(Qt${CTK_QT_VERSION} COMPONENTS Core)
2727

2828
set(CTK_QT_COMPONENTS Core)
2929

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

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

1010
foreach(_moc_file ${_moc_files})
1111
if(CTK_QT_VERSION VERSION_EQUAL "5")
12-
QT5_WRAP_CPP(snippet_src_files EventAdmin-Intro/${_moc_file}
12+
qt_wrap_cpp(snippet_src_files EventAdmin-Intro/${_moc_file}
1313
OPTIONS -f${CMAKE_CURRENT_SOURCE_DIR}/EventAdmin-Intro/${_moc_file})
1414
else()
1515
message(FATAL_ERROR "Support for Qt${CTK_QT_VERSION} is not implemented")

Libs/Widgets/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,11 @@ set(KIT_resources
242242
# The following macro will read the target libraries from the file 'target_libraries.cmake'
243243
ctkFunctionGetTargetLibraries(KIT_target_libraries)
244244

245-
list(APPEND KIT_target_libraries Qt5::Widgets Qt5::Xml Qt5::OpenGL)
245+
list(APPEND KIT_target_libraries
246+
Qt${CTK_QT_VERSION}::Widgets
247+
Qt${CTK_QT_VERSION}::Xml
248+
Qt${CTK_QT_VERSION}::OpenGL
249+
)
246250

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

Libs/Widgets/Testing/Cpp/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ set_target_properties(${KIT}CppTests PROPERTIES
225225
)
226226

227227
if(CTK_QT_VERSION VERSION_EQUAL "5")
228-
list(APPEND KIT_target_libraries Qt5::Test)
228+
list(APPEND KIT_target_libraries Qt${CTK_QT_VERSION}::Test)
229229
if(CTK_USE_QTTESTING)
230-
list(APPEND KIT_target_libraries Qt5::Xml Qt5::XmlPatterns)
230+
list(APPEND KIT_target_libraries Qt${CTK_QT_VERSION}::Xml Qt${CTK_QT_VERSION}::XmlPatterns)
231231
endif()
232232
target_link_libraries(${KIT}CppTests ${KIT_target_libraries})
233233
else()

0 commit comments

Comments
 (0)