-function(add_manpages target manpages translations)
- foreach(man ${manpages})
- string(LENGTH ${man} manpage_length)
- math(EXPR manpage_length ${manpage_length}-1)
- string(SUBSTRING ${man} ${manpage_length} 1 section)
- install(FILES ${man} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${section})
-
- if (USE_NLS)
- foreach(translation ${translations})
- set(transdir ${CMAKE_CURRENT_BINARY_DIR}/${translation})
- add_po4a(man ${man} po/${translation}.po ${transdir}/${man} "")
- install(FILES ${transdir}/${man}
- DESTINATION ${CMAKE_INSTALL_MANDIR}/${translation}/man${section})
- set(files ${files} ${transdir}/${man})
- endforeach(translation ${translations})
- endif()
- endforeach(man ${manpages})
- add_custom_target(${target} ALL DEPENDS ${files})
+# add_docbook(Name [ALL] [HTML] [TEXT] [MANPAGE]
+# [INSTALL install dir]
+# [DEPENDS depend ...]
+# [DOCUMENTS documents ...]
+# [LINGUAS lingua ...])
+#
+# Generate a target called name with all the documents being converted to
+# the chosen output formats and translated to the chosen languages using po4a.
+#
+# For the translation support, the po4a.conf must be written so that
+# translations for a document guide.xml are written to LANG/guide.LANG.xml,
+# and for a manual page man.5.xml to a file called LANG/man.LANG.5.xml.
+#
+# The guide and manual page names may also contain a second component separated
+# by a dot, it must however not be a valid language code.
+#
+# Note that po4a might chose not to generate a translated manual page for a
+# given language if the translation rate is not high enough. We deal with this
+# by creating stamp files.
+function(add_docbook target)
+ set(generated "")
+ set(options HTML TEXT MANPAGE ALL)
+ set(oneValueArgs)
+ set(multiValueArgs INSTALL DOCUMENTS LINGUAS DEPENDS)
+ cmake_parse_arguments(DOC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ if (DOC_HTML)
+ list(APPEND formats HTML)
+ endif()
+ if (DOC_TEXT)
+ list(APPEND formats TEXT)
+ endif()
+ if (DOC_MANPAGE)
+ list(APPEND formats MANPAGE)
+ endif()
+
+ foreach(document ${DOC_DOCUMENTS})
+ foreach(lang ${DOC_LINGUAS})
+ po4a_one(po4a_stamp po4a_out ${document} "${lang}" "${DOC_DEPENDS}")
+ xsltproc_one(STAMP_OUT xslt_stamp
+ STAMP ${po4a_stamp}
+ FULL_DOCUMENT ${po4a_out}
+ INSTALL ${DOC_INSTALL}
+ ${formats})
+
+ list(APPEND stamps ${xslt_stamp})
+ endforeach()
+ xsltproc_one(STAMP_OUT xslt_stamp
+ STAMP ${document}
+ FULL_DOCUMENT ${document}
+ INSTALL ${DOC_INSTALL}
+ ${formats})
+
+ list(APPEND stamps ${xslt_stamp})
+ endforeach()
+
+ if (DOC_ALL)
+ add_custom_target(${target} ALL DEPENDS ${stamps})
+ else()
+ add_custom_target(${target} DEPENDS ${stamps})
+ endif()
+endfunction()
+
+# Add an update-po4a target
+function(add_update_po4a target pot header)
+ set(WRITE_HEADER "")
+
+ if (header)
+ set(WRITE_HEADER
+ COMMAND sed -n "/^\#$/,$p" ${pot} > ${pot}.headerfree
+ COMMAND cat ${header} ${pot}.headerfree > ${pot}
+ COMMAND rm ${pot}.headerfree
+ )
+ endif()
+ add_custom_target(${target}
+ COMMAND po4a --previous --no-backups --force --no-translations
+ --msgmerge-opt --add-location=file
+ --porefs noline,wrap
+ --package-name=${PROJECT_NAME}-doc --package-version=${PACKAGE_VERSION}
+ --msgid-bugs-address=${PACKAGE_MAIL} po4a.conf
+ ${WRITE_HEADER}
+ VERBATIM
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )