CMakeLists.txt 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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}/privacy.but
  77. ${CMAKE_CURRENT_SOURCE_DIR}/index.but
  78. ${VERSION_BUT})
  79. # The HTML manual goes in a subdirectory, for convenience.
  80. set(html_dir ${CMAKE_CURRENT_BINARY_DIR}/html)
  81. file(MAKE_DIRECTORY ${html_dir})
  82. add_custom_command(OUTPUT ${html_dir}/index.html
  83. COMMAND ${HALIBUT} --html ${manual_sources}
  84. WORKING_DIRECTORY ${html_dir}
  85. DEPENDS ${manual_sources} ${manual_dependencies})
  86. list(APPEND doc_outputs ${html_dir}/index.html)
  87. # Windows help.
  88. file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/chmextra.but
  89. "\\cfg{chm-extra-file}{${CMAKE_CURRENT_SOURCE_DIR}/chm.css}{chm.css}\n")
  90. add_custom_command(OUTPUT putty.chm
  91. COMMAND ${HALIBUT} --chm chmextra.but ${manual_sources}
  92. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  93. DEPENDS ${manual_sources} ${manual_dependencies})
  94. list(APPEND doc_outputs putty.chm)
  95. # Plain text.
  96. add_custom_command(OUTPUT puttydoc.txt
  97. COMMAND ${HALIBUT} --text ${manual_sources}
  98. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  99. DEPENDS ${manual_sources} ${manual_dependencies})
  100. list(APPEND doc_outputs puttydoc.txt)
  101. # PDF. (We don't ship this; so it's only built on explicit request.)
  102. add_custom_command(OUTPUT putty.pdf
  103. COMMAND ${HALIBUT} --pdf ${manual_sources}
  104. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  105. DEPENDS ${manual_sources} ${manual_dependencies})
  106. add_custom_target(pdf DEPENDS putty.pdf)
  107. endif()
  108. macro(register_manpage title section)
  109. list(APPEND manpage_outputs ${title}.${section})
  110. if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
  111. # Only set this variable if there _is_ a parent scope.
  112. set(HAVE_MANPAGE_${title}_${section} ON PARENT_SCOPE)
  113. endif()
  114. endmacro()
  115. if(NOT HALIBUT)
  116. # If we don't have Halibut available to rebuild the man pages from
  117. # source, we must check whether the build and source directories
  118. # correspond, so as to suppress the build rules that copy them from
  119. # the source dir to the build dir. (Otherwise, someone unpacking
  120. # putty-src.zip and building on a system without Halibut will find
  121. # that there's a circular dependency in the makefile, which at least
  122. # Ninja complains about.)
  123. get_filename_component(DOCBUILDDIR ${CMAKE_CURRENT_BINARY_DIR} REALPATH)
  124. get_filename_component(DOCSRCDIR ${CMAKE_CURRENT_SOURCE_DIR} REALPATH)
  125. endif()
  126. macro(manpage title section)
  127. if(HALIBUT)
  128. add_custom_command(OUTPUT ${title}.${section}
  129. COMMAND ${HALIBUT} --man=${title}.${section}
  130. ${CMAKE_CURRENT_SOURCE_DIR}/mancfg.but
  131. ${CMAKE_CURRENT_SOURCE_DIR}/man-${title}.but
  132. DEPENDS
  133. mancfg.but man-${title}.but)
  134. register_manpage(${title} ${section})
  135. elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${title}.${section})
  136. # Our tarballs include prebuilt man pages in the source tree, so
  137. # they can be installed from there even if Halibut isn't available.
  138. if(NOT (DOCBUILDDIR STREQUAL DOCSRCDIR))
  139. # Iff the build tree isn't the source tree, they'll need copying
  140. # to the build tree first.
  141. add_custom_command(OUTPUT ${title}.${section}
  142. COMMAND ${CMAKE_COMMAND} -E copy_if_different
  143. ${CMAKE_CURRENT_SOURCE_DIR}/${title}.${section} ${title}.${section}
  144. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${title}.${section})
  145. endif()
  146. register_manpage(${title} ${section})
  147. endif()
  148. endmacro()
  149. manpage(putty 1)
  150. manpage(puttygen 1)
  151. manpage(plink 1)
  152. manpage(pscp 1)
  153. manpage(psftp 1)
  154. manpage(puttytel 1)
  155. manpage(pterm 1)
  156. manpage(pageant 1)
  157. manpage(psocks 1)
  158. manpage(psusan 1)
  159. add_custom_target(manpages ALL DEPENDS ${manpage_outputs})
  160. add_custom_target(doc DEPENDS ${doc_outputs} manpages)
  161. if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
  162. # If we're doing a cmake from just the doc subdir, we expect the
  163. # user to want to make all the documentation, including HTML and so
  164. # forth. (What else would be the point?)
  165. #
  166. # But if we're included from the main makefile, then by default we
  167. # only make the man pages (which are necessary for 'make install'),
  168. # and we leave everything else to a separate 'make doc' target which
  169. # the user can invoke if they need to.
  170. add_custom_target(doc-default ALL DEPENDS doc)
  171. endif()