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.

83 lines
3.0 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(DOC_DIR ${CMAKE_SOURCE_DIR}/doc)
  23. set(XMLTO_OPTS -m ${DOC_DIR}/manpage-normal.xsl -m ${DOC_DIR}/manpage-bold-literal.xsl man)
  24. set(ASCIIDOC_XML_OPTS -b docbook -d manpage -f ${DOC_DIR}/asciidoc.conf -aversion=${PROJECT_VERSION})
  25. set(ASCIIDOC_HTML_OPTS -b html4 -d article -f ${DOC_DIR}/asciidoc.conf -aversion=${PROJECT_VERSION})
  26. set(MAN_NAMES ss-local.1 ss-manager.1 ss-nat.1 ss-redir.1 ss-server.1 ss-tunnel.1 shadowsocks-libev.8)
  27. set(MAN_FILES)
  28. set(HTML_FILES)
  29. foreach (manfile IN LISTS MAN_NAMES)
  30. string(REGEX REPLACE \\.. .xml xmlfile ${manfile})
  31. string(REGEX REPLACE \\.. .asciidoc docfile ${manfile})
  32. string(REGEX REPLACE \\.. .html htmlfile ${manfile})
  33. set(docfile ${DOC_DIR}/${docfile})
  34. add_custom_command(OUTPUT ${manfile}
  35. COMMAND ${ASCIIDOC_EXECUTABLE} ${ASCIIDOC_XML_OPTS} -o ${xmlfile} ${docfile}
  36. COMMAND ${CMAKE_COMMAND} -E env ${XMLTO_ENV} ${XMLTO_EXECUTABLE} ${XMLTO_OPTS} ${xmlfile}
  37. # After we built the manpage, the xmlfile is nolongger needed
  38. COMMAND ${CMAKE_COMMAND} -E remove ${xmlfile}
  39. DEPENDS ${docfile}
  40. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/man
  41. COMMENT "Building manpage ${manfile}"
  42. VERBATIM)
  43. list(APPEND MAN_FILES ${manfile})
  44. add_custom_command(OUTPUT ${htmlfile}
  45. COMMAND ${ASCIIDOC_EXECUTABLE} ${ASCIIDOC_HTML_OPTS} -o ${htmlfile} ${docfile}
  46. DEPENDS ${docfile}
  47. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/html
  48. COMMENT "Building htmlfile ${htmlfile}"
  49. VERBATIM)
  50. list(APPEND HTML_FILES ${htmlfile})
  51. endforeach ()
  52. add_custom_target(doc-man ALL DEPENDS ${MAN_FILES})
  53. add_custom_target(doc-html ALL DEPENDS ${HTML_FILES})
  54. if (NOT WITH_DOC_MAN)
  55. set_target_properties(doc-man PROPERTIES EXCLUDE_FROM_ALL TRUE)
  56. else ()
  57. install(DIRECTORY ${CMAKE_BINARY_DIR}/man/
  58. DESTINATION man)
  59. endif ()
  60. if (NOT WITH_DOC_HTML)
  61. set_target_properties(doc-html PROPERTIES EXCLUDE_FROM_ALL TRUE)
  62. else ()
  63. install(DIRECTORY ${CMAKE_BINARY_DIR}/html/
  64. DESTINATION doc/html)
  65. endif ()
  66. # This is required for custom command
  67. file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/man)
  68. file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/html)