From 5fe1ae8d6b1197aef782ebf9af4d8e072aa3a8ff Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Thu, 8 Sep 2022 10:50:37 +0200 Subject: BUILD(cmake): Don't always recompile mumble_translations.qrc --- cmake/qt-utils.cmake | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/cmake/qt-utils.cmake b/cmake/qt-utils.cmake index 811c0146c..2b0207a38 100644 --- a/cmake/qt-utils.cmake +++ b/cmake/qt-utils.cmake @@ -59,18 +59,37 @@ function(include_translations OUT_VAR OUT_DIR TS_FILES) compile_translations(QM_FILES "${OUT_DIR}" "${TS_FILES}") set(QRC_PATH "${OUT_DIR}/mumble_translations.qrc") + set(TMP_PATH "${QRC_PATH}.tmp") # Create a resource file (.qrc) containing the name of the compiled translation files (.qm). # This is required in order to embed those files into the built executable. # NOTE: We write the files' name instead of their path because they are in the same directory as the resource file. - file(WRITE ${QRC_PATH} "\n\n") + file(WRITE ${TMP_PATH} "\n\n") foreach(QM_FILE ${QM_FILES}) get_filename_component(FILENAME ${QM_FILE} NAME) - file(APPEND ${QRC_PATH} "\t${FILENAME}\n") + file(APPEND ${TMP_PATH} "\t${FILENAME}\n") endforeach() - file(APPEND ${QRC_PATH} "\n\n") + file(APPEND ${TMP_PATH} "\n\n") + + if(EXISTS "${QRC_PATH}") + # The QRC file already exists - there's a chance that it has been generated before already and that + # its contents have not changed. In this case, we don't want to overwrite it, as to not suggest to + # cmake that it has changed and that it needs to be recompiled. + execute_process(COMMAND "${CMAKE_COMMAND}" -E compare_files "${TMP_PATH}" "${QRC_PATH}" RESULT_VARIABLE COMP_RESULT) + + if(COMP_RESULT EQUAL 0) + # Files are equal -> Don't overwrite + elseif(COMP_RESULT 1) + # Files are different -> overwrite + file(RENAME "${TMP_PATH}" "${QRC_PATH}") + else() + message(FATAL_ERROR "Encountered error while comparing files \"${QRC_PATH}\" and \"${TMP_PATH}\"") + endif() + else() + file(RENAME "${TMP_PATH}" "${QRC_PATH}") + endif() set("${OUT_VAR}" "${QRC_PATH}" PARENT_SCOPE) endfunction() -- cgit v1.2.3