CMakeLists.txt 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. cmake_minimum_required(VERSION 3.7)
  2. project(putty-documentation LANGUAGES)
  3. # This build script can be run standalone, or included as a
  4. # subdirectory of the main PuTTY cmake build system. If the latter, a
  5. # couple of things change: it has to set variables telling the rest of
  6. # the build system what manpages are available to be installed, and it
  7. # will change whether the 'make doc' target is included in 'make all'.
  8. include(FindGit)
  9. include(FindPerl)
  10. find_program(HALIBUT halibut)
  11. set(doc_outputs)
  12. set(manpage_outputs)
  13. if(HALIBUT AND PERL_EXECUTABLE)
  14. # Build the main manual, which requires not only Halibut, but also
  15. # Perl to run licence.pl to generate the copyright and licence
  16. # sections from the master data outside this directory.
  17. # If this is a source archive in which a fixed version.but was
  18. # provided, use that. Otherwise, infer one from the git checkout (if
  19. # possible).
  20. set(manual_dependencies) # extra target names to depend on
  21. if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/version.but)
  22. set(VERSION_BUT ${CMAKE_CURRENT_SOURCE_DIR}/version.but)
  23. else()
  24. set(VERSION_BUT ${CMAKE_CURRENT_BINARY_DIR}/cmake_version.but)
  25. set(INTERMEDIATE_VERSION_BUT ${VERSION_BUT}.tmp)
  26. add_custom_target(check_git_commit_for_doc
  27. BYPRODUCTS ${INTERMEDIATE_VERSION_BUT}
  28. COMMAND ${CMAKE_COMMAND}
  29. -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
  30. -DOUTPUT_FILE=${INTERMEDIATE_VERSION_BUT}
  31. -DOUTPUT_TYPE=halibut
  32. -P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/gitcommit.cmake
  33. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/gitcommit.cmake
  34. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..
  35. COMMENT "Checking current git commit")
  36. add_custom_target(cmake_version_but
  37. BYPRODUCTS ${VERSION_BUT}
  38. COMMAND ${CMAKE_COMMAND} -E copy_if_different
  39. ${INTERMEDIATE_VERSION_BUT} ${VERSION_BUT}
  40. DEPENDS check_git_commit_for_doc ${INTERMEDIATE_VERSION_BUT}
  41. COMMENT "Updating cmake_version.but")
  42. set(manual_dependencies ${manual_dependencies} cmake_version_but)
  43. endif()
  44. add_custom_target(copy_but
  45. BYPRODUCTS copy.but
  46. COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../licence.pl
  47. --copyrightdoc -o copy.but
  48. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../licence.pl ${CMAKE_CURRENT_SOURCE_DIR}/../LICENCE)
  49. add_custom_target(licence_but
  50. BYPRODUCTS licence.but
  51. COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../licence.pl
  52. --licencedoc -o licence.but
  53. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../licence.pl ${CMAKE_CURRENT_SOURCE_DIR}/../LICENCE)
  54. set(manual_dependencies ${manual_dependencies} copy_but licence_but)
  55. set(manual_sources
  56. ${CMAKE_CURRENT_BINARY_DIR}/copy.but
  57. ${CMAKE_CURRENT_SOURCE_DIR}/blurb.but
  58. ${CMAKE_CURRENT_SOURCE_DIR}/intro.but
  59. ${CMAKE_CURRENT_SOURCE_DIR}/gs.but
  60. ${CMAKE_CURRENT_SOURCE_DIR}/using.but
  61. ${CMAKE_CURRENT_SOURCE_DIR}/config.but
  62. ${CMAKE_CURRENT_SOURCE_DIR}/pscp.but
  63. ${CMAKE_CURRENT_SOURCE_DIR}/psftp.but
  64. ${CMAKE_CURRENT_SOURCE_DIR}/plink.but
  65. ${CMAKE_CURRENT_SOURCE_DIR}/pubkey.but
  66. ${CMAKE_CURRENT_SOURCE_DIR}/pageant.but
  67. ${CMAKE_CURRENT_SOURCE_DIR}/errors.but
  68. ${CMAKE_CURRENT_SOURCE_DIR}/faq.but
  69. ${CMAKE_CURRENT_SOURCE_DIR}/feedback.but
  70. ${CMAKE_CURRENT_SOURCE_DIR}/pubkeyfmt.but
  71. ${CMAKE_CURRENT_BINARY_DIR}/licence.but
  72. ${CMAKE_CURRENT_SOURCE_DIR}/udp.but
  73. ${CMAKE_CURRENT_SOURCE_DIR}/pgpkeys.but
  74. ${CMAKE_CURRENT_SOURCE_DIR}/sshnames.but
  75. ${CMAKE_CURRENT_SOURCE_DIR}/authplugin.but
  76. ${CMAKE_CURRENT_SOURCE_DIR}/index.but
  77. ${VERSION_BUT})
  78. # The HTML manual goes in a subdirectory, for convenience.
  79. set(html_dir ${CMAKE_CURRENT_BINARY_DIR}/html)
  80. file(MAKE_DIRECTORY ${html_dir})
  81. add_custom_command(OUTPUT ${html_dir}/index.html
  82. COMMAND ${HALIBUT} --html ${manual_sources}
  83. WORKING_DIRECTORY ${html_dir}
  84. DEPENDS ${manual_sources} ${manual_dependencies})
  85. list(APPEND doc_outputs ${html_dir}/index.html)
  86. # Windows help.
  87. file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/chmextra.but
  88. "\\cfg{chm-extra-file}{${CMAKE_CURRENT_SOURCE_DIR}/chm.css}{chm.css}\n")
  89. add_custom_command(OUTPUT putty.chm
  90. COMMAND ${HALIBUT} --chm chmextra.but ${manual_sources}
  91. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  92. DEPENDS ${manual_sources} ${manual_dependencies})
  93. list(APPEND doc_outputs putty.chm)
  94. # Plain text.
  95. add_custom_command(OUTPUT puttydoc.txt
  96. COMMAND ${HALIBUT} --text ${manual_sources}
  97. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  98. DEPENDS ${manual_sources} ${manual_dependencies})
  99. list(APPEND doc_outputs puttydoc.txt)
  100. # PDF. (We don't ship this; so it's only built on explicit request.)
  101. add_custom_command(OUTPUT putty.pdf
  102. COMMAND ${HALIBUT} --pdf ${manual_sources}
  103. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  104. DEPENDS ${manual_sources} ${manual_dependencies})
  105. add_custom_target(pdf DEPENDS putty.pdf)
  106. endif()
  107. macro(register_manpage title section)
  108. list(APPEND manpage_outputs ${title}.${section})
  109. if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
  110. # Only set this variable if there _is_ a parent scope.
  111. set(HAVE_MANPAGE_${title}_${section} ON PARENT_SCOPE)
  112. endif()
  113. endmacro()
  114. if(NOT HALIBUT)
  115. # If we don't have Halibut available to rebuild the man pages from
  116. # source, we must check whether the build and source directories
  117. # correspond, so as to suppress the build rules that copy them from
  118. # the source dir to the build dir. (Otherwise, someone unpacking
  119. # putty-src.zip and building on a system without Halibut will find
  120. # that there's a circular dependency in the makefile, which at least
  121. # Ninja complains about.)
  122. get_filename_component(DOCBUILDDIR ${CMAKE_CURRENT_BINARY_DIR} REALPATH)
  123. get_filename_component(DOCSRCDIR ${CMAKE_CURRENT_SOURCE_DIR} REALPATH)
  124. endif()
  125. macro(manpage title section)
  126. if(HALIBUT)
  127. add_custom_command(OUTPUT ${title}.${section}
  128. COMMAND ${HALIBUT} --man=${title}.${section}
  129. ${CMAKE_CURRENT_SOURCE_DIR}/mancfg.but
  130. ${CMAKE_CURRENT_SOURCE_DIR}/man-${title}.but
  131. DEPENDS
  132. mancfg.but man-${title}.but)
  133. register_manpage(${title} ${section})
  134. elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${title}.${section})
  135. # Our tarballs include prebuilt man pages in the source tree, so
  136. # they can be installed from there even if Halibut isn't available.
  137. if(NOT (DOCBUILDDIR STREQUAL DOCSRCDIR))
  138. # Iff the build tree isn't the source tree, they'll need copying
  139. # to the build tree first.
  140. add_custom_command(OUTPUT ${title}.${section}
  141. COMMAND ${CMAKE_COMMAND} -E copy_if_different
  142. ${CMAKE_CURRENT_SOURCE_DIR}/${title}.${section} ${title}.${section}
  143. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${title}.${section})
  144. endif()
  145. register_manpage(${title} ${section})
  146. endif()
  147. endmacro()
  148. manpage(putty 1)
  149. manpage(puttygen 1)
  150. manpage(plink 1)
  151. manpage(pscp 1)
  152. manpage(psftp 1)
  153. manpage(puttytel 1)
  154. manpage(pterm 1)
  155. manpage(pageant 1)
  156. manpage(psocks 1)
  157. manpage(psusan 1)
  158. add_custom_target(manpages ALL DEPENDS ${manpage_outputs})
  159. add_custom_target(doc DEPENDS ${doc_outputs} manpages)
  160. if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
  161. # If we're doing a cmake from just the doc subdir, we expect the
  162. # user to want to make all the documentation, including HTML and so
  163. # forth. (What else would be the point?)
  164. #
  165. # But if we're included from the main makefile, then by default we
  166. # only make the man pages (which are necessary for 'make install'),
  167. # and we leave everything else to a separate 'make doc' target which
  168. # the user can invoke if they need to.
  169. add_custom_target(doc-default ALL DEPENDS doc)
  170. endif()