File: doctools.cmake

package info (click to toggle)
cmake-format 0.6.13-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,436 kB
  • sloc: python: 16,990; makefile: 14
file content (112 lines) | stat: -rw-r--r-- 3,658 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# porcelain for documentation generation tools

# Run sphinx
#
# usage:
# ~~~
# sphinx(<module>
#        changlog.rst
#        index.rst
#        todo.rst
#        README.rst)
# ~~~
function(sphinx module)
  set(stamp_path_ ${CMAKE_CURRENT_BINARY_DIR}/${module}_doc.stamp)
  add_custom_command(
    OUTPUT ${stamp_path_}
    COMMAND env PYTHONPATH=${CMAKE_SOURCE_DIR} sphinx-build -M html
            ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
    COMMAND touch ${stamp_path_}
    DEPENDS ${ARGN} conf.py ${CMAKE_SOURCE_DIR}/doc/conf.py
            ${CMAKE_SOURCE_DIR}/doc/sphinx-static/css/cheshire_theme.css
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
  add_custom_target(${module}-doc DEPENDS ${stamp_path_})
  add_custom_target(
    show-${module}-doc
    COMMAND xdg-open ${CMAKE_CURRENT_BINARY_DIR}/html/index.html
    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/cmake_format_doc.stamp)
  add_dependencies(doc ${module}-doc)
endfunction()

# Run sphinx
#
# usage:
# ~~~
# autosphinx(
#   module
#   ADDITIONAL_SOURCES [source1, [source2, [...]]]
# )
# ~~~
function(autosphinx module)
  set(options)
  set(one_value_args)
  set(multi_value_args ADDITIONAL_SOURCES)
  cmake_parse_arguments(arg "${options}" "${one_value_args}"
                        "${multi_value_args}" ${ARGN})

  add_custom_target(
    scanrst-${module}-doc
    COMMAND
      python -B ${CMAKE_SOURCE_DIR}/doc/find_rst.py --manifest-path
      ${CMAKE_CURRENT_BINARY_DIR}/rst_manifest.txt --touch
      ${CMAKE_SOURCE_DIR}/${module}
    DEPENDS ${CMAKE_SOURCE_DIR}/doc/find_rst.py
    BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/rst_manifest.txt
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    COMMENT "Scanning RST for ${module}")

  if(NOT CMAKE_GENERATOR STREQUAL "Ninja")
    add_custom_command(
      OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rst_manifest.txt
      COMMAND true
      DEPENDS scanrst-${module}_docs
      COMMENT "Stubbing RST scan for ${module}_doc")
  endif()

  add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${module}_doc.stamp
    COMMAND env PYTHONPATH=${CMAKE_SOURCE_DIR} sphinx-build -M html
            ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
    COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/${module}_doc.stamp
    DEPENDS conf.py
            ${CMAKE_CURRENT_BINARY_DIR}/rst_manifest.txt
            ${CMAKE_SOURCE_DIR}/doc/conf.py
            ${CMAKE_SOURCE_DIR}/doc/sphinx-static/css/cheshire_theme.css
            ${args_ADDITIONAL_SOURCES}
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

  add_custom_target(${module}-doc
                    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${module}_doc.stamp)

  add_custom_target(
    show-${module}-doc
    COMMAND xdg-open ${CMAKE_CURRENT_BINARY_DIR}/html/index.html
    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${module}_doc.stamp)

  add_dependencies(doc ${module}-doc)

endfunction()

# Generate rules to copy a list of files into a common directory at build time
function(stage_files)
  cmake_parse_arguments(_args "" "SOURCEDIR;STAGE;LIST" "FILES" ${ARGN})
  set(copyfiles ${${_args_LIST}})
  foreach(copyfile ${_args_FILES})
    if("${copyfile}" MATCHES "([^:]+):([^:]+)")
      set(srcfile ${CMAKE_MATCH_1})
      set(tgtfile ${CMAKE_MATCH_2})
    else()
      set(srcfile "${copyfile}")
      set(tgtfile "${copyfile}")
    endif()
    add_custom_command(
      OUTPUT ${_args_STAGE}/${tgtfile}
      COMMAND ${CMAKE_COMMAND} -E copy ${_args_SOURCEDIR}/${srcfile}
              ${_args_STAGE}/${tgtfile}
      DEPENDS ${_args_SOURCEDIR}/${srcfile})
    list(APPEND copyfiles ${_args_STAGE}/${tgtfile})
  endforeach()
  set(${_args_LIST}
      ${copyfiles}
      PARENT_SCOPE)
endfunction()