I am looking at rewriting some CMake scripts for Qt so Qt5 and Qt6 can be used, specifically those in the VTK Examples.
I have run into a problem with Visual Studio and CMAKE_AUTOUIC. If CMAKE_AUTOUIC is set to ON, Visual Studio cannot find the ui_*.h files even though the files are in build\[projectname]\[projectname]_autogen\include_Debug and the path exists in the C/C++ additional include directories property pages for [projectname].
If I use ninja as the generator everything is OK as the ui_*.h files are in [projectname] folder.
To account for this I have had to do the following:
# Automatically use qt's moc and uic compilers.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
if (CMAKE_GENERATOR MATCHES "Visual Studio")
set(CMAKE_AUTOUIC OFF)
endif()
and
# Create code from a list of Qt designer ui files.
if(CMAKE_GENERATOR MATCHES "Visual Studio")
# We only need to do this for Visual Studio
if(qt_version EQUAL 6)
qt_wrap_ui(${KIT}_UI_Hdrs ${${KIT}_UIS})
else()
qt5_wrap_ui(${KIT}_UI_Hdrs ${${KIT}_UIS})
endif()
endif()
Actually this is not true, they are found in build/projectname]/[projectname]_autogen/include. I must have had some old files in build/[projectname] from when CMAKE_AUTOUIC was set to OFF.
So I’ll continue using the qt_wrap_ui stuff with set(CMAKE_AUTOUIC OFF).
You can get around it by adding the build/[projectname]/[projectname]_autogen/include path to include_directories command, however for Visual Studio you would need to also add ../[projectname]_autogen/include_Debug, ../[projectname]_autogen/include_Release etc.
All of the Qt5Autogen tests in CMake run and pass with the Visual Studio generators. That covers AUTOUIC for Qt5, so this is expected to work in general. Please try to narrow down the failure to a small example.
I don’t think the CMake test suite has been updated to drive those tests for Qt6 though.
gui\MainWindow.h(4,10): fatal error C1083: Cannot open include file: 'ui_MainWindow.h'
Please strip your example down further to avoid the Qt6/Qt5 switch (use Qt5 only), remove unnecessary Qt components, and remove subdirectories if possible. Then open an issue and attach the example.