You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.4 KiB

  1. find_program(XMLTO_EXECUTABLE NAMES xmlto)
  2. find_program(ASCIIDOC_EXECUTABLE NAMES asciidoc asciidoc.py)
  3. # Opt-in doc build option
  4. if (NOT XMLTO_EXECUTABLE OR NOT ASCIIDOC_EXECUTABLE)
  5. option(WITH_DOC_MAN "Build manpage doc" OFF)
  6. else ()
  7. option(WITH_DOC_MAN "Build manpage doc" ON)
  8. endif ()
  9. if (NOT ASCIIDOC_EXECUTABLE)
  10. option(WITH_DOC_HTML "Build html doc" OFF)
  11. else ()
  12. option(WITH_DOC_HTML "Build html doc" ON)
  13. endif ()
  14. # NOTE For brew user, we have to setup this env var. see `brew info asciidoc'
  15. set(XMLTO_ENV)
  16. set(XMLTO_CATALOG_DIR_MACOS /usr/local/etc/xml/catalog)
  17. if (EXISTS ${XMLTO_CATALOG_DIR_MACOS})
  18. set(XMLTO_ENV XML_CATALOG_FILES=${XMLTO_CATALOG_DIR_MACOS})
  19. message(STATUS "Detect xmlto catalog dir ${XMLTO_CATALOG_DIR_MACOS}")
  20. endif ()
  21. set(CMAKE_MANPAGE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/man)
  22. set(CMAKE_HTML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/html)
  23. set(DOC_DIR ${CMAKE_SOURCE_DIR}/doc)
  24. set(XMLTO_OPTS -m ${DOC_DIR}/manpage-normal.xsl -m ${DOC_DIR}/manpage-bold-literal.xsl man)
  25. set(ASCIIDOC_XML_OPTS -b docbook -d manpage -f ${DOC_DIR}/asciidoc.conf -aversion=${PROJECT_VERSION})
  26. set(ASCIIDOC_HTML_OPTS -b html4 -d article -f ${DOC_DIR}/asciidoc.conf -aversion=${PROJECT_VERSION})
  27. set(MAN_NAMES ss-local.1 ss-manager.1 ss-nat.1 ss-redir.1 ss-server.1 ss-tunnel.1 shadowsocks-libev.8)
  28. set(MAN_FILES)
  29. set(HTML_FILES)
  30. foreach (manfile IN LISTS MAN_NAMES)
  31. string(REGEX REPLACE \\.. .xml xmlfile ${manfile})
  32. string(REGEX REPLACE \\.. .asciidoc docfile ${manfile})
  33. string(REGEX REPLACE \\.. .html htmlfile ${manfile})
  34. set(manfile ${CMAKE_MANPAGE_OUTPUT_DIRECTORY}/${manfile})
  35. set(htmlfile ${CMAKE_HTML_OUTPUT_DIRECTORY}/${htmlfile})
  36. set(docfile ${DOC_DIR}/${docfile})
  37. add_custom_command(OUTPUT ${manfile}
  38. COMMAND ${ASCIIDOC_EXECUTABLE} ${ASCIIDOC_XML_OPTS} -o ${xmlfile} ${docfile}
  39. COMMAND ${CMAKE_COMMAND} -E env ${XMLTO_ENV} ${XMLTO_EXECUTABLE} ${XMLTO_OPTS} ${xmlfile}
  40. # After we built the manpage, the xmlfile is nolongger needed
  41. COMMAND ${CMAKE_COMMAND} -E remove ${xmlfile}
  42. DEPENDS ${docfile}
  43. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/man
  44. COMMENT "Building manpage ${manfile}"
  45. VERBATIM)
  46. list(APPEND MAN_FILES ${manfile})
  47. add_custom_command(OUTPUT ${htmlfile}
  48. COMMAND ${ASCIIDOC_EXECUTABLE} ${ASCIIDOC_HTML_OPTS} -o ${htmlfile} ${docfile}
  49. DEPENDS ${docfile}
  50. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/html
  51. COMMENT "Building htmlfile ${htmlfile}"
  52. VERBATIM)
  53. list(APPEND HTML_FILES ${htmlfile})
  54. endforeach ()
  55. add_custom_target(doc-man ALL DEPENDS ${MAN_FILES})
  56. add_custom_target(doc-html ALL DEPENDS ${HTML_FILES})
  57. if (NOT WITH_DOC_MAN)
  58. set_target_properties(doc-man PROPERTIES EXCLUDE_FROM_ALL TRUE)
  59. else ()
  60. install(DIRECTORY ${CMAKE_BINARY_DIR}/man/
  61. DESTINATION share/man/man1
  62. FILES_MATCHING PATTERN "*.1"
  63. )
  64. install(DIRECTORY ${CMAKE_BINARY_DIR}/man/
  65. DESTINATION share/man/man8
  66. FILES_MATCHING PATTERN "*.8"
  67. )
  68. endif ()
  69. if (NOT WITH_DOC_HTML)
  70. set_target_properties(doc-html PROPERTIES EXCLUDE_FROM_ALL TRUE)
  71. else ()
  72. install(DIRECTORY ${CMAKE_BINARY_DIR}/html/
  73. DESTINATION share/doc/${PROJECT_NAME})
  74. endif ()
  75. # This is required for custom command
  76. file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/man)
  77. file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/html)