|
| 1 | +cmake_minimum_required(VERSION 3.17.0 FATAL_ERROR) |
| 2 | + |
| 3 | +if (NOT BASIC_PROJECT_CONFIG_DONE) |
| 4 | + message(FATAL_ERROR "Before including the Sphinx module, the BasicConfig module must be included.") |
| 5 | +endif () |
| 6 | + |
| 7 | +option(NO_SPHINX "whether creation of Sphinx targets is disabled (enabled by default)" OFF) |
| 8 | +if (NO_SPHINX) |
| 9 | + return() |
| 10 | +endif () |
| 11 | + |
| 12 | +# find doxygen.h template |
| 13 | +include(TemplateFinder) |
| 14 | +find_template_file("sphinx-conf.py" CPP_UTILITIES SPHINX_TEMPLATE_FILE) |
| 15 | + |
| 16 | +# find executables |
| 17 | +find_program(SPHINX_BIN sphinx-build) |
| 18 | +if (NOT SPHINX_BIN) |
| 19 | + message(WARNING "Sphinx not found, unable to add target for generating documentation for ${META_TARGET_NAME}") |
| 20 | + return() |
| 21 | +endif () |
| 22 | + |
| 23 | +# configure paths and "conf.py" |
| 24 | +set(SPHINX_INPUT_FILES ${SPHINX_DOC_FILES}) |
| 25 | +if (NOT SPHINX_SOURCE_DIR) |
| 26 | + set(SPHINX_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") |
| 27 | +endif () |
| 28 | +set(SPHINX_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/sphinxconfig") |
| 29 | +set(SPHINX_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/doc") |
| 30 | +configure_file("${SPHINX_TEMPLATE_FILE}" "${SPHINX_CONFIG_DIR}/conf.py") |
| 31 | + |
| 32 | +# add target for generating documentation |
| 33 | +add_custom_target("${META_TARGET_NAME}_sphinxdoc" COMMAND "${SPHINX_BIN}" -c "${SPHINX_CONFIG_DIR}" "${SPHINX_SOURCE_DIR}" "${SPHINX_OUTPUT_DIR}") |
| 34 | +if (NOT TARGET sphinxdoc) |
| 35 | + add_custom_target(sphinxdoc) |
| 36 | +endif () |
| 37 | +add_dependencies(sphinxdoc "${META_TARGET_NAME}_sphinxdoc") |
| 38 | + |
| 39 | +# add install target for API documentation |
| 40 | +if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS) |
| 41 | + install( |
| 42 | + DIRECTORY "${SPHINX_OUTPUT_DIR}" |
| 43 | + DESTINATION "${META_DATA_DIR}" |
| 44 | + COMPONENT doc |
| 45 | + OPTIONAL) |
| 46 | + if (NOT TARGET install-doc) |
| 47 | + add_custom_target(install-doc COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=doc -P |
| 48 | + "${CMAKE_BINARY_DIR}/cmake_install.cmake") |
| 49 | + endif () |
| 50 | +endif () |
| 51 | + |
| 52 | +message(STATUS "Added target for building documentation for ${META_TARGET_NAME} with Sphinx") |
0 commit comments