From 0cbf5c287d3f16a9f1f5858b712f0d68fa39a369 Mon Sep 17 00:00:00 2001 From: Liu Zhangjian Date: Wed, 17 Dec 2025 13:56:48 +0800 Subject: [PATCH] fix: optimize lrelease command with additional flags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The lrelease command in the CMake build process has been enhanced with additional flags for better performance and output quality. The changes include adding -compress flag to reduce the size of generated .qm files, -nounfinished to exclude unfinished translations, and -removeidentical to remove identical translations. Additionally, a new custom target 'generate_qm' has been added to ensure all .qm files are generated as part of the build process. Influence: 1. Verify that .qm files are correctly generated during build 2. Check that translation files are smaller in size due to compression 3. Ensure unfinished translations are properly excluded from final output 4. Test that identical translations are removed to avoid redundancy 5. Confirm the generate_qm target builds all translation files as expected fix: 优化 lrelease 命令并添加额外标志 CMake 构建过程中的 lrelease 命令已通过附加标志进行增强,以提高性 能和输出质量。更改包括添加 -compress 标志以减少生成的 .qm 文件大 小,-nounfinished 以排除未完成的翻译,以及 -removeidentical 以移除相同的 翻译。此外,新增了一个自定义目标 'generate_qm',以确保所有 .qm 文件作为 构建过程的一部分被生成。 Influence: 1. 验证构建过程中 .qm 文件是否正确生成 2. 检查翻译文件是否因压缩而体积变小 3. 确保未完成的翻译被正确排除在最终输出之外 4. 测试相同的翻译是否被移除以避免冗余 5. 确认 generate_qm 目标按预期构建所有翻译文件 --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb1d333..2582635 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,12 +90,13 @@ else() set(QM_FILE "${CMAKE_CURRENT_BINARY_DIR}/${TS_FILE_NAME}.qm") add_custom_command( OUTPUT ${QM_FILE} - COMMAND lrelease ${TS_FILE} -qm ${QM_FILE} + COMMAND lrelease -compress -nounfinished -removeidentical ${TS_FILE} -qm ${QM_FILE} DEPENDS ${TS_FILE} COMMENT "Generating ${QM_FILE} from ${TS_FILE}" ) list(APPEND QM_FILES ${QM_FILE}) endforeach() + add_custom_target(generate_qm ALL DEPENDS ${QM_FILES}) endif() # 在文件开头部分添加自动 moc 处理