CMakeLists.txt 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. FIND_PACKAGE(Gettext REQUIRED)
  2. # based on the CMake 2.6.3 GETTEXT_CREATE_TRANSLATIONS
  3. # we need our own version because the upstream one contains
  4. # a call to msgmerge (updating po files) which can't be
  5. # disabled
  6. MACRO(MANAPLUS_GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFileArg)
  7. # make it a real variable, so we can modify it here
  8. SET(_firstPoFile "${_firstPoFileArg}")
  9. SET(_gmoFiles)
  10. GET_FILENAME_COMPONENT(_potBasename ${_potFile} NAME_WE)
  11. GET_FILENAME_COMPONENT(_absPotFile ${_potFile} ABSOLUTE)
  12. SET(_addToAll)
  13. IF(${_firstPoFile} STREQUAL "ALL")
  14. SET(_addToAll "ALL")
  15. SET(_firstPoFile)
  16. ENDIF(${_firstPoFile} STREQUAL "ALL")
  17. FOREACH (_currentPoFile ${_firstPoFile} ${ARGN})
  18. GET_FILENAME_COMPONENT(_absFile ${_currentPoFile} ABSOLUTE)
  19. GET_FILENAME_COMPONENT(_abs_PATH ${_absFile} PATH)
  20. GET_FILENAME_COMPONENT(_lang ${_absFile} NAME_WE)
  21. SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo)
  22. ADD_CUSTOM_COMMAND(
  23. OUTPUT ${_gmoFile}
  24. COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_absFile}
  25. DEPENDS ${_absPotFile} ${_absFile}
  26. )
  27. INSTALL(FILES ${_gmoFile} DESTINATION share/locale/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo)
  28. SET(_gmoFiles ${_gmoFiles} ${_gmoFile})
  29. ENDFOREACH (_currentPoFile)
  30. ADD_CUSTOM_TARGET(translations ${_addToAll} DEPENDS ${_gmoFiles})
  31. ENDMACRO()
  32. MACRO(MANAPLUS_GETTEXT_UPDATE_PO _potFile _languages)
  33. GET_FILENAME_COMPONENT(_absPotFile ${_potFile} ABSOLUTE)
  34. ADD_CUSTOM_TARGET(
  35. update-pot
  36. COMMAND xgettext --files-from=translatable-files --directory=. --output=${_potFile} -d manaplus --keyword=_ --keyword=N_
  37. )
  38. ADD_CUSTOM_TARGET(
  39. update-translatable-files
  40. COMMAND grep '_\(' -Irl ../src | sort > translatable-files
  41. )
  42. FOREACH(_lang ${_languages})
  43. GET_FILENAME_COMPONENT(_absFile "${_lang}.po" ABSOLUTE)
  44. SET(_currentPoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.po)
  45. ADD_CUSTOM_TARGET(
  46. "update-translation-${_lang}"
  47. COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${_absFile} ${_absPotFile}
  48. )
  49. ADD_DEPENDENCIES("update-translation-${_lang}" update-pot)
  50. ADD_DEPENDENCIES(update-po "update-translation-${_lang}")
  51. ADD_DEPENDENCIES(update-pot update-translatable-files)
  52. ENDFOREACH()
  53. ENDMACRO()
  54. SET(languages)
  55. SET(POFILES)
  56. FILE(STRINGS LINGUAS _languages)
  57. FOREACH(_lang ${_languages})
  58. STRING(REGEX REPLACE "#.*" "" _lang "${_lang}")
  59. IF(NOT ${_lang} STREQUAL "")
  60. SET(languages ${languages} ${_lang})
  61. SET(POFILES ${POFILES} "${_lang}.po")
  62. ENDIF()
  63. ENDFOREACH()
  64. ADD_CUSTOM_TARGET(update-po)
  65. MANAPLUS_GETTEXT_CREATE_TRANSLATIONS(manaplus.pot ALL ${POFILES})
  66. MANAPLUS_GETTEXT_UPDATE_PO(manaplus.pot "${languages}")