cmake: translations deps handling, build translations as a library

This commit is contained in:
xiphon 2020-07-09 15:13:21 +00:00
parent d931022963
commit c9d36b1302
4 changed files with 40 additions and 13 deletions

View file

@ -514,6 +514,5 @@ if (HIDAPI_FOUND OR LibUSB_COMPILE_TEST_PASSED)
endif() endif()
add_subdirectory(translations) add_subdirectory(translations)
get_directory_property(TRANSLATIONS_QRC DIRECTORY translations DEFINITION TRANSLATIONS_QRC)
add_subdirectory(src) add_subdirectory(src)

View file

@ -6,7 +6,7 @@ add_subdirectory(model)
add_subdirectory(openpgp) add_subdirectory(openpgp)
add_subdirectory(zxcvbn-c) add_subdirectory(zxcvbn-c)
qt5_add_resources(RESOURCES ../qml.qrc ${TRANSLATIONS_QRC}) qt5_add_resources(RESOURCES ../qml.qrc)
# Compile source files (.h/.cpp) # Compile source files (.h/.cpp)
file(GLOB SOURCE_FILES file(GLOB SOURCE_FILES
@ -148,6 +148,7 @@ target_link_libraries(monero-wallet-gui
${EXTRA_LIBRARIES} ${EXTRA_LIBRARIES}
${ICU_LIBRARIES} ${ICU_LIBRARIES}
openpgp openpgp
translations
) )
if(DEVICE_TREZOR_READY) if(DEVICE_TREZOR_READY)

View file

@ -147,6 +147,8 @@ bool isOpenGL = true;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
Q_INIT_RESOURCE(translations);
// platform dependant settings // platform dependant settings
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) #if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
bool isDesktop = true; bool isDesktop = true;

View file

@ -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) file(GLOB TS_FILES *.ts)
set(QRC "<RCC><qresource prefix=\"/\">") set(QM_FILES)
set(QRC_CONTENTS "<RCC><qresource prefix=\"/\">")
foreach(TS_FILE ${TS_FILES}) foreach(TS_FILE ${TS_FILES})
get_filename_component(QM_FILE ${TS_FILE} NAME_WE) get_filename_component(QM_FILE ${TS_FILE} NAME_WE)
set(QM_FILE ${CMAKE_CURRENT_BINARY_DIR}/${QM_FILE}.qm) 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} add_custom_command(
RESULT_VARIABLE RET OUTPUT ${QM_FILE}
OUTPUT_VARIABLE OUT COMMAND ${Qt5_LRELEASE_EXECUTABLE} -compress -nounfinished -removeidentical ${TS_FILE} -qm ${QM_FILE}
ERROR_VARIABLE ERR 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) get_filename_component(QM_FILE_NAME ${QM_FILE} NAME)
string(APPEND QRC "<file>${QM_FILE_NAME}</file>") string(APPEND QRC_CONTENTS "<file>${QM_FILE_NAME}</file>")
endforeach() endforeach()
string(APPEND QRC "</qresource></RCC>") string(APPEND QRC_CONTENTS "</qresource></RCC>")
set(TRANSLATIONS_QRC ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc) 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})