You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.7 KiB

  1. #
  2. # This program source code file is part of KICAD, a free EDA CAD application.
  3. #
  4. # Copyright (C) 2021 Ian McInerney <Ian.S.McInerney@ieee.org>
  5. # Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License
  9. # as published by the Free Software Foundation; either version 2
  10. # of the License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, you may find one here:
  19. # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. # or you may search the http://www.gnu.org website for the version 2 license,
  21. # or you may write to the Free Software Foundation, Inc.,
  22. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. #
  24. # This file will translate a linux metadata file using msgfmt
  25. # It requires the following variables to be defined before its call:
  26. # MSGFMT_EXE - The executable to run
  27. # PO_DIR - The directory containing the .po files
  28. # SRC_FILE - The full path to the source file
  29. # DEST_FILE - The full path to the destination file
  30. get_filename_component( SRC_FNAME ${SRC_FILE} NAME )
  31. get_filename_component( DEST_FNAME ${DEST_FILE} NAME )
  32. get_filename_component( DEST_DIR ${DEST_FILE} DIRECTORY )
  33. # Figure out the type of file we are translating
  34. set( OPT_TYPE "" )
  35. # This requires a double \\ to properly escape the regex character for some reason.
  36. # Without it it throws an error about "Invalid escape sequence \."
  37. if( "${SRC_FNAME}" MATCHES ".*\\.desktop\\.in" )
  38. set( OPT_TYPE "--desktop" )
  39. elseif( "${SRC_FNAME}" MATCHES ".*\\.xml\\.in" )
  40. set( OPT_TYPE "--xml" )
  41. endif()
  42. # Execute the translation process
  43. execute_process(
  44. COMMAND ${MSGFMT_EXE} ${OPT_TYPE} --template=${SRC_FILE} -d ${PO_DIR} -o ${DEST_FILE}
  45. WORKING_DIRECTORY ${DEST_DIR}
  46. OUTPUT_VARIABLE _msgfmt_output
  47. ERROR_VARIABLE _msgfmt_error
  48. RESULT_VARIABLE _msgfmt_result
  49. OUTPUT_STRIP_TRAILING_WHITESPACE
  50. )
  51. # Capture the return value and parse it to see if the translation failed
  52. if( NOT ${_msgfmt_result} EQUAL 0)
  53. message( WARNING "Unable to translate file ${SRC_FNAME}\n"
  54. "Error: ${_msgfmt_error}" )
  55. # If the translation failed, just copy the file from source to destination
  56. message( STATUS "Copying file ${SRC_FNAME} to ${DEST_FNAME} instead." )
  57. execute_process( COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SRC_FILE}" "${DEST_FILE}" )
  58. endif()