tde_create_translated_desktop: Avoid confusing paths when processing

a desktop file in a binary folder.

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
pull/68/head
Slávek Banko 4 years ago
parent 52001b9069
commit a5baa2c1ab
No known key found for this signature in database
GPG Key ID: 608F5293A04BE668

@ -1904,6 +1904,9 @@ macro( tde_create_translated_desktop )
endif( ) endif( )
endforeach( ) endforeach( )
# prepare the length of the binary path prefix
string( LENGTH "${CMAKE_BINARY_DIR}" CMAKE_BINARY_DIR_LEN )
# process source files # process source files
foreach( _src IN LISTS _srcs ) foreach( _src IN LISTS _srcs )
@ -1911,10 +1914,21 @@ macro( tde_create_translated_desktop )
get_filename_component( _basename ${_src} ABSOLUTE ) get_filename_component( _basename ${_src} ABSOLUTE )
get_filename_component( _basedir ${_basename} PATH ) get_filename_component( _basedir ${_basename} PATH )
file( RELATIVE_PATH _sourcename "${CMAKE_SOURCE_DIR}" "${_basename}" ) file( RELATIVE_PATH _sourcename "${CMAKE_SOURCE_DIR}" "${_basename}" )
string( SUBSTRING "${_basename}" 0 ${CMAKE_BINARY_DIR_LEN} _basedir_prefix )
if( ${_basedir_prefix} STREQUAL "${CMAKE_BINARY_DIR}" )
file( RELATIVE_PATH _basename "${CMAKE_CURRENT_BINARY_DIR}" "${_basename}" )
set( _binsuffix ".out" )
else( )
file( RELATIVE_PATH _basename "${CMAKE_CURRENT_SOURCE_DIR}" "${_basename}" ) file( RELATIVE_PATH _basename "${CMAKE_CURRENT_SOURCE_DIR}" "${_basename}" )
set( _binsuffix "" )
endif( )
# prepare the binary directory according to source directory # prepare the binary directory according to source directory
if( ${_basedir_prefix} STREQUAL "${CMAKE_BINARY_DIR}" )
file( RELATIVE_PATH _binary_basedir "${CMAKE_CURRENT_BINARY_DIR}" "${_basedir}" )
else( )
file( RELATIVE_PATH _binary_basedir "${CMAKE_CURRENT_SOURCE_DIR}" "${_basedir}" ) file( RELATIVE_PATH _binary_basedir "${CMAKE_CURRENT_SOURCE_DIR}" "${_basedir}" )
endif( )
set( _binary_basedir "${CMAKE_CURRENT_BINARY_DIR}/${_binary_basedir}" ) set( _binary_basedir "${CMAKE_CURRENT_BINARY_DIR}/${_binary_basedir}" )
file( MAKE_DIRECTORY "${_binary_basedir}" ) file( MAKE_DIRECTORY "${_binary_basedir}" )
@ -1957,6 +1971,7 @@ macro( tde_create_translated_desktop )
# if the translated desktop file is not installed, generate to the specified output name # if the translated desktop file is not installed, generate to the specified output name
if( "${_dest}" STREQUAL "-" ) if( "${_dest}" STREQUAL "-" )
set( _basename "${_out_name}" ) set( _basename "${_out_name}" )
set( _binsuffix "" )
get_filename_component( _out_dir "${CMAKE_CURRENT_BINARY_DIR}/${_out_name}" PATH ) get_filename_component( _out_dir "${CMAKE_CURRENT_BINARY_DIR}/${_out_name}" PATH )
file( MAKE_DIRECTORY "${_out_dir}" ) file( MAKE_DIRECTORY "${_out_dir}" )
endif( ) endif( )
@ -1994,8 +2009,8 @@ macro( tde_create_translated_desktop )
# merge translations command # merge translations command
get_filename_component( _src ${_src} ABSOLUTE ) get_filename_component( _src ${_src} ABSOLUTE )
add_custom_command( add_custom_command(
OUTPUT ${_basename} OUTPUT ${_basename}${_binsuffix}
COMMAND ${CMAKE_COMMAND} -E env "LINGUAS=${_linguas}" ${MSGFMT_EXECUTABLE} --desktop --template ${_src} -d ${_po_dir} -o ${_basename} ${_keywords_arg} COMMAND ${CMAKE_COMMAND} -E env "LINGUAS=${_linguas}" ${MSGFMT_EXECUTABLE} --desktop --template ${_src} -d ${_po_dir} -o ${_basename}${_binsuffix} ${_keywords_arg}
DEPENDS ${_src} DEPENDS ${_src}
COMMENT "Merging translations into ${_sourcename}" COMMENT "Merging translations into ${_sourcename}"
) )
@ -2010,8 +2025,8 @@ macro( tde_create_translated_desktop )
# merge translations command # merge translations command
add_custom_command( add_custom_command(
OUTPUT ${_basename} OUTPUT ${_basename}${_binsuffix}
COMMAND ${PERL_EXECUTABLE} ${INTLTOOL_MERGE_EXECUTABLE} -q -d ${_po_dir} ${_basename}.in ${_basename} COMMAND ${PERL_EXECUTABLE} ${INTLTOOL_MERGE_EXECUTABLE} -q -d ${_po_dir} ${_basename}.in ${_basename}${_binsuffix}
DEPENDS ${_src} DEPENDS ${_src}
COMMENT "Merging translations into ${_sourcename}" COMMENT "Merging translations into ${_sourcename}"
) )
@ -2019,7 +2034,7 @@ macro( tde_create_translated_desktop )
endif( ) endif( )
# merge translations target # merge translations target
add_custom_target( "${_target}" ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_basename} ) add_custom_target( "${_target}" ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_basename}${_binsuffix} )
endif() endif()
@ -2027,14 +2042,14 @@ macro( tde_create_translated_desktop )
# just write the original file without translations # just write the original file without translations
file( READ ${_src} _src_data ) file( READ ${_src} _src_data )
file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/${_basename} "${_src_data}" ) file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}${_binsuffix} "${_src_data}" )
endif( ) endif( )
# install traslated desktop file # install traslated desktop file
if( NOT "${_dest}" STREQUAL "-" ) if( NOT "${_dest}" STREQUAL "-" )
install( install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${_basename} FILES ${CMAKE_CURRENT_BINARY_DIR}/${_basename}${_binsuffix}
RENAME ${_out_name} RENAME ${_out_name}
DESTINATION ${_dest} DESTINATION ${_dest}
) )

Loading…
Cancel
Save