| 1 |
# porcelain for documentation generation tools |
| 2 |
|
| 3 |
# Run sphinx |
| 4 |
# |
| 5 |
# usage: |
| 6 |
# ~~~ |
| 7 |
# sphinx(<module> |
| 8 |
# changlog.rst |
| 9 |
# index.rst |
| 10 |
# todo.rst |
| 11 |
# README.rst) |
| 12 |
# ~~~ |
| 13 |
function(sphinx module) |
| 14 |
set(stamp_path_ ${CMAKE_CURRENT_BINARY_DIR}/${module}_doc.stamp) |
| 15 |
add_custom_command( |
| 16 |
OUTPUT ${stamp_path_} |
| 17 |
COMMAND env PYTHONPATH=${CMAKE_SOURCE_DIR} sphinx-build -M html |
| 18 |
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} |
| 19 |
COMMAND touch ${stamp_path_} |
| 20 |
DEPENDS ${ARGN} conf.py ${CMAKE_SOURCE_DIR}/doc/conf.py |
| 21 |
${CMAKE_SOURCE_DIR}/doc/sphinx-static/css/cheshire_theme.css |
| 22 |
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) |
| 23 |
add_custom_target(${module}-doc DEPENDS ${stamp_path_}) |
| 24 |
add_custom_target( |
| 25 |
show-${module}-doc |
| 26 |
COMMAND xdg-open ${CMAKE_CURRENT_BINARY_DIR}/html/index.html |
| 27 |
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/cmake_format_doc.stamp) |
| 28 |
add_dependencies(doc ${module}-doc) |
| 29 |
endfunction() |
| 30 |
|
| 31 |
# Run sphinx |
| 32 |
# |
| 33 |
# usage: |
| 34 |
# ~~~ |
| 35 |
# autosphinx( |
| 36 |
# module |
| 37 |
# ADDITIONAL_SOURCES [source1, [source2, [...]]] |
| 38 |
# ) |
| 39 |
# ~~~ |
| 40 |
function(autosphinx module) |
| 41 |
set(options) |
| 42 |
set(one_value_args) |
| 43 |
set(multi_value_args ADDITIONAL_SOURCES) |
| 44 |
cmake_parse_arguments(arg "${options}" "${one_value_args}" |
| 45 |
"${multi_value_args}" ${ARGN}) |
| 46 |
|
| 47 |
add_custom_target( |
| 48 |
scanrst-${module}-doc |
| 49 |
COMMAND |
| 50 |
python -B ${CMAKE_SOURCE_DIR}/doc/find_rst.py --manifest-path |
| 51 |
${CMAKE_CURRENT_BINARY_DIR}/rst_manifest.txt --touch |
| 52 |
${CMAKE_SOURCE_DIR}/${module} |
| 53 |
DEPENDS ${CMAKE_SOURCE_DIR}/doc/find_rst.py |
| 54 |
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/rst_manifest.txt |
| 55 |
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 56 |
COMMENT "Scanning RST for ${module}") |
| 57 |
|
| 58 |
if(NOT CMAKE_GENERATOR STREQUAL "Ninja") |
| 59 |
add_custom_command( |
| 60 |
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rst_manifest.txt |
| 61 |
COMMAND true |
| 62 |
DEPENDS scanrst-${module}_docs |
| 63 |
COMMENT "Stubbing RST scan for ${module}_doc") |
| 64 |
endif() |
| 65 |
|
| 66 |
add_custom_command( |
| 67 |
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${module}_doc.stamp |
| 68 |
COMMAND env PYTHONPATH=${CMAKE_SOURCE_DIR} sphinx-build -M html |
| 69 |
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} |
| 70 |
COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/${module}_doc.stamp |
| 71 |
DEPENDS conf.py |
| 72 |
${CMAKE_CURRENT_BINARY_DIR}/rst_manifest.txt |
| 73 |
${CMAKE_SOURCE_DIR}/doc/conf.py |
| 74 |
${CMAKE_SOURCE_DIR}/doc/sphinx-static/css/cheshire_theme.css |
| 75 |
${args_ADDITIONAL_SOURCES} |
| 76 |
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) |
| 77 |
|
| 78 |
add_custom_target(${module}-doc |
| 79 |
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${module}_doc.stamp) |
| 80 |
|
| 81 |
add_custom_target( |
| 82 |
show-${module}-doc |
| 83 |
COMMAND xdg-open ${CMAKE_CURRENT_BINARY_DIR}/html/index.html |
| 84 |
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${module}_doc.stamp) |
| 85 |
|
| 86 |
add_dependencies(doc ${module}-doc) |
| 87 |
|
| 88 |
endfunction() |
| 89 |
|
| 90 |
# Generate rules to copy a list of files into a common directory at build time |
| 91 |
function(stage_files) |
| 92 |
cmake_parse_arguments(_args "" "SOURCEDIR;STAGE;LIST" "FILES" ${ARGN}) |
| 93 |
set(copyfiles ${${_args_LIST}}) |
| 94 |
foreach(copyfile ${_args_FILES}) |
| 95 |
if("${copyfile}" MATCHES "([^:]+):([^:]+)") |
| 96 |
set(srcfile ${CMAKE_MATCH_1}) |
| 97 |
set(tgtfile ${CMAKE_MATCH_2}) |
| 98 |
else() |
| 99 |
set(srcfile "${copyfile}") |
| 100 |
set(tgtfile "${copyfile}") |
| 101 |
endif() |
| 102 |
add_custom_command( |
| 103 |
OUTPUT ${_args_STAGE}/${tgtfile} |
| 104 |
COMMAND ${CMAKE_COMMAND} -E copy ${_args_SOURCEDIR}/${srcfile} |
| 105 |
${_args_STAGE}/${tgtfile} |
| 106 |
DEPENDS ${_args_SOURCEDIR}/${srcfile}) |
| 107 |
list(APPEND copyfiles ${_args_STAGE}/${tgtfile}) |
| 108 |
endforeach() |
| 109 |
set(${_args_LIST} |
| 110 |
${copyfiles} |
| 111 |
PARENT_SCOPE) |
| 112 |
endfunction() |