| 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("${META_PROJECT_VARNAME_UPPER}_SPHINX_CONFIG_DIR" |
| 29 |
"${CMAKE_CURRENT_BINARY_DIR}/sphinxconfig" |
| 30 |
CACHE PATH "config directory for Sphinx documentation") |
| 31 |
set("${META_PROJECT_VARNAME_UPPER}_SPHINX_OUTPUT_DIR" |
| 32 |
"${CMAKE_CURRENT_BINARY_DIR}/doc" |
| 33 |
CACHE PATH "output directory for Sphinx documentation") |
| 34 |
set(SPHINX_CONFIG_DIR "${${META_PROJECT_VARNAME_UPPER}_SPHINX_CONFIG_DIR}") |
| 35 |
set(SPHINX_OUTPUT_DIR "${${META_PROJECT_VARNAME_UPPER}_SPHINX_OUTPUT_DIR}") |
| 36 |
configure_file("${SPHINX_TEMPLATE_FILE}" "${SPHINX_CONFIG_DIR}/conf.py") |
| 37 |
|
| 38 |
# add target for generating documentation |
| 39 |
add_custom_target("${META_TARGET_NAME}_sphinxdoc" COMMAND "${SPHINX_BIN}" -c "${SPHINX_CONFIG_DIR}" "${SPHINX_SOURCE_DIR}" |
| 40 |
"${SPHINX_OUTPUT_DIR}") |
| 41 |
if (NOT TARGET sphinxdoc) |
| 42 |
add_custom_target(sphinxdoc) |
| 43 |
endif () |
| 44 |
add_dependencies(sphinxdoc "${META_TARGET_NAME}_sphinxdoc") |
| 45 |
|
| 46 |
# add install target for API documentation |
| 47 |
if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS) |
| 48 |
install( |
| 49 |
DIRECTORY "${SPHINX_OUTPUT_DIR}" |
| 50 |
DESTINATION "${META_DATA_DIR}" |
| 51 |
COMPONENT doc |
| 52 |
OPTIONAL) |
| 53 |
if (NOT TARGET install-doc) |
| 54 |
add_custom_target(install-doc COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=doc -P |
| 55 |
"${CMAKE_BINARY_DIR}/cmake_install.cmake") |
| 56 |
endif () |
| 57 |
endif () |
| 58 |
|
| 59 |
message(STATUS "Added target for building documentation for ${META_TARGET_NAME} with Sphinx") |