FindGettext.cmake 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. FIND_PROGRAM(GETTEXT_MSGMERGE_EXECUTABLE msgmerge)
  15. FIND_PROGRAM(GETTEXT_MSGFMT_EXECUTABLE msgfmt)
  16. MACRO(GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFile)
  17. SET(_gmoFiles)
  18. GET_FILENAME_COMPONENT(_potBasename ${_potFile} NAME_WE)
  19. GET_FILENAME_COMPONENT(_absPotFile ${_potFile} ABSOLUTE)
  20. SET(_addToAll)
  21. IF(${_firstPoFile} STREQUAL "ALL")
  22. SET(_addToAll "ALL")
  23. SET(_firstPoFile)
  24. ENDIF(${_firstPoFile} STREQUAL "ALL")
  25. FOREACH (_currentPoFile ${ARGN})
  26. GET_FILENAME_COMPONENT(_absFile ${_currentPoFile} ABSOLUTE)
  27. GET_FILENAME_COMPONENT(_abs_PATH ${_absFile} PATH)
  28. GET_FILENAME_COMPONENT(_lang ${_absFile} NAME_WE)
  29. SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo)
  30. ADD_CUSTOM_COMMAND(
  31. OUTPUT ${_gmoFile}
  32. COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${_absFile} ${_absPotFile}
  33. COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_absFile}
  34. DEPENDS ${_absPotFile} ${_absFile}
  35. )
  36. INSTALL(FILES ${_gmoFile} DESTINATION share/locale/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo)
  37. SET(_gmoFiles ${_gmoFiles} ${_gmoFile})
  38. ENDFOREACH (_currentPoFile )
  39. ADD_CUSTOM_TARGET(translations ${_addToAll} DEPENDS ${_gmoFiles})
  40. ENDMACRO(GETTEXT_CREATE_TRANSLATIONS )
  41. IF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
  42. SET(GETTEXT_FOUND TRUE)
  43. ELSE (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
  44. SET(GETTEXT_FOUND FALSE)
  45. IF (GetText_REQUIRED)
  46. MESSAGE(FATAL_ERROR "GetText not found")
  47. ENDIF (GetText_REQUIRED)
  48. ENDIF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )