From 49e925ef472c0ce4e29a073f88b5e008fd8881c2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 27 Aug 2020 15:34:17 +0200 Subject: [PATCH] i18n: untangle translations in the executable - there's no need for a macro that is going to be used once, especially if there's only one place it can be called. - expand it in place and remove it from the installed CMake module --- CMakeModules/CalamaresAddTranslations.cmake | 36 ----------------- src/calamares/CMakeLists.txt | 44 +++++++++++++++++++-- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/CMakeModules/CalamaresAddTranslations.cmake b/CMakeModules/CalamaresAddTranslations.cmake index ed09d98f9..3556c7eda 100644 --- a/CMakeModules/CalamaresAddTranslations.cmake +++ b/CMakeModules/CalamaresAddTranslations.cmake @@ -12,42 +12,6 @@ include( CMakeParseArguments ) -# Internal macro for adding the C++ / Qt translations to the -# build and install tree. Should be called only once, from -# src/calamares/CMakeLists.txt. -macro(add_calamares_translations language) - list( APPEND CALAMARES_LANGUAGES ${ARGV} ) - - set( calamares_i18n_qrc_content "" ) - - # calamares and qt language files - foreach( lang ${CALAMARES_LANGUAGES} ) - foreach( tlsource "calamares_${lang}" "tz_${lang}" ) - if( EXISTS "${CMAKE_SOURCE_DIR}/lang/${tlsource}.ts" ) - set( calamares_i18n_qrc_content "${calamares_i18n_qrc_content}${tlsource}.qm\n" ) - list( APPEND TS_FILES "${CMAKE_SOURCE_DIR}/lang/${tlsource}.ts" ) - endif() - endforeach() - endforeach() - - set( trans_file calamares_i18n ) - set( trans_infile ${CMAKE_CURRENT_BINARY_DIR}/${trans_file}.qrc ) - set( trans_outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${trans_file}.cxx ) - - configure_file( ${CMAKE_SOURCE_DIR}/lang/calamares_i18n.qrc.in ${trans_infile} @ONLY ) - - qt5_add_translation(QM_FILES ${TS_FILES}) - - # Run the resource compiler (rcc_options should already be set) - add_custom_command( - OUTPUT ${trans_outfile} - COMMAND "${Qt5Core_RCC_EXECUTABLE}" - ARGS ${rcc_options} --format-version 1 -name ${trans_file} -o ${trans_outfile} ${trans_infile} - MAIN_DEPENDENCY ${trans_infile} - DEPENDS ${QM_FILES} - ) -endmacro() - # Installs a directory containing language-code-labeled subdirectories with # gettext data into the appropriate system directory. Allows renaming the # .mo files during install to avoid namespace clashes. diff --git a/src/calamares/CMakeLists.txt b/src/calamares/CMakeLists.txt index 604760f3a..ff7c90bcc 100644 --- a/src/calamares/CMakeLists.txt +++ b/src/calamares/CMakeLists.txt @@ -4,8 +4,6 @@ # SPDX-License-Identifier: BSD-2-Clause # -# "calamares_bin" is the main application, not to be confused with -# the target "calamares" which is the non-GUI library part. set( calamaresSources main.cpp CalamaresApplication.cpp @@ -36,9 +34,44 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ) -# Translations -add_calamares_translations( ${CALAMARES_TRANSLATION_LANGUAGES} ) +### TRANSLATIONS +# +# +set( TS_FILES "" ) +set( calamares_i18n_qrc_content "" ) +# calamares and qt language files +foreach( lang ${CALAMARES_LANGUAGES} ) + foreach( tlsource "calamares_${lang}" "tz_${lang}" ) + if( EXISTS "${CMAKE_SOURCE_DIR}/lang/${tlsource}.ts" ) + set( calamares_i18n_qrc_content "${calamares_i18n_qrc_content}${tlsource}.qm\n" ) + list( APPEND TS_FILES "${CMAKE_SOURCE_DIR}/lang/${tlsource}.ts" ) + endif() + endforeach() +endforeach() + +set( trans_file calamares_i18n ) +set( trans_infile ${CMAKE_CURRENT_BINARY_DIR}/${trans_file}.qrc ) +set( trans_outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${trans_file}.cxx ) + +configure_file( ${CMAKE_SOURCE_DIR}/lang/calamares_i18n.qrc.in ${trans_infile} @ONLY ) + +qt5_add_translation(QM_FILES ${TS_FILES}) + +# Run the resource compiler (rcc_options should already be set) +add_custom_command( + OUTPUT ${trans_outfile} + COMMAND "${Qt5Core_RCC_EXECUTABLE}" + ARGS ${rcc_options} --format-version 1 -name ${trans_file} -o ${trans_outfile} ${trans_infile} + MAIN_DEPENDENCY ${trans_infile} + DEPENDS ${QM_FILES} +) + +### EXECUTABLE +# +# "calamares_bin" is the main application, not to be confused with +# the target "calamares" which is the non-GUI library part. +# add_executable( calamares_bin ${calamaresSources} calamares.qrc ${trans_outfile} ) target_include_directories( calamares_bin PRIVATE ${CMAKE_SOURCE_DIR} ) set_target_properties(calamares_bin @@ -81,6 +114,9 @@ install( FILES ${CMAKE_SOURCE_DIR}/data/images/squid.svg DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps ) +### TESTS +# +# if( BUILD_TESTING ) # Don't install, these are just for enable_testing add_executable( loadmodule testmain.cpp )