From c9d36b1302dc5caf2d1db03e8fb284cbb2255ace Mon Sep 17 00:00:00 2001 From: xiphon Date: Thu, 9 Jul 2020 15:13:21 +0000 Subject: [PATCH] cmake: translations deps handling, build translations as a library --- CMakeLists.txt | 1 - src/CMakeLists.txt | 3 ++- src/main/main.cpp | 2 ++ translations/CMakeLists.txt | 47 ++++++++++++++++++++++++++++--------- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b853d2cb..f8431d5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -514,6 +514,5 @@ if (HIDAPI_FOUND OR LibUSB_COMPILE_TEST_PASSED) endif() add_subdirectory(translations) -get_directory_property(TRANSLATIONS_QRC DIRECTORY translations DEFINITION TRANSLATIONS_QRC) add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 23af9a05..b73bff79 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,7 +6,7 @@ add_subdirectory(model) add_subdirectory(openpgp) add_subdirectory(zxcvbn-c) -qt5_add_resources(RESOURCES ../qml.qrc ${TRANSLATIONS_QRC}) +qt5_add_resources(RESOURCES ../qml.qrc) # Compile source files (.h/.cpp) file(GLOB SOURCE_FILES @@ -148,6 +148,7 @@ target_link_libraries(monero-wallet-gui ${EXTRA_LIBRARIES} ${ICU_LIBRARIES} openpgp + translations ) if(DEVICE_TREZOR_READY) diff --git a/src/main/main.cpp b/src/main/main.cpp index 18986409..d7788dc6 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -147,6 +147,8 @@ bool isOpenGL = true; int main(int argc, char *argv[]) { + Q_INIT_RESOURCE(translations); + // platform dependant settings #if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) bool isDesktop = true; diff --git a/translations/CMakeLists.txt b/translations/CMakeLists.txt index 8f1c0bc6..ab10fa4a 100644 --- a/translations/CMakeLists.txt +++ b/translations/CMakeLists.txt @@ -1,23 +1,48 @@ +find_package(Qt5Core REQUIRED) + +find_package(Qt5LinguistTools QUIET) +if(NOT Qt5_LRELEASE_EXECUTABLE) + find_program(Qt5_LRELEASE_EXECUTABLE lrelease REQUIRED) +endif() + file(GLOB TS_FILES *.ts) -set(QRC "") +set(QM_FILES) +set(QRC_CONTENTS "") foreach(TS_FILE ${TS_FILES}) get_filename_component(QM_FILE ${TS_FILE} NAME_WE) set(QM_FILE ${CMAKE_CURRENT_BINARY_DIR}/${QM_FILE}.qm) + list(APPEND QM_FILES ${QM_FILE}) - execute_process(COMMAND lrelease -compress -nounfinished -removeidentical ${TS_FILE} -qm ${QM_FILE} - RESULT_VARIABLE RET - OUTPUT_VARIABLE OUT - ERROR_VARIABLE ERR + add_custom_command( + OUTPUT ${QM_FILE} + COMMAND ${Qt5_LRELEASE_EXECUTABLE} -compress -nounfinished -removeidentical ${TS_FILE} -qm ${QM_FILE} + DEPENDS ${TS_FILE} ) - if(RET) - message(FATAL_ERROR "${TS_FILE}: lrelease returned non-zero exit code: ${RET} ${OUT} ${ERR}") - endif() get_filename_component(QM_FILE_NAME ${QM_FILE} NAME) - string(APPEND QRC "${QM_FILE_NAME}") + string(APPEND QRC_CONTENTS "${QM_FILE_NAME}") endforeach() -string(APPEND QRC "") +string(APPEND QRC_CONTENTS "") set(TRANSLATIONS_QRC ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc) -file(WRITE ${TRANSLATIONS_QRC} ${QRC}) +add_custom_command( + OUTPUT ${TRANSLATIONS_QRC} + COMMAND echo ${QRC_CONTENTS} > ${TRANSLATIONS_QRC} + VERBATIM +) +set_source_files_properties(${TRANSLATIONS_QRC} PROPERTIES SKIP_AUTORCC ON) + +set(TRANSLATIONS_CPP ${CMAKE_CURRENT_BINARY_DIR}/qrc_translations.cpp) +add_custom_command( + OUTPUT ${TRANSLATIONS_CPP} + COMMAND ${Qt5Core_RCC_EXECUTABLE} + ARGS --name translations --output ${TRANSLATIONS_CPP} ${TRANSLATIONS_QRC} + MAIN_DEPENDENCY ${TRANSLATIONS_QRC} + DEPENDS ${QM_FILES} + VERBATIM +) +set_source_files_properties(${TRANSLATIONS_CPP} PROPERTIES SKIP_AUTOMOC ON) +set_source_files_properties(${TRANSLATIONS_CPP} PROPERTIES SKIP_AUTOUIC ON) + +add_library(translations ${TRANSLATIONS_CPP})