I asked this question in the itk forum before as I thought this might somehow be related with the way ITK depended on VTK, but it was pointed out that ITK knows nothing about Qt and that the proper solution probably lies in VTK.
Here’s the problem again:
We have project using ITK, VTK and Qt; VTK is configured to use Qt (VTK_MODULE_ENABLE_VTK_GUISupportQt = YES, VTK_MODULE_ENABLE_VTK_RenderingQt = YES, VTK_MODULE_ENABLE_VTK_ViewsQt = YES), and ITK is configured to depend on VTK (Module_ITKVtkGlue enabled), and therefore transitively gets some Qt configuration as well; however, part of the Qt settings seems to get lost somewhere. When we do find_package(ITK)
, it pulls in vtk and Qt as well, but fails with
CMake Error at C:/Tools/vtk/bin-9.1.0/lib/cmake/vtk-9.1/VTK-vtk-module-find-packages.cmake:115 (find_package):
Found package configuration file:
C:/Tools/Qt/6.5.0/msvc2019_64/lib/cmake/Qt6/Qt6Config.cmake
but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT
FOUND. Reason given by package:
Failed to find required Qt component "Widgets".
which in turn is caused by Qt6WidgetsTools component not finding its dependencies Qt6CoreTools and Qt6GuiTools.
The tedious fix for this is to each time for a new build folder require the user to manually set the Qt6(Core|Gui)Tools folder.
Slightly better is to set the Qt6(Core|Gui)Tools folders automatically from the (correctly set) Qt6_DIR in our CMakeLists.txt; however, that only works on a second CMake configure run (since the failing find_package for Qt is called inside of ITK’s find_package, and leads to the configure run erroring out prematurely).
We could search for Qt first in our project; but then, the user has to specify two library locations separately (Qt and ITK), and has to take care to specify the same Qt library that was used for the VTK build, whereas when searching for ITK first, the Qt library used there is pulled in automatically.
Does maybe somebody know of a nicer solution to this issue we can apply on our end, or a fix to VTK to avoid having to specify Qt folders multiple times?