Documentation.cmake 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # Copyright (C) 2009, 2016 Julian Andres Klode <jak@debian.org>.
  2. #
  3. # Permission is hereby granted, free of charge, to any person
  4. # obtaining a copy of this software and associated documentation files
  5. # (the "Software"), to deal in the Software without restriction,
  6. # including without limitation the rights to use, copy, modify, merge,
  7. # publish, distribute, sublicense, and/or sell copies of the Software,
  8. # and to permit persons to whom the Software is furnished to do so,
  9. # subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be
  12. # included in all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  18. # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  19. # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. # SOFTWARE.
  22. function(add_docbook target sourcefiles installdest)
  23. foreach(file ${sourcefiles})
  24. get_filename_component(relfile ${file} NAME)
  25. string(REPLACE ".dbk" "" manual ${relfile})
  26. get_filename_component(absolute ${file} ABSOLUTE)
  27. add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${manual}.html/
  28. COMMAND xsltproc --nonet --novalid --xinclude
  29. --stringparam base.dir ${CMAKE_CURRENT_BINARY_DIR}/${manual}.html/
  30. --path ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/${CURRENT_VENDOR}/
  31. --path ${CMAKE_CURRENT_SOURCE_DIR}/
  32. ${CMAKE_CURRENT_SOURCE_DIR}/docbook-html-style.xsl
  33. ${absolute}
  34. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  35. DEPENDS ${file}
  36. )
  37. set(commands ${commands} ${CMAKE_CURRENT_BINARY_DIR}/${manual}.html)
  38. if (NOT ${installdest} EQUAL "" )
  39. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${manual}.html
  40. DESTINATION ${installdest})
  41. endif()
  42. endforeach(file ${sourcefiles})
  43. add_custom_target(${target} ALL DEPENDS ${commands})
  44. endfunction()
  45. function(add_po4a type master po target deps)
  46. add_custom_command(OUTPUT ${target}
  47. COMMAND po4a-translate --keep 0 -f ${type} -m ${master}
  48. -p ${po} -l ${target}
  49. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  50. DEPENDS ${deps} ${master} ${po})
  51. endfunction()
  52. # Macro for XML man pages.
  53. function(add_xml_manpages target manpages translations entities)
  54. foreach(manpage ${manpages})
  55. string(LENGTH ${manpage} manpage_length)
  56. math(EXPR manpage_length ${manpage_length}-1)
  57. string(SUBSTRING ${manpage} ${manpage_length} 1 section)
  58. add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${manpage}
  59. COMMAND xsltproc --path ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/${CURRENT_VENDOR}/
  60. --path ${CMAKE_CURRENT_SOURCE_DIR}/
  61. ${CMAKE_CURRENT_SOURCE_DIR}/manpage-style.xsl
  62. ${CMAKE_CURRENT_SOURCE_DIR}/${manpage}.xml
  63. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  64. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${manpage}.xml
  65. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/manpage-style.xsl
  66. )
  67. set(commands ${commands} ${CMAKE_CURRENT_BINARY_DIR}/${manpage})
  68. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${manpage}
  69. DESTINATION ${CMAKE_INSTALL_MANDIR}/man${section})
  70. # Add the translations for the manpage.
  71. foreach(translation ${translations})
  72. set(entities)
  73. # transdir = shortcut to the output directory for translations.
  74. set(transdir ${CMAKE_CURRENT_BINARY_DIR}/${translation})
  75. add_po4a(docbook ${manpage}.xml po/${translation}.po
  76. ${transdir}/${manpage}.xml "${ent_cmds}")
  77. add_custom_command(OUTPUT ${transdir}/${manpage}
  78. COMMAND xsltproc --path ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/${CURRENT_VENDOR}/
  79. --path ${CMAKE_CURRENT_SOURCE_DIR}/
  80. --stringparam l10n.gentext.default.language ${translation}
  81. ${CMAKE_CURRENT_SOURCE_DIR}/manpage-style.xsl
  82. ${transdir}/${manpage}.xml
  83. WORKING_DIRECTORY ${transdir}
  84. DEPENDS ${transdir}/${manpage}.xml
  85. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/manpage-style.xsl)
  86. set(nls-cmd ${nls-cmd} ${transdir}/${manpage})
  87. install(FILES ${transdir}/${manpage}
  88. DESTINATION ${CMAKE_INSTALL_MANDIR}/${translation}/man${section})
  89. endforeach(translation ${translations})
  90. endforeach(manpage ${manpages})
  91. add_custom_target(${target} ALL DEPENDS ${commands})
  92. # Sort the list of the translations.
  93. list(SORT nls-cmd)
  94. add_custom_target(nls-${target} ALL DEPENDS ${nls-cmd})
  95. endfunction()
  96. function(add_manpages target manpages translations)
  97. foreach(man ${manpages})
  98. string(LENGTH ${man} manpage_length)
  99. math(EXPR manpage_length ${manpage_length}-1)
  100. string(SUBSTRING ${man} ${manpage_length} 1 section)
  101. install(FILES ${man} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${section})
  102. if (USE_NLS)
  103. foreach(translation ${translations})
  104. set(transdir ${CMAKE_CURRENT_BINARY_DIR}/${translation})
  105. add_po4a(man ${man} po/${translation}.po ${transdir}/${man} "")
  106. install(FILES ${transdir}/${man}
  107. DESTINATION ${CMAKE_INSTALL_MANDIR}/${translation}/man${section})
  108. set(files ${files} ${transdir}/${man})
  109. endforeach(translation ${translations})
  110. endif()
  111. endforeach(man ${manpages})
  112. add_custom_target(${target} ALL DEPENDS ${files})
  113. endfunction()