| 1 |
# Gettext support: Create/Update pot file and |
| 2 |
# |
| 3 |
# To use: INCLUDE(Gettext) |
| 4 |
# |
| 5 |
# Most of the gettext support code is from FindGettext.cmake of cmake, |
| 6 |
# but it is included here because: |
| 7 |
# |
| 8 |
# 1. Some system like RHEL5 does not have FindGettext.cmake |
| 9 |
# 2. Bug of GETTEXT_CREATE_TRANSLATIONS make it unable to be include in 'All' |
| 10 |
# 3. It does not support xgettext |
| 11 |
# |
| 12 |
#=================================================================== |
| 13 |
# Variables: |
| 14 |
# XGETTEXT_OPTIONS: Options pass to xgettext |
| 15 |
# Default: --language=C --keyword=_ --keyword=N_ --keyword=C_:1c,2 --keyword=NC_:1c,2 |
| 16 |
# GETTEXT_MSGMERGE_EXECUTABLE: the full path to the msgmerge tool. |
| 17 |
# GETTEXT_MSGFMT_EXECUTABLE: the full path to the msgfmt tool. |
| 18 |
# GETTEXT_FOUND: True if gettext has been found. |
| 19 |
# XGETTEXT_EXECUTABLE: the full path to the xgettext. |
| 20 |
# XGETTEXT_FOUND: True if xgettext has been found. |
| 21 |
# |
| 22 |
#=================================================================== |
| 23 |
# Macros: |
| 24 |
# GETTEXT_CREATE_POT(potFile |
| 25 |
# [OPTION xgettext_options] |
| 26 |
# SRC list_of_source_file_that_contains_msgid |
| 27 |
# ) |
| 28 |
# |
| 29 |
# Generate .pot file. |
| 30 |
# OPTION xgettext_options: Override XGETTEXT_OPTIONS |
| 31 |
# |
| 32 |
# * Produced targets: pot_file |
| 33 |
# |
| 34 |
#------------------------------------------------------------------- |
| 35 |
# GETTEXT_CREATE_TRANSLATIONS ( outputFile [ALL] locale1 ... localeN |
| 36 |
# [COMMENT comment] ) |
| 37 |
# |
| 38 |
# This will create a target "translations" which will convert the |
| 39 |
# given input po files into the binary output mo file. If the |
| 40 |
# ALL option is used, the translations will also be created when |
| 41 |
# building the default target. |
| 42 |
# |
| 43 |
# * Produced targets: translations |
| 44 |
#------------------------------------------------------------------- |
| 45 |
|
| 46 |
|
| 47 |
FIND_PROGRAM(GETTEXT_MSGMERGE_EXECUTABLE msgmerge) |
| 48 |
FIND_PROGRAM(GETTEXT_MSGFMT_EXECUTABLE msgfmt) |
| 49 |
FIND_PROGRAM(XGETTEXT_EXECUTABLE xgettext) |
| 50 |
|
| 51 |
IF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE ) |
| 52 |
SET(GETTEXT_FOUND TRUE) |
| 53 |
ELSE (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE) |
| 54 |
SET(GETTEXT_FOUND FALSE) |
| 55 |
IF (GetText_REQUIRED) |
| 56 |
MESSAGE(FATAL_ERROR "GetText not found") |
| 57 |
ENDIF (GetText_REQUIRED) |
| 58 |
ENDIF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE ) |
| 59 |
|
| 60 |
IF(XGETTEXT_EXECUTABLE) |
| 61 |
SET(XGETTEXT_FOUND TRUE) |
| 62 |
ELSE(XGETTEXT_EXECUTABLE) |
| 63 |
MESSAGE(STATUS "xgettext not found.") |
| 64 |
SET(XGETTTEXT_FOUND FALSE) |
| 65 |
ENDIF(XGETTEXT_EXECUTABLE) |
| 66 |
|
| 67 |
IF(NOT DEFINED XGETTEXT_OPTIONS) |
| 68 |
SET(XGETTEXT_OPTIONS --keyword=_ --keyword=N_ --keyword=C_:1c,2 --keyword=NC_:1c,2 -s) |
| 69 |
ENDIF(NOT DEFINED XGETTEXT_OPTIONS) |
| 70 |
|
| 71 |
IF(XGETTEXT_FOUND) |
| 72 |
MACRO(GETTEXT_CREATE_POT _potFile _pot_options ) |
| 73 |
SET(_xgettext_options_list) |
| 74 |
SET(_src_list) |
| 75 |
SET(_src_list_abs) |
| 76 |
SET(_stage "SRC") |
| 77 |
FOREACH(_pot_option ${_pot_options} ${ARGN}) |
| 78 |
IF(_pot_option STREQUAL "OPTION") |
| 79 |
SET(_stage "OPTION") |
| 80 |
ELSEIF(_pot_option STREQUAL "SRC") |
| 81 |
SET(_stage "SRC") |
| 82 |
ELSE(_pot_option STREQUAL "OPTION") |
| 83 |
IF(_stage STREQUAL "OPTION") |
| 84 |
SET(_xgettext_options_list ${_xgettext_options_list} ${_pot_option}) |
| 85 |
ELSE(_stage STREQUAL "OPTION") |
| 86 |
FILE(RELATIVE_PATH _relFile ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${_pot_option}) |
| 87 |
GET_FILENAME_COMPONENT(_absFile ${_pot_option} ABSOLUTE) |
| 88 |
SET(_src_list ${_src_list} ${_relFile}) |
| 89 |
SET(_src_list_abs ${_src_list_abs} ${_absFile}) |
| 90 |
ENDIF(_stage STREQUAL "OPTION") |
| 91 |
ENDIF(_pot_option STREQUAL "OPTION") |
| 92 |
ENDFOREACH(_pot_option ${_pot_options} ${ARGN}) |
| 93 |
|
| 94 |
IF (_xgettext_options_list) |
| 95 |
SET(_xgettext_options ${_xgettext_options_list}) |
| 96 |
ELSE(_xgettext_options_list) |
| 97 |
SET(_xgettext_options ${XGETTEXT_OPTIONS}) |
| 98 |
ENDIF(_xgettext_options_list) |
| 99 |
|
| 100 |
#MESSAGE("${XGETTEXT_EXECUTABLE} ${_xgettext_options_list} -o ${_potFile} ${_src_list}") |
| 101 |
ADD_CUSTOM_COMMAND(OUTPUT ${_potFile} |
| 102 |
COMMAND ${XGETTEXT_EXECUTABLE} ${_xgettext_options} -o ${_potFile} ${_src_list} |
| 103 |
DEPENDS ${_src_list_abs} |
| 104 |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 105 |
) |
| 106 |
|
| 107 |
ADD_CUSTOM_TARGET(pot_file |
| 108 |
COMMAND ${XGETTEXT_EXECUTABLE} ${_xgettext_options_list} -o ${_potFile} ${_src_list} |
| 109 |
DEPENDS ${_src_list_abs} |
| 110 |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 111 |
COMMENT "Extract translatable messages to ${_potFile}" |
| 112 |
) |
| 113 |
ENDMACRO(GETTEXT_CREATE_POT _potFile _pot_options) |
| 114 |
|
| 115 |
|
| 116 |
MACRO(GETTEXT_CREATE_TRANSLATIONS _potFile _firstLang) |
| 117 |
SET(_gmoFiles) |
| 118 |
GET_FILENAME_COMPONENT(_potBasename ${_potFile} NAME_WE) |
| 119 |
GET_FILENAME_COMPONENT(_absPotFile ${_potFile} ABSOLUTE) |
| 120 |
|
| 121 |
SET(_addToAll) |
| 122 |
SET(_is_comment FALSE) |
| 123 |
|
| 124 |
FOREACH (_currentLang ${_firstLang} ${ARGN}) |
| 125 |
IF(_currentLang STREQUAL "ALL") |
| 126 |
SET(_addToAll "ALL") |
| 127 |
ELSEIF(_currentLang STREQUAL "COMMENT") |
| 128 |
SET(_is_comment TRUE) |
| 129 |
ELSEIF(_is_comment) |
| 130 |
SET(_is_comment FALSE) |
| 131 |
SET(_comment ${_currentLang}) |
| 132 |
ELSE() |
| 133 |
SET(_lang ${_currentLang}) |
| 134 |
GET_FILENAME_COMPONENT(_absFile ${_currentLang}.po ABSOLUTE) |
| 135 |
GET_FILENAME_COMPONENT(_abs_PATH ${_absFile} PATH) |
| 136 |
SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo) |
| 137 |
|
| 138 |
#MESSAGE("_absFile=${_absFile} _abs_PATH=${_abs_PATH} _lang=${_lang} curr_bin=${CMAKE_CURRENT_BINARY_DIR}") |
| 139 |
ADD_CUSTOM_COMMAND( |
| 140 |
OUTPUT ${_gmoFile} |
| 141 |
COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${_absFile} ${_absPotFile} |
| 142 |
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_absFile} |
| 143 |
DEPENDS ${_absPotFile} ${_absFile} |
| 144 |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 145 |
) |
| 146 |
|
| 147 |
INSTALL(FILES ${_gmoFile} DESTINATION share/locale/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo) |
| 148 |
SET(_gmoFiles ${_gmoFiles} ${_gmoFile}) |
| 149 |
ENDIF() |
| 150 |
ENDFOREACH (_currentLang ) |
| 151 |
|
| 152 |
IF(DEFINED _comment) |
| 153 |
ADD_CUSTOM_TARGET(translations ${_addToAll} DEPENDS ${_gmoFiles} COMMENT ${_comment}) |
| 154 |
ELSE(DEFINED _comment) |
| 155 |
ADD_CUSTOM_TARGET(translations ${_addToAll} DEPENDS ${_gmoFiles}) |
| 156 |
ENDIF(DEFINED _comment) |
| 157 |
ENDMACRO(GETTEXT_CREATE_TRANSLATIONS ) |
| 158 |
ENDIF(XGETTEXT_FOUND) |
| 159 |
|
| 160 |
# -*- indent-tabs-mode: nil -*- vim:et:ts=4 |