触摸.ui文件时CMake Qt5和AUTOUIC无法重建 [英] CMake Qt5 and AUTOUIC not rebuilding when .ui file touched

查看:704
本文介绍了触摸.ui文件时CMake Qt5和AUTOUIC无法重建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Qt5项目,使用CMake和 AUTOUIC AUTOMOC AUTORCC

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

我的问题是,如果我更改一个.ui文件,我希望UIC运行并生成相应的ui_XXX.h文件。没错我在 add_library(... Foo1.ui Foo2.ui)声明中列出了.ui文件。

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.

这是在Windows上使用Visual Studio 2019的情况。我使用的是CMake产生的VS解决方案文件。据我所知,Auto UIC唯一的运行时间是它是否正在构建库。触摸任何源文件,一切都会按预期进行。只需触摸.ui文件并进行构建,它就不会构建任何内容。

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.

在Linux上构建应用程序的工作符合预期。

Building the application on Linux works as expected.

我们刚刚将项目迁移到CMake,以便在Windows和Linux之间建立一个通用的构建系统,这样的怪癖使团队中的某些人感到烦恼,我们想解决这些问题。

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.

推荐答案

这是已知的CMake 问题,并且在撰写本文时尚未得到解决。该问题专门提到了Visual Studio 2017,但其他Visual Studio生成器的问题相同。

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.

一种解决方法是使用 qt5_wrap_ui() 命令,而不是依赖 CMAKE_AUTOUIC 。这样,将为每个明确列出的 .ui 文件创建一个UIC规则:

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}
)

这篇关于触摸.ui文件时CMake Qt5和AUTOUIC无法重建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆