1
# Gettext support: Create/Update pot file and
3
# To use: INCLUDE(Gettext)
5
# Most of the gettext support code is from FindGettext.cmake of cmake,
6
# but it is included here because:
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
12
#===================================================================
14
# XGETTEXT_OPTIONS_DEFAULT: Default xgettext option:
15
#===================================================================
17
# XGETTEXT_OPTIONS: Options pass to xgettext
18
# Default: XGETTEXT_OPTIONS_DEFAULT
19
# GETTEXT_MSGMERGE_EXECUTABLE: the full path to the msgmerge tool.
20
# GETTEXT_MSGFMT_EXECUTABLE: the full path to the msgfmt tool.
21
# GETTEXT_FOUND: True if gettext has been found.
22
# XGETTEXT_EXECUTABLE: the full path to the xgettext.
23
# XGETTEXT_FOUND: True if xgettext has been found.
25
#===================================================================
27
# GETTEXT_CREATE_POT(potFile
28
# [OPTION xgettext_options]
29
# SRC list_of_source_file_that_contains_msgid
33
# OPTION xgettext_options: Override XGETTEXT_OPTIONS
35
# * Produced targets: pot_file
37
#-------------------------------------------------------------------
38
# GETTEXT_CREATE_TRANSLATIONS ( outputFile [ALL] locale1 ... localeN
41
# This will create a target "translations" which will convert the
42
# given input po files into the binary output mo file. If the
43
# ALL option is used, the translations will also be created when
44
# building the default target.
46
# * Produced targets: translations
47
#-------------------------------------------------------------------
49
FIND_PROGRAM(GETTEXT_MSGMERGE_EXECUTABLE msgmerge)
50
FIND_PROGRAM(GETTEXT_MSGFMT_EXECUTABLE msgfmt)
51
FIND_PROGRAM(GETTEXT_MSGCAT_EXECUTABLE msgcat)
52
FIND_PROGRAM(XGETTEXT_EXECUTABLE xgettext)
54
SET(XGETTEXT_OPTIONS_DEFAULT
55
--language=C --keyword=_ --keyword=N_ --keyword=C_:1c,2 --keyword=NC_:1c,2 -s
56
--escape --add-comments="/" --package-name=${PROJECT_NAME} --package-version=${VERSION})
58
IF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE AND GETTEXT_MSGCAT_EXECUTABLE)
59
SET(GETTEXT_FOUND TRUE)
60
ELSE (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE)
61
SET(GETTEXT_FOUND FALSE)
63
MESSAGE(FATAL_ERROR "GetText not found")
64
ENDIF (GetText_REQUIRED)
65
ENDIF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE AND GETTEXT_MSGCAT_EXECUTABLE)
67
IF(XGETTEXT_EXECUTABLE)
68
SET(XGETTEXT_FOUND TRUE)
69
ELSE(XGETTEXT_EXECUTABLE)
70
MESSAGE(STATUS "xgettext not found.")
71
SET(XGETTTEXT_FOUND FALSE)
72
ENDIF(XGETTEXT_EXECUTABLE)
74
IF(NOT DEFINED XGETTEXT_OPTIONS)
75
SET(XGETTEXT_OPTIONS ${XGETTEXT_OPTIONS_DEFAULT})
76
ENDIF(NOT DEFINED XGETTEXT_OPTIONS)
79
MACRO(GETTEXT_CREATE_POT _potFile _pot_options )
80
SET(_xgettext_options_list)
86
FOREACH(_pot_option ${_pot_options} ${ARGN})
87
IF(_pot_option STREQUAL "OPTION")
89
ELSEIF(_pot_option STREQUAL "SRC")
91
ELSEIF(_pot_option STREQUAL "GLADE")
93
ELSE(_pot_option STREQUAL "OPTION")
94
IF(_stage STREQUAL "OPTION")
95
SET(_xgettext_options_list ${_xgettext_options_list} ${_pot_option})
96
ELSEIF(_stage STREQUAL "GLADE")
97
FILE(RELATIVE_PATH _relFile ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/${_pot_option})
98
GET_FILENAME_COMPONENT(_absFile ${_pot_option} ABSOLUTE)
99
SET(_glade_list ${_glade_list} ${_relFile})
100
SET(_glade_list_abs ${_glade_list_abs} ${_absFile})
101
ELSEIF(_stage STREQUAL "SRC")
102
FILE(RELATIVE_PATH _relFile ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${_pot_option})
103
GET_FILENAME_COMPONENT(_absFile ${_pot_option} ABSOLUTE)
104
SET(_src_list ${_src_list} ${_relFile})
105
SET(_src_list_abs ${_src_list_abs} ${_absFile})
106
ENDIF(_stage STREQUAL "OPTION")
107
ENDIF(_pot_option STREQUAL "OPTION")
108
ENDFOREACH(_pot_option ${_pot_options} ${ARGN})
110
IF (_xgettext_options_list)
111
SET(_xgettext_options ${_xgettext_options_list})
112
ELSE(_xgettext_options_list)
113
SET(_xgettext_options ${XGETTEXT_OPTIONS})
114
ENDIF(_xgettext_options_list)
116
#MESSAGE("${XGETTEXT_EXECUTABLE} ${_xgettext_options_list} -o ${_potFile} ${_src_list}")
117
ADD_CUSTOM_COMMAND(OUTPUT pot_file
118
COMMAND ${XGETTEXT_EXECUTABLE} ${_xgettext_options} -o ${_potFile} ${_src_list}
119
DEPENDS ${_src_list_abs} ${GLADE_FILES}
120
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
123
ADD_CUSTOM_TARGET(pot_file
124
COMMAND ${XGETTEXT_EXECUTABLE} ${_xgettext_options_list} -o _source.pot ${_src_list}
125
COMMAND ${XGETTEXT_EXECUTABLE} --language=Glade --omit-header -o _glade.pot ${_glade_list}
126
COMMAND ${GETTEXT_MSGCAT_EXECUTABLE} -o ${_potFile} --use-first _source.pot _glade.pot
127
DEPENDS ${_src_list_abs}
128
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
129
COMMENT "Extract translatable messages to ${_potFile}"
131
ENDMACRO(GETTEXT_CREATE_POT _potFile _pot_options)
134
MACRO(GETTEXT_CREATE_TRANSLATIONS _potFile _firstLang)
136
GET_FILENAME_COMPONENT(_potBasename ${_potFile} NAME_WE)
137
GET_FILENAME_COMPONENT(_absPotFile ${_potFile} ABSOLUTE)
140
SET(_is_comment FALSE)
142
FOREACH (_currentLang ${_firstLang} ${ARGN})
143
IF(_currentLang STREQUAL "ALL")
145
ELSEIF(_currentLang STREQUAL "COMMENT")
146
SET(_is_comment TRUE)
148
SET(_is_comment FALSE)
149
SET(_comment ${_currentLang})
151
SET(_lang ${_currentLang})
152
GET_FILENAME_COMPONENT(_absFile ${_currentLang}.po ABSOLUTE)
153
GET_FILENAME_COMPONENT(_abs_PATH ${_absFile} PATH)
154
SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.mo)
156
#MESSAGE("_absFile=${_absFile} _abs_PATH=${_abs_PATH} _lang=${_lang} curr_bin=${CMAKE_CURRENT_BINARY_DIR}")
159
COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none -s ${_absFile} ${_absPotFile}
160
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_absFile}
161
DEPENDS ${_absPotFile} ${_absFile}
162
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
165
INSTALL(FILES ${_gmoFile} DESTINATION share/locale/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo)
166
SET(_gmoFiles ${_gmoFiles} ${_gmoFile})
168
ENDFOREACH (_currentLang )
171
ADD_CUSTOM_TARGET(translations ${_addToAll} DEPENDS ${_gmoFiles} COMMENT ${_comment})
172
ELSE(DEFINED _comment)
173
ADD_CUSTOM_TARGET(translations ${_addToAll} DEPENDS ${_gmoFiles})
174
ENDIF(DEFINED _comment)
175
ENDMACRO(GETTEXT_CREATE_TRANSLATIONS )
176
ENDIF(XGETTEXT_FOUND)