From 438302fcf5b6ae26459613e73c8c7695c23fc491 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 7 Sep 2021 16:31:24 +0200 Subject: [PATCH] i18n: Shuffle the build so that all the bits are in lang/ Move the CMake code responsible for building the translations from the src/calamares directory (yeah, yeah, the translations need to link into the executable) into lang/ (which is where the source and other infrastructure lives). --- CMakeLists.txt | 5 +++- lang/CMakeLists.txt | 44 ++++++++++++++++++++++++++++++++++++ src/calamares/CMakeLists.txt | 39 ++++---------------------------- 3 files changed, 53 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 99ee4330e..b4ac77946 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -404,7 +404,10 @@ set(Calamares_WITH_QML ${WITH_QML}) ### Transifex Translation status # -# Construct language lists for use. +# Construct language lists for use. This massages the language lists +# for use with older Qt (which does not support Esperanto) and checks +# for some obvious error. The actual work of compiling translations +# is done in the lang/ directory. # if( Qt5_VERSION VERSION_GREATER 5.12.1 ) # At least Qt 5.12.2 seems to support Esperanto in QLocale diff --git a/lang/CMakeLists.txt b/lang/CMakeLists.txt index 8658653ab..72aae9588 100644 --- a/lang/CMakeLists.txt +++ b/lang/CMakeLists.txt @@ -4,6 +4,14 @@ # SPDX-License-Identifier: BSD-2-Clause # ### +# +# This CMakeList handles the following i18n / language targets: +# +# - creating a translation test-tool +# - building the Python (gettext-based) translations +# - compiling all the Qt translations into a C++ file calamares-i18n.cxx +# - defines an OBJECT LIBRARY calamares-i18n for linking the compiled +# translations into an executable. include( CalamaresAddTranslations ) @@ -18,3 +26,39 @@ install_calamares_gettext_translations( python FILENAME python.mo RENAME calamares-python.mo ) + +### TRANSLATIONS +# +# +set( TS_FILES "" ) +set( calamares_i18n_qrc_content "" ) + +# calamares and qt language files +foreach( lang ${CALAMARES_TRANSLATION_LANGUAGES} ) + foreach( tlsource "calamares_${lang}" "tz_${lang}" "kb_${lang}" ) + if( EXISTS "${CMAKE_SOURCE_DIR}/lang/${tlsource}.ts" ) + string( APPEND 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}/calamares-i18n.cxx ) +set( CALAMARES_TRANSLATIONS_SOURCE ${trans_outfile} ) + +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} +) + +add_library(calamares-i18n OBJECT ${trans_outfile}) diff --git a/src/calamares/CMakeLists.txt b/src/calamares/CMakeLists.txt index cf00dca37..d06a53d83 100644 --- a/src/calamares/CMakeLists.txt +++ b/src/calamares/CMakeLists.txt @@ -34,45 +34,15 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ) -### TRANSLATIONS -# -# -set( TS_FILES "" ) -set( calamares_i18n_qrc_content "" ) - -# calamares and qt language files -foreach( lang ${CALAMARES_TRANSLATION_LANGUAGES} ) - foreach( tlsource "calamares_${lang}" "tz_${lang}" "kb_${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} ) +# The calamares-i18n.cxx file -- full path in CALAMARES_TRANSLATIONS_SOURCE -- +# is created as a target in the lang/ directory. This is compiled to a +# library (it's just the result of a QRC compile). +add_executable( calamares_bin ${calamaresSources} calamares.qrc ) target_include_directories( calamares_bin PRIVATE ${CMAKE_SOURCE_DIR} ) set_target_properties(calamares_bin PROPERTIES @@ -91,6 +61,7 @@ target_link_libraries( calamares_bin PRIVATE calamares calamaresui + calamares-i18n Qt5::Core Qt5::Widgets KF5::CoreAddons