CMake + Qt转换系统的正确工作流程 [英] A proper workflow for CMake + Qt translation system
问题描述
我最近将我的Qt项目qmake从qmake移到了CMake构建系统,现在我正在尝试建立翻译系统。我尝试使用 qt5_create_translation
宏(记录为此处)更新我的* .ts文件并生成* .qm文件。默认情况下,宏在源目录中创建(或更新)*。ts文件,在构建目录中创建* .qm文件,这非常合逻辑且易于使用。底层 lupdate
实用程序的性质使得* .ts文件不能被破坏-它们只能被更新。因此,我的工作流程如下:
I recently moved my Qt project form qmake to CMake build system and now I'm trying to set up a translation system. I tried to use qt5_create_translation
macro (documented here) to update my *.ts files and generate *.qm files. By default the macro creates (or updates) *.ts files in the source directory and *.qm files in the build directory, which is pretty logical and convenient to use. The nature of underlying lupdate
utility is such that *.ts files cannot be destroyed - they may be updated only. So I see my workflow as follows:
- 添加或修改源文件或UI文件。
- 重建该项目:新的可翻译字符串将添加到* .ts文件中。
- 立即将实际翻译添加到* .ts或按原样提交更改,以便以后添加翻译。 / li>
- 将翻译添加到* .ts中后,立即重建项目以获取最新的* .qm文件。
通过此工作流程,*。ts文件几乎总是与源文件同步,并且每次构建项目时都会生成* .qm文件。但是CMake和/或Qt5插件的思想是另一种方式。 CMake正确地将* .ts文件视为构建工件,因此它会生成一条规则,以从 make clean
删除它们(从源树(!))。此行为至少是 tw ice 已注册为错误,但维护者似乎坚持认为这不是错误,而是功能。
With this workflow *.ts files are almost always synchronized with source files and *.qm files are generated every time you build the project. But the ideology of CMake and/or Qt5 plugin for CMake follows another way. CMake rightly accounts *.ts files as build artifacts, so it generates a rule to delete them (from source tree (!)) on make clean
. This behavior was at least twice registered as a bug, but maintainers seem to insist it's not a bug, but a feature.
我找到了建议添加带有翻译和 CLEAN_NO_CUSTOM
的子目录,但是这些修改破坏了构建:向可执行目标添加* .qm文件不会将子目录添加到可执行文件依赖项列表。因此,构建构建无法找到* .qm文件并停止。
I found an advice to add a subdirectory with translations and CLEAN_NO_CUSTOM
on it, but these modifications break the build: adding *.qm file to executable target does not add the subdirectory to executable dependency list. So build build fails to find *.qm files and stops.
添加自定义CMake目标和命令或调用 lupdate
贬低了 Qt5LinguistTools
模块和 qt5_create_translation
宏的所有优势。
Adding custom CMake target and\or command invoking lupdate
derogates all advantages of Qt5LinguistTools
module and qt5_create_translation
macro.
添加CMake选项,例如此处看起来很丑陋,无法解决开发人员的问题在打开 UPDATE_TRANSLATIONS
时意外调用 make clean
会丢失未提交的翻译。
Adding a CMake option like here looks like an ugly workaround and does not keep the developer from loosing uncommitted translation by accidental invocation of make clean
when UPDATE_TRANSLATIONS
is turned on.
那么将 qt5_create_translation
宏用于当前行为的正确方法是什么?
So what is the proper way to use qt5_create_translation
macro with it's present-day behavior?
推荐答案
,无需做ADD_SUBDIRECTORY
,
我只需添加 SET_DIRECTORY_PROPERTIES(PROPERTIES CLEAN_NO_CUSTOM TRUE)
在致电
QT5_CREATE_TRANSLATION
这篇关于CMake + Qt转换系统的正确工作流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!