FindGettext.cmake 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. # GETTEXT_PROCESS_POT( <potfile> [ALL] [INSTALL_DESTINATION <destdir>] LANGUAGES <lang1> <lang2> ... )
  15. # Process the given pot file to mo files.
  16. # If INSTALL_DESTINATION is given then automatically install rules will be created,
  17. # the language subdirectory will be taken into account (by default use share/locale/).
  18. # If ALL is specified, the pot file is processed when building the all traget.
  19. # It creates a custom target "potfile".
  20. # GETTEXT_PROCESS_PO_FILES( <lang> [ALL] [INSTALL_DESTINATION <dir>] PO_FILES <po1> <po2> ... )
  21. # Process the given po files to mo files for the given language.
  22. # If INSTALL_DESTINATION is given then automatically install rules will be created,
  23. # the language subdirectory will be taken into account (by default use share/locale/).
  24. # If ALL is specified, the po files are processed when building the all traget.
  25. # It creates a custom target "pofiles".
  26. #=============================================================================
  27. # Copyright 2007-2009 Kitware, Inc.
  28. # Copyright 2007 Alexander Neundorf <[email protected]>
  29. #
  30. # Distributed under the OSI-approved BSD License (the "License");
  31. # see accompanying file Copyright.txt for details.
  32. #
  33. # This software is distributed WITHOUT ANY WARRANTY; without even the
  34. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  35. # See the License for more information.
  36. #=============================================================================
  37. # (To distribute this file outside of CMake, substitute the full
  38. # License text for the above reference.)
  39. FIND_PROGRAM(GETTEXT_MSGMERGE_EXECUTABLE msgmerge)
  40. FIND_PROGRAM(GETTEXT_MSGFMT_EXECUTABLE msgfmt)
  41. INCLUDE(FindPackageHandleStandardArgs)
  42. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Gettext REQUIRED_VARS GETTEXT_MSGMERGE_EXECUTABLE GETTEXT_MSGFMT_EXECUTABLE)
  43. INCLUDE(CMakeParseArguments)
  44. MACRO(GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFileArg)
  45. # make it a real variable, so we can modify it here
  46. SET(_firstPoFile "${_firstPoFileArg}")
  47. SET(_gmoFiles)
  48. GET_FILENAME_COMPONENT(_potBasename ${_potFile} NAME_WE)
  49. GET_FILENAME_COMPONENT(_absPotFile ${_potFile} ABSOLUTE)
  50. SET(_addToAll)
  51. IF(${_firstPoFile} STREQUAL "ALL")
  52. SET(_addToAll "ALL")
  53. SET(_firstPoFile)
  54. ENDIF(${_firstPoFile} STREQUAL "ALL")
  55. FOREACH (_currentPoFile ${_firstPoFile} ${ARGN})
  56. GET_FILENAME_COMPONENT(_absFile ${_currentPoFile} ABSOLUTE)
  57. GET_FILENAME_COMPONENT(_abs_PATH ${_absFile} PATH)
  58. GET_FILENAME_COMPONENT(_lang ${_absFile} NAME_WE)
  59. SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo)
  60. ADD_CUSTOM_COMMAND(
  61. OUTPUT ${_gmoFile}
  62. COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${_absFile} ${_absPotFile}
  63. COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_absFile}
  64. DEPENDS ${_absPotFile} ${_absFile}
  65. )
  66. INSTALL(FILES ${_gmoFile} DESTINATION share/locale/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo)
  67. SET(_gmoFiles ${_gmoFiles} ${_gmoFile})
  68. ENDFOREACH (_currentPoFile )
  69. ADD_CUSTOM_TARGET(translations ${_addToAll} DEPENDS ${_gmoFiles})
  70. ENDMACRO(GETTEXT_CREATE_TRANSLATIONS )
  71. FUNCTION(GETTEXT_PROCESS_POT_FILE _potFile)
  72. SET(_gmoFiles)
  73. SET(_options ALL)
  74. SET(_oneValueArgs INSTALL_DESTINATION)
  75. SET(_multiValueArgs LANGUAGES)
  76. CMAKE_PARSE_ARGUMENTS(_parsedArguments "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  77. GET_FILENAME_COMPONENT(_potBasename ${_potFile} NAME_WE)
  78. GET_FILENAME_COMPONENT(_absPotFile ${_potFile} ABSOLUTE)
  79. FOREACH (_lang ${_parsedArguments_LANGUAGES})
  80. SET(_poFile "${CMAKE_CURRENT_BINARY_DIR}/${_lang}.po")
  81. SET(_gmoFile "${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo")
  82. ADD_CUSTOM_COMMAND(
  83. OUTPUT "${_poFile}"
  84. COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${_poFile} ${_absPotFile}
  85. DEPENDS ${_absPotFile}
  86. )
  87. ADD_CUSTOM_COMMAND(
  88. OUTPUT "${_gmoFile}"
  89. COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_poFile}
  90. DEPENDS ${_absPotFile} ${_poFile}
  91. )
  92. IF(_parsedArguments_INSTALL_DESTINATION)
  93. INSTALL(FILES ${_gmoFile} DESTINATION ${_parsedArguments_INSTALL_DESTINATION}/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo)
  94. ENDIF(_parsedArguments_INSTALL_DESTINATION)
  95. LIST(APPEND _gmoFiles ${_gmoFile})
  96. ENDFOREACH (_lang )
  97. IF(_parsedArguments_ALL)
  98. ADD_CUSTOM_TARGET(potfiles ALL DEPENDS ${_gmoFiles})
  99. ELSE(_parsedArguments_ALL)
  100. ADD_CUSTOM_TARGET(potfiles DEPENDS ${_gmoFiles})
  101. ENDIF(_parsedArguments_ALL)
  102. ENDFUNCTION(GETTEXT_PROCESS_POT_FILE)
  103. FUNCTION(GETTEXT_PROCESS_PO_FILES _lang)
  104. SET(_options ALL)
  105. SET(_oneValueArgs INSTALL_DESTINATION)
  106. SET(_multiValueArgs PO_FILES)
  107. SET(_gmoFiles)
  108. CMAKE_PARSE_ARGUMENTS(_parsedArguments "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  109. FOREACH(_current_PO_FILE ${_parsedArguments_PO_FILES})
  110. GET_FILENAME_COMPONENT(_basename ${_current_PO_FILE} NAME_WE)
  111. SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.gmo)
  112. ADD_CUSTOM_COMMAND(OUTPUT ${_gmoFile}
  113. COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_current_PO_FILE}
  114. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  115. DEPENDS ${_current_PO_FILE}
  116. )
  117. IF(_parsedArguments_INSTALL_DESTINATION)
  118. INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.gmo DESTINATION ${_parsedArguments_INSTALL_DESTINATION}/${_lang}/LC_MESSAGES/ RENAME ${_basename}.mo)
  119. ENDIF(_parsedArguments_INSTALL_DESTINATION)
  120. LIST(APPEND _gmoFiles ${_gmoFile})
  121. ENDFOREACH(_current_PO_FILE)
  122. IF(_parsedArguments_ALL)
  123. ADD_CUSTOM_TARGET(pofiles ALL DEPENDS ${_gmoFiles})
  124. ELSE(_parsedArguments_ALL)
  125. ADD_CUSTOM_TARGET(pofiles DEPENDS ${_gmoFiles})
  126. ENDIF(_parsedArguments_ALL)
  127. ENDFUNCTION(GETTEXT_PROCESS_PO_FILES)
  128. IF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
  129. SET(GETTEXT_FOUND TRUE)
  130. ELSE (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
  131. SET(GETTEXT_FOUND FALSE)
  132. IF (GetText_REQUIRED)
  133. MESSAGE(FATAL_ERROR "GetText not found")
  134. ENDIF (GetText_REQUIRED)
  135. ENDIF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )