FindGettext.cmake 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # - Find GNU gettext tools
  2. # This module looks for the GNU gettext tools. This module defines the
  3. # following values:
  4. # GETTEXT_MSGMERGE_EXECUTABLE: the full path to the msgmerge tool.
  5. # GETTEXT_MSGFMT_EXECUTABLE: the full path to the msgfmt tool.
  6. # GETTEXT_FOUND: True if gettext has been found.
  7. #
  8. # Additionally it provides the following macros:
  9. # GETTEXT_CREATE_TRANSLATIONS ( outputFile [ALL] file1 ... fileN )
  10. # This will create a target "translations" which will convert the
  11. # given input po files into the binary output mo file. If the
  12. # ALL option is used, the translations will also be created when
  13. # building the default target.
  14. #=============================================================================
  15. # Copyright 2007-2009 Kitware, Inc.
  16. #
  17. # Distributed under the OSI-approved BSD License (the "License");
  18. # see accompanying file Copyright.txt for details.
  19. #
  20. # This software is distributed WITHOUT ANY WARRANTY; without even the
  21. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. # See the License for more information.
  23. #=============================================================================
  24. # (To distributed this file outside of CMake, substitute the full
  25. # License text for the above reference.)
  26. FIND_PROGRAM(GETTEXT_MSGMERGE_EXECUTABLE msgmerge)
  27. FIND_PROGRAM(GETTEXT_MSGFMT_EXECUTABLE msgfmt)
  28. MACRO(GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFileArg)
  29. # make it a real variable, so we can modify it here
  30. SET(_firstPoFile "${_firstPoFileArg}")
  31. SET(_gmoFiles)
  32. GET_FILENAME_COMPONENT(_potBasename ${_potFile} NAME_WE)
  33. GET_FILENAME_COMPONENT(_absPotFile ${_potFile} ABSOLUTE)
  34. SET(_addToAll)
  35. IF(${_firstPoFile} STREQUAL "ALL")
  36. SET(_addToAll "ALL")
  37. SET(_firstPoFile)
  38. ENDIF(${_firstPoFile} STREQUAL "ALL")
  39. FOREACH (_currentPoFile ${_firstPoFile} ${ARGN})
  40. GET_FILENAME_COMPONENT(_absFile ${_currentPoFile} ABSOLUTE)
  41. GET_FILENAME_COMPONENT(_abs_PATH ${_absFile} PATH)
  42. GET_FILENAME_COMPONENT(_lang ${_absFile} NAME_WE)
  43. SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo)
  44. ADD_CUSTOM_COMMAND(
  45. OUTPUT ${_gmoFile}
  46. COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${_absFile} ${_absPotFile}
  47. COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_absFile}
  48. DEPENDS ${_absPotFile} ${_absFile}
  49. )
  50. INSTALL(FILES ${_gmoFile} DESTINATION share/locale/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo)
  51. SET(_gmoFiles ${_gmoFiles} ${_gmoFile})
  52. ENDFOREACH (_currentPoFile )
  53. ADD_CUSTOM_TARGET(translations ${_addToAll} DEPENDS ${_gmoFiles})
  54. ENDMACRO(GETTEXT_CREATE_TRANSLATIONS )
  55. IF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
  56. SET(GETTEXT_FOUND TRUE)
  57. ELSE (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
  58. SET(GETTEXT_FOUND FALSE)
  59. IF (GetText_REQUIRED)
  60. MESSAGE(FATAL_ERROR "GetText not found")
  61. ENDIF (GetText_REQUIRED)
  62. ENDIF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )