CMakeLists.txt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # The following will be generated or updated when the 'doc' target is built:
  2. # • user guide and man pages: if BUILD_DOCS is set
  3. # • HTML versions of the above: if BUILD_DOCS and BUILD_WEB_DOCS are set
  4. # • Doxygen / reference documentation: if USE_DOXYGEN is set
  5. ########################################################################
  6. configure_file(
  7. ${PROJECT_SOURCE_DIR}/doc/version.texi.in
  8. ${PROJECT_BINARY_DIR}/doc/version.texi)
  9. if (USE_DOXYGEN)
  10. find_package(Doxygen)
  11. if (NOT DOXYGEN_FOUND)
  12. message(FATAL_ERROR "Could not find doxygen. Reference documentation cannot be built.")
  13. endif()
  14. configure_file(Doxyfile.in Doxyfile @ONLY)
  15. # see INPUT/FILE_PATTERNS in Doxyfile.in
  16. file(GLOB doxygen_input_files ${CMAKE_SOURCE_DIR}/src/*.h)
  17. add_custom_command(OUTPUT html/index.html
  18. COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile
  19. DEPENDS Doxyfile ${doxygen_input_files}
  20. COMMENT "Building doxygen documentation")
  21. add_custom_target(doc.doxygen DEPENDS html/index.html)
  22. else()
  23. add_custom_target(doc.doxygen)
  24. endif()
  25. ########################################################################
  26. # BUILD_WEB_DOCS implies BUILD_DOCS
  27. if (BUILD_WEB_DOCS)
  28. set(BUILD_DOCS 1)
  29. endif()
  30. if (BUILD_DOCS)
  31. find_program(MAKEINFO makeinfo)
  32. find_program(TEXI2PDF texi2pdf)
  33. find_program(TEX tex)
  34. find_program(MAN2HTML man2html)
  35. find_program(GROFF groff)
  36. set(ledger_info_files ledger3.texi ledger-mode.texi)
  37. if (NOT MAKEINFO)
  38. message(WARNING "Could not find makeinfo. Info version of documentation cannot be built.")
  39. endif()
  40. if (NOT TEXI2PDF OR NOT TEX)
  41. message(WARNING "Could not find texi2pdf or tex. PDF version of documentation will not be built.")
  42. endif()
  43. endif()
  44. ########################################################################
  45. foreach(file ${ledger_info_files})
  46. get_filename_component(file_base ${file} NAME_WE)
  47. if (MAKEINFO)
  48. add_custom_command(OUTPUT ${file_base}.info
  49. COMMAND makeinfo --force --no-split -o ${file_base}.info ${CMAKE_CURRENT_SOURCE_DIR}/${file}
  50. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
  51. VERBATIM)
  52. list(APPEND ledger_doc_files ${file_base}.info)
  53. endif()
  54. if (BUILD_WEB_DOCS AND MAKEINFO)
  55. add_custom_command(OUTPUT ${file_base}.html
  56. COMMAND makeinfo --force --html --no-split -o ${file_base}.html ${CMAKE_CURRENT_SOURCE_DIR}/${file}
  57. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
  58. VERBATIM)
  59. list(APPEND ledger_doc_files ${file_base}.html)
  60. endif()
  61. if (TEXI2PDF AND TEX)
  62. if (BUILD_A4_PDF)
  63. set(papersize --texinfo=@afourpaper)
  64. endif()
  65. add_custom_command(OUTPUT ${file_base}.pdf
  66. COMMAND texi2pdf ${papersize} -b -q -o ${file_base}.pdf ${CMAKE_CURRENT_SOURCE_DIR}/${file}
  67. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file}
  68. VERBATIM)
  69. list(APPEND ledger_doc_files ${file_base}.pdf)
  70. endif()
  71. endforeach()
  72. ########################################################################
  73. if (BUILD_WEB_DOCS)
  74. include(FindUnixCommands)
  75. if (NOT BASH)
  76. message(FATAL_ERROR "Could not find bash. Unable to build documentation.")
  77. endif()
  78. if (MAN2HTML)
  79. add_custom_command(OUTPUT ledger.1.html
  80. COMMAND ${BASH} -c "man2html ${CMAKE_CURRENT_SOURCE_DIR}/ledger.1 | tail -n+3 > ledger.1.html"
  81. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ledger.1
  82. VERBATIM)
  83. list(APPEND ledger_doc_files ledger.1.html)
  84. elseif(GROFF)
  85. add_custom_command(OUTPUT ledger.1.html
  86. COMMAND ${BASH} -c "groff -mandoc -Thtml ${CMAKE_CURRENT_SOURCE_DIR}/ledger.1 > ledger.1.html"
  87. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ledger.1
  88. VERBATIM)
  89. list(APPEND ledger_doc_files ledger.1.html)
  90. else()
  91. message(FATAL_ERROR "Could not find man2html or groff. HTML version of man page cannot be built.")
  92. endif()
  93. endif(BUILD_WEB_DOCS)
  94. ########################################################################
  95. add_custom_target(doc DEPENDS ${ledger_doc_files} doc.doxygen)
  96. ########################################################################
  97. include(GNUInstallDirs)
  98. if (CMAKE_INSTALL_MANDIR)
  99. install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/ledger.1
  100. DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
  101. endif(CMAKE_INSTALL_MANDIR)
  102. foreach(file ${ledger_doc_files})
  103. get_filename_component(file_ext ${file} EXT)
  104. if(file_ext STREQUAL ".info")
  105. if(CMAKE_INSTALL_INFODIR)
  106. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${file}
  107. DESTINATION ${CMAKE_INSTALL_INFODIR} COMPONENT doc)
  108. endif()
  109. elseif(CMAKE_INSTALL_DOCDIR)
  110. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${file}
  111. DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT doc)
  112. endif()
  113. endforeach()