[CMake] Xgettext macro, problems and pitfalls

Leopold Palomo Avellaneda leo at alaxarxa.net
Fri Mar 28 05:24:59 EDT 2008


Hi,

I'm in a frustrating situation trying to create a macro for the xgettext 
command. For who doesn't know it, xgettext is a command of the gettext 
tools[1] that extract the strings of a file in the way to let you translate 
it. 

The xgettext accept a lot of arguments and finally a list of files. I have 
tried with the macro written below, but with the '\' char, the line feed, and 
some erratic behaviour of cmake I'm really desperately. cmake write a command 
that doesn't works. If I take the line, erase all the \, then it works. 
However, in my case I have never be able to pass a list.

I have fount that if I have a var with a list of files ${sources} this code:

foreach (file ${sources})
	WRITE_FILE(filelist ${file} APPEND)
endforeach(file)

doesn't works. Simple, only wrote 1 line, and not the rest. I suppose that is 
a but in cmake 2.4.8.

I have the suspicious that is not possible to do it with cmake because the 
first user (kde team) doesn't extract the string using cmake, they do the job 
with a script.

So, someone that success in this area? 
Please, help.....

Regards,

Leo



[1] http://www.gnu.org/software/gettext/

############################
# template, the name of the finally pot file without the .pot
# dirIN the directory where to find the files
# sources list of files to create the pot

macro(GETTEXT_CREATE_TEMPLATE template dirIN sources )
	#foreach (file ${sources})
	#	WRITE_FILE(filelist ${file} APPEND)
	#endforeach(file)
	string(REPLACE ";" " " sourcesN "${sources}")
	message (STATUS "Files to process ${sourcesN}")

	set (XGETTEXT_OPTIONS "--qt\\
	--keyword=tr --flag=tr:1:pass-c-format --flag=tr:1:pass-qt-format\\
   --keyword=trUtf8 --flag=tr:1:pass-c-format --flag=tr:1:pass-qt-format\\
   --keyword=translate:2 --flag=translate:2:pass-c-format --flag=translate:2:pass-qt-format\\
   --keyword=QT_TR_NOOP --flag=QT_TR_NOOP:1:pass-c-format --flag=QT_TR_NOOP:1:pass-qt-format\\
   --keyword=QT_TRANSLATE_NOOP:2 --flag=QT_TRANSLATE_NOOP:2:pass-c-format --flag=QT_TRANSLATE_NOOP:2:pass-qt-format\\
   --keyword=_ --flag=_:1:pass-c-format --flag=_:1:pass-qt-format\\
   --keyword=N_ --flag=N_:1:pass-c-format --flag=N_:1:pass-qt-format\\
   --from-code=utf-8")

	message (STATUS ${XGETTEXT_OPTIONS})
	set (MSGID_BUGS_ADDRESS "bulmages at bulma.net")

	add_custom_command( 
		OUTPUT ${template}.pot
		COMMAND ${GETTEXT_XGETTEXT_EXECUTABLE} 
        ARGS "--add-comments=TRANSLATORS: 
${XGETTEXT_OPTIONS} --directory=${dirIN} --output=${template}.pot --msgid-bugs-address=${MSGID_BUGS_ADDRESS} 
${sourcesN}"
        DEPENDS ${template})
           
   add_custom_target( messages_extract DEPENDS ${template}.pot)

endmacro( GETTEXT_CREATE_TEMPLATE)




-- 
--
Linux User 152692
PGP: 0xF944807E
Catalonia
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080328/4a9b98f2/attachment.pgp>


More information about the CMake mailing list