CMake Qt5 and AUTOUIC not rebuilding when .ui file touched

孤者浪人 提交于 2020-03-03 11:35:52

问题


I have a Qt5 project, using CMake with AUTOUIC, AUTOMOC, and AUTORCC.

My problem is that if I change one of the .ui files, I expect UIC to run and produce the corresponding ui_XXX.h file. It doesn't. I have the .ui files listed in my add_library(... Foo1.ui Foo2.ui) declaration.

This is on Windows with Visual Studio 2019. I am using the VS solution file produced my CMake. As far as I can tell, the only time Auto UIC runs is if it is building the library; touch any source file, and everything builds as expected. Touch just a .ui file and build, and it doesn't build anything.

Building the application on Linux works as expected.

We just migrated the project to CMake for a common build system between Windows and Linux and quirks like this are annoying some people on the team and we would like to resolve them.


回答1:


This is a known CMake issue, and has not yet been addressed at the time of writing. The issue mentions Visual Studio 2017 specifically, but the problem will be the same for other Visual Studio generators.

One work-around is to use the qt5_wrap_ui() command instead of relying on CMAKE_AUTOUIC. This way, a UIC rule is created for each .ui file explicitly listed:

qt5_wrap_ui(MY_LIB_UI_FILES Foo1.ui Foo2.ui ...)
add_library(MyLib 
    ... 
    ${MY_LIB_UI_FILES}
)


来源:https://stackoverflow.com/questions/60304171/cmake-qt5-and-autouic-not-rebuilding-when-ui-file-touched

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!