tde_create_translated_desktop: Add the ability to process multiple source

files to be installed in the same destination folder.

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
(cherry picked from commit 7592371d26)
v3.5.13-sru
Slávek Banko 4 years ago
parent 0368210118
commit 25375aaa87
No known key found for this signature in database
GPG Key ID: 608F5293A04BE668

@ -1584,13 +1584,13 @@ endmacro( )
macro( tde_create_translated_desktop )
unset( _src )
unset( _srcs )
unset( _arg_out_name )
unset( _arg_po_dir )
unset( _keywords_add )
unset( _po_dir )
unset( _dest )
unset( _out_name )
unset( _directive )
set( _var _src )
set( _var _srcs )
set( _keywords_desktop_default
"Name" "GenericName" "Comment" "Keywords"
"Description" "ExtraNames" "X-TDE-Submenu" )
@ -1599,8 +1599,8 @@ macro( tde_create_translated_desktop )
# found directive "SOURCE"
if( "+${_arg}" STREQUAL "+SOURCE" )
unset( _src )
set( _var _src )
unset( _srcs )
set( _var _srcs )
set( _directive 1 )
endif( )
@ -1613,8 +1613,8 @@ macro( tde_create_translated_desktop )
# found directive "PO_DIR"
if( "+${_arg}" STREQUAL "+PO_DIR" )
unset( _po_dir )
set( _var _po_dir )
unset( _arg_po_dir )
set( _var _arg_po_dir )
set( _directive 1 )
endif( )
@ -1627,8 +1627,8 @@ macro( tde_create_translated_desktop )
# found directive "OUTPUT_NAME"
if( "+${_arg}" STREQUAL "+OUTPUT_NAME" )
unset( _out_name )
set( _var _out_name )
unset( _arg_out_name )
set( _var _arg_out_name )
set( _directive 1 )
endif( )
@ -1641,6 +1641,22 @@ macro( tde_create_translated_desktop )
endforeach( )
# no source file specified!
if( NOT _srcs )
tde_message_fatal( "no source desktop file specified" )
endif( )
# OUTPUT_NAME can only be used if we have only one file
list( LENGTH _srcs _srcs_num )
if( _arg_out_name AND _srcs_num GREATER 1 )
tde_message_fatal( "OUTPUT_NAME can be supplied only with single file" )
endif( )
# if no destination directory specified, install as application link
if( NOT _dest )
set( _dest ${XDG_APPS_INSTALL_DIR} )
endif( )
# select a tool for merging desktop file translations
#
# Because some of our desktop files contain underscores in variable
@ -1681,132 +1697,131 @@ macro( tde_create_translated_desktop )
endif( )
endforeach( )
# no source file specified!
if( NOT _src )
tde_message_fatal( "no source desktop file specified" )
endif( )
get_filename_component( _basename ${_src} ABSOLUTE )
get_filename_component( _basedir ${_basename} PATH )
file( RELATIVE_PATH _basename "${CMAKE_CURRENT_SOURCE_DIR}" "${_basename}" )
# prepare the binary directory according to source directory
file( RELATIVE_PATH _binary_basedir "${CMAKE_CURRENT_SOURCE_DIR}" "${_basedir}" )
set( _binary_basedir "${CMAKE_CURRENT_BINARY_DIR}/${_binary_basedir}" )
file( MAKE_DIRECTORY "${_binary_basedir}" )
# process source files
foreach( _src IN LISTS _srcs )
# process source file as a configuration file if necessary
if( "${_src}" MATCHES "\\.cmake$" )
configure_file( ${_src} ${_basename} @ONLY )
set( ${_src} "${CMAKE_CURRENT_BINARY_DIR}/${_basename}" )
string( REGEX REPLACE "\\.cmake$" "" _basename "${_basename}" )
endif()
# get a base name and a directory
get_filename_component( _basename ${_src} ABSOLUTE )
get_filename_component( _basedir ${_basename} PATH )
file( RELATIVE_PATH _basename "${CMAKE_CURRENT_SOURCE_DIR}" "${_basename}" )
# if no output name specified, use the same as source
if( NOT _out_name )
get_filename_component( _out_name ${_basename} NAME )
endif( )
# prepare the binary directory according to source directory
file( RELATIVE_PATH _binary_basedir "${CMAKE_CURRENT_SOURCE_DIR}" "${_basedir}" )
set( _binary_basedir "${CMAKE_CURRENT_BINARY_DIR}/${_binary_basedir}" )
file( MAKE_DIRECTORY "${_binary_basedir}" )
# determine po directory
if( _po_dir )
set( _po_base ${_po_dir} )
else()
get_filename_component( _po_base ${_basename} NAME )
endif()
if( IS_ABSOLUTE ${_po_base} )
set( _po_dir ${_po_base} )
else()
if( EXISTS ${CMAKE_SOURCE_DIR}/translations/desktop_files/${_po_base} AND
IS_DIRECTORY ${CMAKE_SOURCE_DIR}/translations/desktop_files/${_po_base} )
set( _po_dir ${CMAKE_SOURCE_DIR}/translations/desktop_files/${_po_base} )
# process source file as a configuration file if necessary
if( "${_src}" MATCHES "\\.cmake$" )
configure_file( ${_src} ${_basename} @ONLY )
set( ${_src} "${CMAKE_CURRENT_BINARY_DIR}/${_basename}" )
string( REGEX REPLACE "\\.cmake$" "" _basename "${_basename}" )
endif()
elseif( EXISTS ${CMAKE_SOURCE_DIR}/po/desktop_files/${_po_base} AND
IS_DIRECTORY ${CMAKE_SOURCE_DIR}/po/desktop_files/${_po_base} )
set( _po_dir ${CMAKE_SOURCE_DIR}/po/desktop_files/${_po_base} )
# determine output name
if( _arg_out_name )
set( _out_name ${_arg_out_name} )
else()
get_filename_component( _out_name ${_basename} NAME )
endif( )
# determine po directory
if( _arg_po_dir )
set( _po_base ${_arg_po_dir} )
else()
set( _po_dir ${CMAKE_SOURCE_DIR}/translations/desktop_files )
get_filename_component( _po_base ${_basename} NAME )
endif()
if( IS_ABSOLUTE ${_po_base} )
set( _po_dir ${_po_base} )
else()
if( EXISTS ${CMAKE_SOURCE_DIR}/translations/desktop_files/${_po_base} AND
IS_DIRECTORY ${CMAKE_SOURCE_DIR}/translations/desktop_files/${_po_base} )
set( _po_dir ${CMAKE_SOURCE_DIR}/translations/desktop_files/${_po_base} )
elseif( EXISTS ${CMAKE_SOURCE_DIR}/po/desktop_files/${_po_base} AND
IS_DIRECTORY ${CMAKE_SOURCE_DIR}/po/desktop_files/${_po_base} )
set( _po_dir ${CMAKE_SOURCE_DIR}/po/desktop_files/${_po_base} )
else()
set( _po_dir ${CMAKE_SOURCE_DIR}/translations/desktop_files )
endif( )
endif( )
endif( )
# if no destination directory specified, install as application link
if( NOT _dest )
set( _dest ${XDG_APPS_INSTALL_DIR} )
endif( )
# are there any translations available?
unset( _translations )
if( EXISTS "${_po_dir}" AND IS_DIRECTORY "${_po_dir}" )
file( GLOB _translations RELATIVE "${_po_dir}" "${_po_dir}/*.po" )
endif( )
if( _translations )
# are there any translations available?
unset( _translations )
if( EXISTS "${_po_dir}" AND IS_DIRECTORY "${_po_dir}" )
file( GLOB _translations RELATIVE "${_po_dir}" "${_po_dir}/*.po" )
endif( )
if( _translations )
# prepare a full name for the target
get_filename_component( _target ${_basename} ABSOLUTE )
file( RELATIVE_PATH _target "${CMAKE_SOURCE_DIR}" "${_target}" )
string( REPLACE "/" "+" _target "${_target}-translated" )
# prepare a full name for the target
get_filename_component( _target ${_basename} ABSOLUTE )
file( RELATIVE_PATH _target "${CMAKE_SOURCE_DIR}" "${_target}" )
string( REPLACE "/" "+" _target "${_target}-translated" )
if( NOT TARGET ${_target} )
if( NOT TARGET ${_target} )
if( DESKTOP_MERGE_MSGFMT )
if( DESKTOP_MERGE_MSGFMT )
# Decide which translations to build; the ones selected in the
# LINGUAS environment variable, or all that are available.
if( DEFINED ENV{LINGUAS} )
set( _linguas "$ENV{LINGUAS}" )
else( )
string( REPLACE ".po;" " " _linguas "${_translations};" )
endif( )
# Decide which translations to build; the ones selected in the
# LINGUAS environment variable, or all that are available.
if( DEFINED ENV{LINGUAS} )
set( _linguas "$ENV{LINGUAS}" )
else( )
string( REPLACE ".po;" " " _linguas "${_translations};" )
endif( )
# prepare keywords for msgfmt
set( _keywords_arg "--keyword=" )
foreach( _keyword ${_keywords_desktop} )
list( APPEND _keywords_arg "--keyword=\"${_keyword}\"" )
endforeach( )
# prepare keywords for msgfmt
set( _keywords_arg "--keyword=" )
foreach( _keyword ${_keywords_desktop} )
list( APPEND _keywords_arg "--keyword=\"${_keyword}\"" )
endforeach( )
# merge translations command
get_filename_component( _src ${_src} ABSOLUTE )
add_custom_command(
OUTPUT ${_basename}
COMMAND ${CMAKE_COMMAND} -E env "LINGUAS=${_linguas}" ${MSGFMT_EXECUTABLE} --desktop --template ${_src} -d ${_po_dir} -o ${_basename} ${_keywords_arg}
DEPENDS ${_src}
)
# merge translations command
get_filename_component( _src ${_src} ABSOLUTE )
add_custom_command(
OUTPUT ${_basename}
COMMAND ${CMAKE_COMMAND} -E env "LINGUAS=${_linguas}" ${MSGFMT_EXECUTABLE} --desktop --template ${_src} -d ${_po_dir} -o ${_basename} ${_keywords_arg}
DEPENDS ${_src}
)
else( )
else( )
# create template for intltool-merge
file( READ ${_src} _src_data )
string( REPLACE ";" "|" _keywords_match "(${_keywords_desktop})" )
string( REGEX REPLACE "(^|\n)${_keywords_match}[ ]*=[ ]*" "\\1_\\2=" _src_data "${_src_data}" )
file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.in "${_src_data}" )
# create template for intltool-merge
file( READ ${_src} _src_data )
string( REPLACE ";" "|" _keywords_match "(${_keywords_desktop})" )
string( REGEX REPLACE "(^|\n)${_keywords_match}[ ]*=[ ]*" "\\1_\\2=" _src_data "${_src_data}" )
file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.in "${_src_data}" )
# merge translations command
add_custom_command(
OUTPUT ${_basename}
COMMAND ${INTLTOOL_MERGE_EXECUTABLE} -d ${_po_dir} ${_basename}.in ${_basename}
DEPENDS ${_src}
)
# merge translations command
add_custom_command(
OUTPUT ${_basename}
COMMAND ${INTLTOOL_MERGE_EXECUTABLE} -d ${_po_dir} ${_basename}.in ${_basename}
DEPENDS ${_src}
)
endif( )
endif( )
# merge translations target
add_custom_target( "${_target}" ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_basename} )
# merge translations target
add_custom_target( "${_target}" ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_basename} )
endif()
endif()
else( )
else( )
# just write the original file without translations
file( READ ${_src} _src_data )
file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/${_basename} "${_src_data}" )
# just write the original file without translations
file( READ ${_src} _src_data )
file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/${_basename} "${_src_data}" )
endif( )
endif( )
# install traslated desktop file
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${_basename}
RENAME ${_out_name}
DESTINATION ${_dest}
)
# install traslated desktop file
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${_basename}
RENAME ${_out_name}
DESTINATION ${_dest}
)
endforeach()
endmacro( )

Loading…
Cancel
Save