From 34c1a1e96ba58769d8123228a0111ccbc89790e0 Mon Sep 17 00:00:00 2001 From: sudden6 Date: Thu, 21 May 2020 23:25:10 +0200 Subject: [PATCH] refactor(cmake): fix missing dependency --- translations/CMakeLists.txt | 41 +++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/translations/CMakeLists.txt b/translations/CMakeLists.txt index f2b48831e..f5a37ae8b 100644 --- a/translations/CMakeLists.txt +++ b/translations/CMakeLists.txt @@ -60,23 +60,28 @@ qt5_add_translation(translations_FILES zh_TW.ts ) -file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/translations.qrc.in" -" - - -") -foreach(qm ${translations_FILES}) - get_filename_component(qm_name ${qm} NAME) - file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/translations.qrc.in" - " ${qm}\n") -endforeach(qm) -file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/translations.qrc.in" -" - -") +# Generate a resource file which contains all translation files +function(generate_translation_resource) + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/translations.qrc.in" + " + + + ") + foreach(qm ${translations_FILES}) + get_filename_component(qm_name ${qm} NAME) + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/translations.qrc.in" + " ${qm}\n") + endforeach(qm) + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/translations.qrc.in" + " + + ") +endfunction() -execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc.in - ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc) +generate_translation_resource() +configure_file(${CMAKE_CURRENT_BINARY_DIR}/translations.qrc.in ./translations.qrc COPYONLY) -add_library(translations_library ${translations_FILES} ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc) +add_library(translations_library ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc) + +# An explicit dependency is needed or AUTORCC will run before the translation files are created +set_target_properties(translations_library PROPERTIES AUTOGEN_TARGET_DEPENDS "${translations_FILES}")