1# This file is a helper file for the gettext translation macros found in 2# KWWidgetsInternationalizationMacros.cmake. 3# If is used as a custom command in the KWWidgets_CREATE_POT_TARGETS macro. 4# This macro extracts translatable strings out of source files into a POT 5# file (template translation fiel). The problem is that even if no changes 6# occurred as far as the translation strings are concerned, xgettext will 7# always create a new file with a different POT-Creation-Date field. This 8# forces all the depending targets to be updated when they do not really have 9# to. Fix that by comparing the next POT file to the old one without taking 10# the POT-Creation-Date into account. 11# 12# 'pot_build_file' (string): the POT file the strings should be extracted to 13# 'pot_uptodate_file' (string): the dummy file which will be up to date 14# 'options' (string): options 15# 'keywords' (string): keywords 16# 'copyright_holder': copyright holder of the template file 17# 'msgid_bugs_address': report address for msgid bugs 18# 'files_from': 19# GETTEXT_XGETTEXT_EXECUTABLE (string): path to the 'xgettext' executable 20 21set(SUCCESS 1) 22if(NOT "${GETTEXT_XGETTEXT_EXECUTABLE}" STREQUAL "") 23 24 # Extract the strings, store the result in a variable instead of a POT file 25 26 exec_program(${GETTEXT_XGETTEXT_EXECUTABLE} 27 RETURN_VALUE xgettext_return 28 OUTPUT_VARIABLE xgettext_output 29 ARGS --output="-" ${options} ${keywords} --msgid-bugs-address="${msgid_bugs_address}" --copyright-holder="${copyright_holder}" --files-from="${files_from}") 30 if(xgettext_return) 31 message("${xgettext_output}") 32 set(SUCCESS 0) 33 else(xgettext_return) 34 35 set(xgettext_output "${xgettext_output}\n") 36 37 # Check if the new POT file would be different than the old one 38 # without taking into account the POT-Creation-Date. 39 40 set(update_pot_file 0) 41 if(EXISTS ${pot_build_file}) 42 string(REGEX REPLACE "\"POT-Creation-Date:[^\"]*\"" "" 43 xgettext_output_nodate "${xgettext_output}") 44 file(READ "${pot_build_file}" xgettext_old) 45 string(REGEX REPLACE "\"POT-Creation-Date:[^\"]*\"" "" 46 xgettext_old_nodate "${xgettext_old}") 47 if(NOT "${xgettext_output_nodate}" STREQUAL "${xgettext_old_nodate}") 48 set(update_pot_file 1) 49 endif(NOT "${xgettext_output_nodate}" STREQUAL "${xgettext_old_nodate}") 50 else(EXISTS ${pot_build_file}) 51 set(update_pot_file 1) 52 endif(EXISTS ${pot_build_file}) 53 54 # Create the POT file if it is really needed 55 56 if(update_pot_file) 57 message("Updating ${pot_build_file}") 58 file(WRITE "${pot_build_file}" "${xgettext_output}") 59 endif(update_pot_file) 60 61 # Update the dummy file to say: this POT target is up to date as 62 # far as its dependencies are concerned. This will prevent the POT 63 # target to be triggered again and again because the sources are older 64 # than the POT, but the POT does not really need to be changed, etc. 65 66 if(SUCCESS) 67 file(WRITE "${pot_uptodate_file}" 68 "${pot_build_file} is *really* up-to-date.") 69 endif(SUCCESS) 70 71 endif(xgettext_return) 72endif(NOT "${GETTEXT_XGETTEXT_EXECUTABLE}" STREQUAL "") 73