Skip to content
Snippets Groups Projects

Add qt6

All threads resolved!
Merged Andrew Maclean requested to merge Add-Qt6 into master
All threads resolved!
Files
4
+ 47
24
@@ -15,26 +15,42 @@ find_package(VTK COMPONENTS ZZZ
QUIET
)
if (NOT VTK_FOUND)
message("Skipping XXX: ${VTK_NOT_FOUND_MESSAGE}")
return ()
if(NOT VTK_FOUND)
message(FATAL_ERROR "XXX: ${VTK_NOT_FOUND_MESSAGE}")
endif()
message (STATUS "VTK_VERSION: ${VTK_VERSION}")
if(vtkGUISupportQt_LOADED OR TARGET VTK::GUISupportQt)
if (VTK_VERSION VERSION_LESS "8.90.0")
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
else()
# Instruct CMake to run moc and uic automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
endif()
# We have ui files, this will bring in the macro: qt5_wrap_ui
find_package(Qt5Widgets REQUIRED QUIET)
if(NOT(vtkGUISupportQt_LOADED OR TARGET VTK::GUISupportQt))
message(FATAL_ERROR "XXX: VTK not built with Qt support.")
endif()
if(NOT DEFINED VTK_QT_VERSION)
set(VTK_QT_VERSION 5)
endif()
set(qt_components Core Gui Widgets)
if(${VTK_QT_VERSION} VERSION_GREATER_EQUAL 6)
list(APPEND qt_components OpenGLWidgets)
endif()
list(SORT qt_components)
# We have ui files, so this will also bring in the macro:
# qt5_wrap_ui or qt_wrap_ui from Widgets.
find_package(Qt${VTK_QT_VERSION} QUIET
REQUIRED COMPONENTS ${qt_components}
)
foreach(_qt_comp IN LISTS qt_components)
list(APPEND qt_modules "Qt${VTK_QT_VERSION}::${_qt_comp}")
endforeach()
message (STATUS "VTK_VERSION: ${VTK_VERSION}, Qt Version: ${Qt${VTK_QT_VERSION}Widgets_VERSION}")
if (VTK_VERSION VERSION_LESS "8.90.0")
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
else()
message(STATUS "GuiSupportQt not found.")
return()
# Instruct CMake to run moc and uic automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
@@ -43,7 +59,14 @@ file(GLOB UI_FILES *.ui)
file(GLOB QT_WRAP *.h)
file(GLOB CXX_FILES *.cxx)
qt5_wrap_ui(UISrcs ${UI_FILES})
# For VTK versions greater than or equal to 8.90.0:
# CMAKE_AUTOUIC is ON so we handle uic automatically for Qt targets.
# CMAKE_AUTOMOC is ON so we handle moc automatically for Qt targets.
# However we have to do the following for VTK versions less than 8.90.0,
# and we also assume, in this case, that Qt5 is being used.
if (VTK_VERSION VERSION_LESS "8.90.0")
qt5_wrap_ui(UISrcs ${EXAMPLE}.ui)
endif()
if (VTK_VERSION VERSION_LESS "8.90.0")
# old system
@@ -51,20 +74,20 @@ if (VTK_VERSION VERSION_LESS "8.90.0")
# CMAKE_AUTOMOC in ON so the MOC headers will be automatically wrapped.
add_executable(XXX MACOSX_BUNDLE
${CXX_FILES} ${UISrcs} ${QT_WRAP})
if (Qt5Widgets_VERSION VERSION_LESS "5.11.0")
qt5_use_modules(XXX Core Gui Widgets)
if (Qt${VTK_QT_VERSION}Widgets_VERSION VERSION_LESS "5.11.0")
qt5_use_modules(XXX ${qt_components})
else()
target_link_libraries(XXX Qt5::Core Qt5::Gui Qt5::Widgets)
target_link_libraries(XXX ${qt_modules})
endif()
target_link_libraries(XXX ${VTK_LIBRARIES})
else()
# CMAKE_AUTOMOC in ON so the MOC headers will be automatically wrapped.
add_executable(XXX MACOSX_BUNDLE
${CXX_FILES} ${UISrcs} ${QT_WRAP})
if (Qt5Widgets_VERSION VERSION_LESS "5.11.0")
qt5_use_modules(XXX Core Gui Widgets)
if (Qt${VTK_QT_VERSION}Widgets_VERSION VERSION_LESS "5.11.0")
qt5_use_modules(XXX ${qt_components})
else()
target_link_libraries(XXX Qt5::Core Qt5::Gui Qt5::Widgets)
target_link_libraries(XXX ${qt_modules})
endif()
target_link_libraries(XXX ${VTK_LIBRARIES})
# vtk_module_autoinit is needed
Loading