CMakeLists.txt 5.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. find_package(Sphinx)
  2. find_package(LATEX)
  3. set(DOC_LATEX_DIR ${PROJECT_BINARY_DIR}/doc_latex)
  4. set(DOC_HTML_DIR ${PROJECT_BINARY_DIR}/doc)
  5. set(DOC_SRC_DIR ${PROJECT_BINARY_DIR}/doc_src)
  6. make_directory(${DOC_SRC_DIR})
  7. # Copy all files from /doc dir to the /doc_src dir. doc_src is used to compile the documentation.
  8. # Use custom copy command to make sure files are correctly updated when they are changed.
  9. file(GLOB DOC_SRC "${PROJECT_SOURCE_DIR}/doc/*")
  10. list(REMOVE_ITEM DOC_SRC "${PROJECT_SOURCE_DIR}/doc/conf.py")
  11. list(REMOVE_ITEM DOC_SRC "${PROJECT_SOURCE_DIR}/doc/CMakeLists.txt")
  12. string(REPLACE "${PROJECT_SOURCE_DIR}/doc" "${DOC_SRC_DIR}" DOC_TARGET "${DOC_SRC}")
  13. add_custom_command(OUTPUT ${DOC_TARGET}
  14. PRE_BUILD
  15. DEPENDS ${DOC_SRC}
  16. COMMAND ${CMAKE_COMMAND}
  17. ARGS -E copy ${DOC_SRC} ${DOC_SRC_DIR}
  18. )
  19. configure_file("${PROJECT_SOURCE_DIR}/doc/conf.py" "${DOC_SRC_DIR}/conf.py")
  20. list(APPEND GENERATED_RST "")
  21. macro(generate_rst in out)
  22. add_custom_command(OUTPUT ${out}
  23. DEPENDS ${PROJECT_SOURCE_DIR}/tools/c2rst.py ${in}
  24. PRE_BUILD
  25. COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/c2rst.py ${in} ${out})
  26. list(APPEND GENERATED_RST "${out}")
  27. endmacro()
  28. # Doc from headers
  29. generate_rst(${PROJECT_SOURCE_DIR}/include/open62541/types.h ${DOC_SRC_DIR}/types.rst)
  30. generate_rst(${PROJECT_SOURCE_DIR}/include/open62541/constants.h ${DOC_SRC_DIR}/constants.rst)
  31. generate_rst(${PROJECT_BINARY_DIR}/src_generated/open62541/statuscodes.h ${DOC_SRC_DIR}/statuscodes.rst)
  32. generate_rst(${PROJECT_BINARY_DIR}/src_generated/open62541/types_generated.h ${DOC_SRC_DIR}/types_generated.rst)
  33. generate_rst(${PROJECT_SOURCE_DIR}/include/open62541/server_config.h ${DOC_SRC_DIR}/server_config.rst)
  34. generate_rst(${PROJECT_SOURCE_DIR}/include/open62541/server.h ${DOC_SRC_DIR}/server.rst)
  35. generate_rst(${PROJECT_SOURCE_DIR}/include/open62541/client_config.h ${DOC_SRC_DIR}/client_config.rst)
  36. generate_rst(${PROJECT_SOURCE_DIR}/include/open62541/client_subscriptions.h ${DOC_SRC_DIR}/client_subscriptions.rst)
  37. generate_rst(${PROJECT_SOURCE_DIR}/include/open62541/client.h ${DOC_SRC_DIR}/client.rst)
  38. generate_rst(${PROJECT_SOURCE_DIR}/include/open62541/client_highlevel.h ${DOC_SRC_DIR}/client_highlevel.rst)
  39. generate_rst(${PROJECT_SOURCE_DIR}/include/open62541/plugin/log.h ${DOC_SRC_DIR}/plugin_log.rst)
  40. generate_rst(${PROJECT_SOURCE_DIR}/include/open62541/plugin/network.h ${DOC_SRC_DIR}/plugin_network.rst)
  41. generate_rst(${PROJECT_SOURCE_DIR}/include/open62541/plugin/accesscontrol.h ${DOC_SRC_DIR}/plugin_accesscontrol.rst)
  42. generate_rst(${PROJECT_SOURCE_DIR}/src/server/ua_services.h ${DOC_SRC_DIR}/services.rst)
  43. generate_rst(${PROJECT_SOURCE_DIR}/include/open62541/plugin/nodestore.h ${DOC_SRC_DIR}/nodestore.rst)
  44. generate_rst(${PROJECT_SOURCE_DIR}/include/open62541/plugin/pubsub.h ${DOC_SRC_DIR}/plugin_pubsub_connection.rst)
  45. generate_rst(${PROJECT_SOURCE_DIR}/include/open62541/server_pubsub.h ${DOC_SRC_DIR}/pubsub.rst)
  46. # Doc from tutorial code
  47. generate_rst(${PROJECT_SOURCE_DIR}/examples/tutorial_datatypes.c ${DOC_SRC_DIR}/tutorial_datatypes.rst)
  48. generate_rst(${PROJECT_SOURCE_DIR}/examples/tutorial_server_firststeps.c ${DOC_SRC_DIR}/tutorial_server_firststeps.rst)
  49. generate_rst(${PROJECT_SOURCE_DIR}/examples/tutorial_server_variable.c ${DOC_SRC_DIR}/tutorial_server_variable.rst)
  50. generate_rst(${PROJECT_SOURCE_DIR}/examples/tutorial_server_variabletype.c ${DOC_SRC_DIR}/tutorial_server_variabletype.rst)
  51. generate_rst(${PROJECT_SOURCE_DIR}/examples/tutorial_server_datasource.c ${DOC_SRC_DIR}/tutorial_server_datasource.rst)
  52. generate_rst(${PROJECT_SOURCE_DIR}/examples/tutorial_server_events.c ${DOC_SRC_DIR}/tutorial_server_events.rst)
  53. generate_rst(${PROJECT_SOURCE_DIR}/examples/tutorial_server_monitoreditems.c ${DOC_SRC_DIR}/tutorial_server_monitoreditems.rst)
  54. generate_rst(${PROJECT_SOURCE_DIR}/examples/tutorial_server_object.c ${DOC_SRC_DIR}/tutorial_server_object.rst)
  55. generate_rst(${PROJECT_SOURCE_DIR}/examples/tutorial_server_method.c ${DOC_SRC_DIR}/tutorial_server_method.rst)
  56. generate_rst(${PROJECT_SOURCE_DIR}/examples/tutorial_client_firststeps.c ${DOC_SRC_DIR}/tutorial_client_firststeps.rst)
  57. generate_rst(${PROJECT_SOURCE_DIR}/examples/pubsub/tutorial_pubsub_publish.c ${DOC_SRC_DIR}/tutorial_pubsub_publish.rst)
  58. # Doc targets
  59. add_custom_target(doc_latex ${SPHINX_EXECUTABLE}
  60. -b latex "${DOC_SRC_DIR}" "${DOC_LATEX_DIR}"
  61. DEPENDS ${GENERATED_RST} ${DOC_TARGET}
  62. COMMENT "Building LaTeX sources for documentation with Sphinx")
  63. add_dependencies(doc_latex open62541)
  64. add_custom_target(doc_pdf ${PDFLATEX_COMPILER} -interaction=batchmode "open62541.tex"
  65. WORKING_DIRECTORY ${DOC_LATEX_DIR}
  66. # compile it twice so that the contents pages are correct
  67. COMMAND ${PDFLATEX_COMPILER} -interaction=batchmode "open62541.tex"
  68. DEPENDS ${PDFLATEX_COMPILER}
  69. COMMENT "Generating PDF documentation from LaTeX sources")
  70. add_dependencies(doc_pdf doc_latex)
  71. add_custom_target(doc ${SPHINX_EXECUTABLE}
  72. -b html "${DOC_SRC_DIR}" "${DOC_HTML_DIR}"
  73. DEPENDS ${GENERATED_RST} ${DOC_TARGET}
  74. COMMENT "Building HTML documentation with Sphinx")
  75. add_dependencies(doc open62541)
  76. set_target_properties(doc doc_latex doc_pdf PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD TRUE)
  77. set_target_properties(doc doc_latex doc_pdf PROPERTIES FOLDER "open62541/doc")