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()
Is there a better solution than this?
I am using Visual Studio 16.8.5 and CMake 13.9.5.