diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -336,6 +336,30 @@ endif() #################################################### +# Handle translation catalogs of KDE Application release tarball of marble +# (for custom bundle translation handling see data/lang/README) + +# KDE Application release tarballs have the respective po files added on tarball creation, +# which are otherwise stored and edited separately on the KDE svn servers. +# Toplevel subdir "poqm/" holds all the po files which should be processed and installed as qm files +marble_install_po_files_as_qm(poqm) + +# Toplevel subdir "po/" holds all the po files which should be processed and installed as mo files +# Those are used by app and plugin code building against KI18n. +# So the respective macro ki18n_install can be used. +# Just, the macro is not available here in the toplevel CMakeLists.txt file. +# As a temporary hack (your task to improve it, dear reader :) ) the macro +# is called only from src/apps/marble-kde/CMakeLists.txt. +# That should catch 99.9 % cases of builds from released tarball, where all the +# KF5-dependant apps and plugins will be built and installed together. +# Currently these are: +# src/apps/marble-kde +# src/plasmarunner +# src/plasma/applets/worldclock +# src/plasma/wallpapers/worldmap + + +#################################################### # Install extra files install(FILES LICENSE.txt DESTINATION ${MARBLE_DATA_INSTALL_PATH}) diff --git a/MarbleMacros.cmake b/MarbleMacros.cmake --- a/MarbleMacros.cmake +++ b/MarbleMacros.cmake @@ -147,3 +147,119 @@ # just ignore it endmacro() endif() + + +# Find Qt translation tools +find_package(Qt5LinguistTools CONFIG) + +if(NOT Qt5LinguistTools_FOUND) + +# dummy implementation +function(marble_install_po_files_as_qm podir) + set(options) + set(oneValueArgs TARGET) + set(multiValueArgs) + cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(ARGS_TARGET) + if(NOT TARGET ${ARGS_TARGET}) + add_custom_target(${ARGS_TARGET}) + endif() + endif() + if (NOT IS_ABSOLUTE "${podir}") + set(podir "${CMAKE_CURRENT_SOURCE_DIR}/${podir}") + endif() + if (IS_DIRECTORY "${podir}") + message(STATUS "Will do nothing for po files in \"${podir}\", tools missing") + endif() +endfunction() + +else() + +if(TARGET Qt5::lconvert) + set(lconvert_executable Qt5::lconvert) +else() + # Qt < 5.3.1 does not define Qt5::lconvert + get_target_property(lrelease_location Qt5::lrelease LOCATION) + get_filename_component(lrelease_path ${lrelease_location} PATH) + find_program(lconvert_executable + NAMES lconvert-qt5 lconvert + PATHS ${lrelease_path} + NO_DEFAULT_PATH + ) +endif() + +function(marble_process_po_files_as_qm lang po_file) + set(options) + set(oneValueArgs TARGET) + set(multiValueArgs) + cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + # Create commands to turn po files into qm files + get_filename_component(po_file ${po_file} ABSOLUTE) + get_filename_component(filename_base ${po_file} NAME_WE) + + # Include ${lang} in build dir because we might be called multiple times + # with the same ${filename_base} + set(build_dir ${CMAKE_CURRENT_BINARY_DIR}/locale/${lang}) + set(ts_file ${build_dir}/${filename_base}.ts) + set(qm_file ${build_dir}/${filename_base}.qm) + + file(MAKE_DIRECTORY ${build_dir}) + + # lconvert from .po to .ts, then lrelease from .ts to .qm. + add_custom_command(OUTPUT ${qm_file} + COMMAND ${lconvert_executable} + ARGS -i ${po_file} -o ${ts_file} -target-language ${lang} + COMMAND Qt5::lrelease + ARGS -removeidentical -nounfinished -silent ${ts_file} -qm ${qm_file} + DEPENDS ${po_file} + ) + install( + FILES ${qm_file} + DESTINATION ${data_dir}/locale/${lang} + OPTIONAL # if not build, ignore it + ) + + if(ARGS_TARGET) + set(target_name_prefix ${ARGS_TARGET}) + else() + set(target_name_prefix translation) + endif() + string(REPLACE "@" "AT" _lang ${lang}) + set(target_name ${target_name_prefix}_${_lang}_${filename_base}) + + if(ARGS_TARGET) + add_custom_target(${target_name} DEPENDS ${qm_file}) + add_dependencies(${ARGS_TARGET} ${target_name}) + else() + add_custom_target(${target_name} ALL DEPENDS ${qm_file}) + endif() +endfunction() + + +function(marble_install_po_files_as_qm podir) + set(options) + set(oneValueArgs TARGET) + set(multiValueArgs) + cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(ARGS_TARGET) + if(NOT TARGET ${ARGS_TARGET}) + add_custom_target(${ARGS_TARGET}) + endif() + + set(target_arg TARGET ${ARGS_TARGET}) + else() + set(target_arg) + endif() + + file(GLOB po_files "${podir}/*/*.po") + foreach(po_file ${po_files}) + get_filename_component(po_dir ${po_file} DIRECTORY) + get_filename_component(lang ${po_dir} NAME) + marble_process_po_files_as_qm(${lang} ${po_file} ${target_arg}) + endforeach() +endfunction() + +endif() diff --git a/data/lang/CMakeLists.txt b/data/lang/CMakeLists.txt --- a/data/lang/CMakeLists.txt +++ b/data/lang/CMakeLists.txt @@ -1,67 +1,4 @@ # custom translation catalog , for creation of bundled binary packages # TODO: disable for builds in normal linux distri builds, to not confuse people - -# Find Qt translation tools -find_package(Qt5LinguistTools CONFIG) - -# enable target in any case -add_custom_target(bundle_translations) - -if(NOT Qt5LinguistTools_FOUND) - return() -endif() - - -if(TARGET Qt5::lconvert) - set(lconvert_executable Qt5::lconvert) -else() - # Qt < 5.3.1 does not define Qt5::lconvert - get_target_property(lrelease_location Qt5::lrelease LOCATION) - get_filename_component(lrelease_path ${lrelease_location} PATH) - find_program(lconvert_executable - NAMES lconvert-qt5 lconvert - PATHS ${lrelease_path} - NO_DEFAULT_PATH - ) -endif() - -function(marble_process_po_files_as_qm lang po_file) - # Create commands to turn po files into qm files - get_filename_component(po_file ${po_file} ABSOLUTE) - get_filename_component(filename_base ${po_file} NAME_WE) - - # Include ${lang} in build dir because we might be called multiple times - # with the same ${filename_base} - set(build_dir ${CMAKE_CURRENT_BINARY_DIR}/locale/${lang}) - set(ts_file ${build_dir}/${filename_base}.ts) - set(qm_file ${build_dir}/${filename_base}.qm) - - file(MAKE_DIRECTORY ${build_dir}) - - # lconvert from .po to .ts, then lrelease from .ts to .qm. - add_custom_command(OUTPUT ${qm_file} - COMMAND ${lconvert_executable} - ARGS -i ${po_file} -o ${ts_file} -target-language ${lang} - COMMAND Qt5::lrelease - ARGS -removeidentical -nounfinished -silent ${ts_file} -qm ${qm_file} - DEPENDS ${po_file} - ) - install( - FILES ${qm_file} - DESTINATION ${data_dir}/locale/${lang} - OPTIONAL # if not build, ignore it - ) - - string(REPLACE "@" "AT" _lang ${lang}) - set(target_name translation_${_lang}_${filename_base}) - add_custom_target(${target_name} DEPENDS ${qm_file}) - add_dependencies(bundle_translations ${target_name}) -endfunction() - -file(GLOB po_files "po/*/*.po") -foreach(po_file ${po_files}) - get_filename_component(po_dir ${po_file} DIRECTORY) - get_filename_component(lang ${po_dir} NAME) - marble_process_po_files_as_qm(${lang} ${po_file}) -endforeach() +marble_install_po_files_as_qm(po TARGET bundle_translations) diff --git a/src/apps/marble-kde/CMakeLists.txt b/src/apps/marble-kde/CMakeLists.txt --- a/src/apps/marble-kde/CMakeLists.txt +++ b/src/apps/marble-kde/CMakeLists.txt @@ -80,3 +80,7 @@ # register marble app as schemehandler install(FILES marble_geo.desktop DESTINATION ${KDE_INSTALL_APPDIR}) install(FILES marble_worldwind.desktop DESTINATION ${KDE_INSTALL_APPDIR}) + +# Handle mo-targetted translation catalogs as added for release tarballs +# see toplevel CMakeLists.txt for further explanation why it is done here +ki18n_install(${CMAKE_SOURCE_DIR}/po)