Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Applications/Testing/Cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ if(CTK_APP_ctkDICOMQuery AND CTK_APP_ctkDICOMRetrieve)
ctk_add_executable_utf8(ctkDICOMApplicationTest1 ctkDICOMApplicationTest1.cpp)
if(CTK_QT_VERSION VERSION_LESS "5")
target_link_libraries(ctkDICOMApplicationTest1 ${QT_LIBRARIES})
else()
elsei if(CTK_QT_VERSION VERSION_LESS "6")
Comment thread
EricAtORS marked this conversation as resolved.
Outdated
target_link_libraries(ctkDICOMApplicationTest1 Qt5::Core)
else()
target_link_libraries(ctkDICOMApplicationTest1 Qt6::Core)
endif()

ADD_TEST( NAME ctkDICOMApplicationTest1
Expand Down
4 changes: 3 additions & 1 deletion Applications/ctkExampleHost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ set(KIT_resources
# The following macro will read the target libraries from the file 'target_libraries.cmake'
ctkFunctionGetTargetLibraries(KIT_target_libraries)

if(CTK_QT_VERSION VERSION_GREATER "4")
if(CTK_QT_VERSION VERSION_GREATER "5")
list(APPEND KIT_target_libraries Qt6::Widgets)
elseif(CTK_QT_VERSION VERSION_GREATER "4")
list(APPEND KIT_target_libraries Qt5::Widgets)
endif()

Expand Down
4 changes: 3 additions & 1 deletion Applications/ctkPluginBrowser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ set(KIT_resources
# The following macro will read the target libraries from the file 'target_libraries.cmake'
ctkFunctionGetTargetLibraries(KIT_target_libraries)

if(CTK_QT_VERSION VERSION_GREATER "4")
if(CTK_QT_VERSION VERSION_GREATER "5")
list(APPEND KIT_target_libraries Qt6::Widgets)
elseif(CTK_QT_VERSION VERSION_GREATER "4")
list(APPEND KIT_target_libraries Qt5::Widgets)
endif()

Expand Down
14 changes: 8 additions & 6 deletions CMake/CMakeFindDependencyMacro.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ macro(find_dependency dep)
set(cmake_fd_version ${ARGV1})
endif()
set(cmake_fd_exact_arg)
if(${ARGC} GREATER 2)
if (NOT "${ARGV2}" STREQUAL EXACT)
if(CTK_QT_VERSION VERSION_LESS "6")
if(${ARGC} GREATER 2)
if (NOT "${ARGV2}" STREQUAL EXACT)
message(FATAL_ERROR "Invalid arguments to find_dependency")
endif()
set(cmake_fd_exact_arg EXACT)
endif()
if(${ARGC} GREATER 3)
message(FATAL_ERROR "Invalid arguments to find_dependency")
endif()
set(cmake_fd_exact_arg EXACT)
endif()
if(${ARGC} GREATER 3)
message(FATAL_ERROR "Invalid arguments to find_dependency")
endif()
set(cmake_fd_quiet_arg)
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
Expand Down
17 changes: 13 additions & 4 deletions CMake/ctkMacroBuildLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ ${${MY_EXPORT_CUSTOM_CONTENT_FROM_VARIABLE}}
# moc files can get very long and can't be resolved by the MSVC compiler.
if(CTK_QT_VERSION VERSION_GREATER "4")
foreach(moc_src ${MY_MOC_SRCS})
qt5_wrap_cpp(MY_MOC_CPP ${moc_src} OPTIONS -f${moc_src} OPTIONS -DHAVE_QT5)
qt_wrap_cpp(MY_MOC_CPP ${moc_src} OPTIONS -f${moc_src} OPTIONS "-DHAVE_QT${CTK_QT_VERSION}")
endforeach()
else()
foreach(moc_src ${MY_MOC_SRCS})
Expand All @@ -130,8 +130,15 @@ ${${MY_EXPORT_CUSTOM_CONTENT_FROM_VARIABLE}}
if(MY_GENERATE_MOC_SRCS)
QT4_GENERATE_MOCS(${MY_GENERATE_MOC_SRCS})
endif()
if(CTK_QT_VERSION VERSION_GREATER "4")
if(Qt5Widgets_FOUND)
if(CTK_QT_VERSION VERSION_GREATER "5")
if(Qt6Widgets_FOUND OR Qt6_FOUND)
qt_wrap_ui(MY_UI_CPP ${MY_UI_FORMS})
elseif(MY_UI_FORMS)
message(FATAL_ERROR "Argument UI_FORMS ignored because Qt6Widgets module was not specified")
endif()
elseif(CTK_QT_VERSION VERSION_GREATER "4")
MESSAGE(STATUS "CALLING QT WRAPUI 5")
if(Qt5Widgets_FOUND)
qt5_wrap_ui(MY_UI_CPP ${MY_UI_FORMS})
elseif(MY_UI_FORMS)
message(WARNING "Argument UI_FORMS ignored because Qt5Widgets module was not specified")
Expand All @@ -140,7 +147,9 @@ ${${MY_EXPORT_CUSTOM_CONTENT_FROM_VARIABLE}}
QT4_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
endif()
if(DEFINED MY_RESOURCES AND NOT MY_RESOURCES STREQUAL "")
if(CTK_QT_VERSION VERSION_GREATER "4")
if(CTK_QT_VERSION VERSION_GREATER "5")
qt_add_resources(MY_QRC_SRCS ${MY_RESOURCES})
elseif(CTK_QT_VERSION VERSION_GREATER "4")
qt5_add_resources(MY_QRC_SRCS ${MY_RESOURCES})
else()
QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
Expand Down
16 changes: 8 additions & 8 deletions CMake/ctkMacroBuildPlugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ macro(ctkMacroBuildPlugin)
# Add Qt include dirs and defines
include(${QT_USE_FILE})
else()
find_package(Qt5 COMPONENTS LinguistTools REQUIRED)
find_package(Qt${CTK_QT_VERSION} COMPONENTS LinguistTools REQUIRED)
endif()

# Add the library directories from the external project
Expand Down Expand Up @@ -316,16 +316,16 @@ macro(ctkMacroBuildPlugin)
endforeach()
endif()
else()
find_package(Qt5LinguistTools REQUIRED)
find_package(Qt${CTK_QT_VERSION}LinguistTools REQUIRED)
endif()

if(MY_TEST_PLUGIN AND CTK_QT_VERSION VERSION_GREATER "4")
find_package(Qt5Test REQUIRED)
if(CMAKE_VERSION VERSION_LESS 2.8.12)
target_link_libraries(${lib_name} Qt5::Test)
else()
target_link_libraries(${lib_name} PRIVATE Qt5::Test)
endif()
find_package(Qt${CTK_QT_VERSION} Test REQUIRED)
if(CMAKE_VERSION VERSION_LESS 2.8.12)
target_link_libraries(${lib_name} Qt::Test)
else()
target_link_libraries(${lib_name} PRIVATE Qt::Test)
Copy link
Copy Markdown
Contributor

@jamesobutler jamesobutler Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you've switch from Qt5::Test to Qt::Test. This versionless target support would only be possible with Qt 5.15 and Qt 6+.

Re https://doc.qt.io/qt-6/cmake-qt5-and-qt6-compatibility.html#versionless-targets

set(QT_NO_CREATE_VERSIONLESS_FUNCTIONS ON)  # Versionless functions requires Qt 5.15 and newer
set(QT_NO_CREATE_VERSIONLESS_TARGETS ON)  # Versionless targets requires Qt 5.15 and newer

Re https://doc.qt.io/qt-6/cmake-qt5-and-qt6-compatibility.html#supporting-older-qt-5-versions
Following

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${CTK_QT_VERSION} REQUIRED COMPONENTS Core)

Could you instead utilize Qt${CTK_QT_VERSION}::Test in this case? And then apply the same logic for other targets?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know that it was only for qt 5.15+ for the versionless targets. I'll fix them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you've made some changes with the versioned target, though I still see this specific place in the code and some other places with only a versionless target being used like Qt::

endif()
endif()

# Set the output directory for the plugin
Expand Down
15 changes: 10 additions & 5 deletions CMake/ctkMacroBuildQtPlugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ macro(ctkMacroBuildQtPlugin)
set(MY_QRC_SRCS "")
if(CTK_QT_VERSION VERSION_GREATER "4")
set(target)
if(Qt5Core_VERSION VERSION_GREATER "5.2.0")
if(Qt${CTK_QT_VERSION}Core_VERSION VERSION_GREATER "5.2.0")
set(target TARGET ${MY_LIBNAME})
endif()
qt5_wrap_cpp(MY_MOC_CPP ${MY_MOC_SRCS} OPTIONS -DHAVE_QT5 ${target})
qt_wrap_cpp(MY_MOC_CPP ${MY_MOC_SRCS} OPTIONS -DHAVE_QT${CTK_QT_VERSION} ${target})

if(DEFINED MY_RESOURCES)
qt5_add_resources(MY_QRC_SRCS ${MY_RESOURCES})
qt_add_resources(MY_QRC_SRCS ${MY_RESOURCES})
endif()
else()
QT4_WRAP_CPP(MY_MOC_CPP ${MY_MOC_SRCS})
Expand Down Expand Up @@ -191,7 +191,7 @@ endmacro()

macro(ctkMacroBuildQtDesignerPlugin)
if(CTK_QT_VERSION VERSION_GREATER "4")
find_package(Qt5 COMPONENTS Designer REQUIRED)
find_package(Qt${CTK_QT_VERSION} COMPONENTS Designer REQUIRED)
add_definitions(${Qt5Designer_DEFINITIONS})
include_directories(${Qt5Designer_INCLUDE_DIRS})
endif()
Expand All @@ -205,7 +205,12 @@ macro(ctkMacroBuildQtDesignerPlugin)
"SRCS;MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES" # multi value args
${ARGN}
)
target_link_libraries(${MY_NAME} Qt5::Designer)
if(CTK_QT_VERSION VERSION_GREATER "5")
target_link_libraries(${MY_NAME} Qt6::Designer)
else()
target_link_libraries(${MY_NAME} Qt5::Designer)
endif()

endif()
endmacro()

Expand Down
18 changes: 13 additions & 5 deletions CMake/ctkMacroGenerateMocs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include(MacroAddFileDependencies)

function(_ctk_generate_mocs)
if(CTK_QT_VERSION VERSION_GREATER "4")
if(Qt5_VERSION VERSION_LESS "5.15.0")
if(CTK_QT_VERSION VERSION_LESS "6")
QT5_GET_MOC_FLAGS(_moc_flags)
else()
# _moc_flags is not needed because it is internally handled
Expand All @@ -29,17 +29,19 @@ function(_ctk_generate_mocs)
endif()

set(moc_file ${CMAKE_CURRENT_BINARY_DIR}/moc_${source_name}${source_ext})

if(CTK_QT_VERSION VERSION_GREATER "4")

if(CTK_QT_VERSION VERSION_GREATER "5")
qt_generate_moc(${abs_file} ${moc_file})
elseif(CTK_QT_VERSION VERSION_GREATER "4")
if(Qt5_VERSION VERSION_LESS "5.6")
QT5_CREATE_MOC_COMMAND(${abs_file} ${moc_file} "${_moc_flags}" "" "")
elseif(Qt5_VERSION VERSION_LESS "5.15.0")
QT5_CREATE_MOC_COMMAND(${abs_file} ${moc_file} "${_moc_flags}" "" "" "")
else()
elseif(Qt5_VERSION VERSION_LESS "6")
# qt5_generate_moc internally calls qt5_get_moc_flags and ensure
# no warnings are reported.
qt5_generate_moc(${abs_file} ${moc_file})
endif()
endif()
else()
QT4_CREATE_MOC_COMMAND(${abs_file} ${moc_file} "${_moc_flags}" "" "")
endif()
Expand All @@ -56,3 +58,9 @@ endmacro()
macro(QT5_GENERATE_MOCS)
_ctk_generate_mocs(${ARGN})
endmacro()


# create a Qt5 alias
macro(QT6_GENERATE_MOCS)
_ctk_generate_mocs(${ARGN})
endmacro()
4 changes: 2 additions & 2 deletions CMake/ctkMacroSetupPlugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ macro(ctkMacroSetupPlugins )
# Qt shared libraries
if (CTK_QT_VERSION VERSION_GREATER "4")
if(WIN32)
get_target_property(_qt5_moc_executable Qt5::moc LOCATION)
get_target_property(_qt5_moc_executable Qt::moc LOCATION)
get_filename_component(QT_INSTALLED_LIBRARY_DIR ${_qt5_moc_executable} PATH)
else()
get_target_property(_qt5_core_lib Qt5::Core LOCATION)
get_target_property(_qt5_core_lib Qt::Core LOCATION)
get_filename_component(QT_INSTALLED_LIBRARY_DIR ${_qt5_core_lib} PATH)
endif()
else()
Expand Down
40 changes: 33 additions & 7 deletions CMake/ctkMacroSetupQt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,48 @@ macro(ctkMacroSetupQt)
set(CTK_QT_VERSION "4" CACHE STRING "Expected Qt version")
mark_as_advanced(CTK_QT_VERSION)

set_property(CACHE CTK_QT_VERSION PROPERTY STRINGS 4 5)
set_property(CACHE CTK_QT_VERSION PROPERTY STRINGS 4 5 6)

if(NOT (CTK_QT_VERSION VERSION_EQUAL "4" OR CTK_QT_VERSION VERSION_EQUAL "5"))
message(FATAL_ERROR "Expected value for CTK_QT_VERSION is either '4' or '5'")
if(NOT (CTK_QT_VERSION VERSION_EQUAL "4" OR CTK_QT_VERSION VERSION_EQUAL "5" OR CTK_QT_VERSION VERSION_EQUAL "6"))
message(FATAL_ERROR "Expected value for CTK_QT_VERSION is either '4' or '5' or '6'")
endif()

if(CTK_QT_VERSION VERSION_GREATER "5")
cmake_minimum_required(VERSION 2.8.12)
find_package(Qt6 COMPONENTS Core)
set(CTK_QT6_COMPONENTS Core Xml Concurrent Sql Test StateMachine Core5Compat)
# XmlPatterns
if(CTK_ENABLE_Widgets OR CTK_LIB_Widgets OR CTK_LIB_CommandLineModules/Frontend/QtGui OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
list(APPEND CTK_QT6_COMPONENTS Widgets OpenGL UiTools)
endif()
if(CTK_LIB_CommandLineModules/Frontend/QtWebKit OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
if(TARGET Qt6::WebKitWidgets)
list(APPEND CTK_QT6_COMPONENTS WebKitWidgets)
else()
list(APPEND CTK_QT6_COMPONENTS WebEngineWidgets)
endif()
endif()
if(CTK_LIB_XNAT/Core OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
list(APPEND CTK_QT6_COMPONENTS Script)
endif()
find_package(Qt6 COMPONENTS ${CTK_QT6_COMPONENTS} REQUIRED)

mark_as_superbuild(Qt6_DIR) # Qt 6

# XXX Backward compatible way
if(DEFINED CMAKE_PREFIX_PATH)
mark_as_superbuild(CMAKE_PREFIX_PATH) # Qt 6
endif()

if(CTK_QT_VERSION VERSION_GREATER "4")
elseif(CTK_QT_VERSION VERSION_GREATER "4")
cmake_minimum_required(VERSION 2.8.12)
find_package(Qt5 COMPONENTS Core)
find_package(Qt$${CTK_QT_VERSION} COMPONENTS Core)
set(CTK_QT5_COMPONENTS Core Xml XmlPatterns Concurrent Sql Test Multimedia)
if(CTK_ENABLE_Widgets OR CTK_LIB_Widgets OR CTK_LIB_CommandLineModules/Frontend/QtGui OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
list(APPEND CTK_QT5_COMPONENTS Widgets OpenGL UiTools)
endif()
if(CTK_LIB_CommandLineModules/Frontend/QtWebKit OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
if(TARGET Qt5::WebKitWidgets)
if(TARGET Qt${CTK_QT_VERSION}::WebKitWidgets)
list(APPEND CTK_QT5_COMPONENTS WebKitWidgets)
else()
list(APPEND CTK_QT5_COMPONENTS WebEngineWidgets)
Expand All @@ -47,7 +73,7 @@ macro(ctkMacroSetupQt)
if(CTK_LIB_XNAT/Core OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
list(APPEND CTK_QT5_COMPONENTS Script)
endif()
find_package(Qt5 COMPONENTS ${CTK_QT5_COMPONENTS} REQUIRED)
find_package(Qt${CTK_QT_VERSION} COMPONENTS ${CTK_QT5_COMPONENTS} REQUIRED)

mark_as_superbuild(Qt5_DIR) # Qt 5

Expand Down
92 changes: 92 additions & 0 deletions CMake/ctkMacroSetupQt.cmake.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
###########################################################################
Comment thread
EricAtORS marked this conversation as resolved.
Outdated
#
# Library: CTK
#
# Copyright (c) Kitware Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################

#! \ingroup CMakeUtilities
macro(ctkMacroSetupQt)
set(CTK_QT_VERSION "4" CACHE STRING "Expected Qt version")
mark_as_advanced(CTK_QT_VERSION)

set_property(CACHE CTK_QT_VERSION PROPERTY STRINGS 4 5)

if(NOT (CTK_QT_VERSION VERSION_EQUAL "4" OR CTK_QT_VERSION VERSION_EQUAL "5"))
message(FATAL_ERROR "Expected value for CTK_QT_VERSION is either '4' or '5'")
endif()


if(CTK_QT_VERSION VERSION_GREATER "4")
cmake_minimum_required(VERSION 2.8.12)
find_package(Qt5 COMPONENTS Core)
set(CTK_QT5_COMPONENTS Core Xml XmlPatterns Concurrent Sql Test Multimedia)
if(CTK_ENABLE_Widgets OR CTK_LIB_Widgets OR CTK_LIB_CommandLineModules/Frontend/QtGui OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
list(APPEND CTK_QT5_COMPONENTS Widgets OpenGL UiTools)
endif()
if(CTK_LIB_CommandLineModules/Frontend/QtWebKit OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
if(TARGET Qt5::WebKitWidgets)
list(APPEND CTK_QT5_COMPONENTS WebKitWidgets)
else()
list(APPEND CTK_QT5_COMPONENTS WebEngineWidgets)
endif()
endif()
if(CTK_LIB_XNAT/Core OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
list(APPEND CTK_QT5_COMPONENTS Script)
endif()
find_package(Qt5 COMPONENTS ${CTK_QT5_COMPONENTS} REQUIRED)

mark_as_superbuild(Qt5_DIR) # Qt 5

# XXX Backward compatible way
if(DEFINED CMAKE_PREFIX_PATH)
mark_as_superbuild(CMAKE_PREFIX_PATH) # Qt 5
endif()

else()
set(minimum_required_qt_version "4.6")

find_package(Qt4)

if(QT4_FOUND)

if("${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" VERSION_LESS "${minimum_required_qt_version}")
message(FATAL_ERROR "error: CTK requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}.")
endif()

set(QT_USE_QTNETWORK ON)
set(QT_USE_QTSQL ON)
set(QT_USE_QTOPENGL ON)
set(QT_USE_QTXML ON)
set(QT_USE_QTXMLPATTERNS ON)
set(QT_USE_QTTEST ${BUILD_TESTING})
include(${QT_USE_FILE})

# Set variable QT_INSTALLED_LIBRARY_DIR that will contains
# Qt shared library
set(QT_INSTALLED_LIBRARY_DIR ${QT_LIBRARY_DIR})
if(WIN32)
get_filename_component(QT_INSTALLED_LIBRARY_DIR ${QT_QMAKE_EXECUTABLE} PATH)
endif()

mark_as_superbuild(QT_QMAKE_EXECUTABLE) # Qt 4
else()
message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable")
endif()
endif()

mark_as_superbuild(CTK_QT_VERSION)
endmacro()
5 changes: 4 additions & 1 deletion Libs/CommandLineModules/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ set(KIT_resources
# The following macro will read the target libraries from the file 'target_libraries.cmake'
ctkFunctionGetTargetLibraries(KIT_target_libraries)

if(CTK_QT_VERSION VERSION_EQUAL "5")
list(APPEND KIT_target_libraries Qt::XmlPatterns)
endif()
if(CTK_QT_VERSION VERSION_GREATER "4")
list(APPEND KIT_target_libraries Qt5::XmlPatterns Qt5::Widgets Qt5::Concurrent)
list(APPEND KIT_target_libraries Qt::Widgets Qt::Concurrent)
else()
set(QT_USE_QTXMLPATTERNS 1)
include(${QT_USE_FILE})
Expand Down
Loading