-
-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
190 lines (186 loc) · 6.08 KB
/
Copy pathCMakeLists.txt
File metadata and controls
190 lines (186 loc) · 6.08 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
cmake_minimum_required(VERSION 3.10)
if(MKDOCS_FOUND)
project(generate_docs)
# --path-override key=value redirects a path-resolver token directly at the path_manager.
# (Renamed from --path; the old name collided with `settings --path`.)
if(WIN32)
set(MODULE_ARG "module-path=\${base-path}/modules")
# docs_extract.py imports the generated *_pb2.py, which PythonScript adds to
# sys.path from ${scripts}/python/lib. Point ${scripts} at the build tree
# (where protoc generated them) so this works without `make install`.
set(SCRIPTS_ARG "scripts=\${base-path}/scripts")
set(COMMAND_LINE
${CMAKE_BINARY_DIR}/nscp
client
--module
PythonScript
--settings
dummy
--load-all
--log
info
--log
oneline
--path-override
"${MODULE_ARG}"
--path-override
"${SCRIPTS_ARG}"
--
execute
--script
scripts/python/docs_extract.py
--input
docs
--output
docs
)
else()
set(MODULE_ARG "module-path=${CMAKE_BINARY_DIR}/modules")
set(LOG_ARG "log-path=.")
set(DATA_ARGS "data-path=.")
# docs_extract.py imports the generated *_pb2.py, which PythonScript adds to
# sys.path from ${scripts}/python/lib. Point ${scripts} at the build tree
# (where protoc generated them) so this works without `make install`.
set(SCRIPTS_ARG "scripts=${CMAKE_BINARY_DIR}/scripts")
set(COMMAND_LINE
${CMAKE_BINARY_DIR}/nscp
client
--module
PythonScript
--settings
dummy
--load-all
--log
info
--log
oneline
--path-override
"\"${MODULE_ARG}\""
--path-override
"\"${LOG_ARG}\""
--path-override
"\"${DATA_ARGS}\""
--path-override
"\"${SCRIPTS_ARG}\""
--
execute
--script
scripts/python/docs_extract.py
--input
docs
--output
docs
)
endif()
# Step 1: extract per-module documentation into git-committed YAML
# (docs/reference/*.yaml). Needs a running nscp to introspect the loaded
# modules, so it runs under the PythonScript harness. It only rewrites the
# slice for the current platform, so run it on both Linux and Windows to keep
# both slices current. NOT part of `ALL`: invoke explicitly to refresh YAML.
add_custom_target(
extract_doc_sources
COMMAND
${COMMAND_LINE}
WORKING_DIRECTORY ${BUILD_ROOT_FOLDER}
DEPENDS
nscp
${ALL_MODULE_NAMES}
copy_files
COMMENT "Extract documentation into per-module YAML"
)
add_dependencies(
extract_doc_sources
nscp
${ALL_MODULE_NAMES}
copy_files
copy_scripts
copy_resources
)
set_target_properties(
extract_doc_sources
PROPERTIES
FOLDER
"docs"
)
# Step 2: render Markdown from the committed YAML. Standalone Python
# (PyYAML + jinja2 only) -- no nscp needed -- so HTML builds work from the
# committed YAML without first building nscp.
add_custom_target(
generate_doc_sources
COMMAND
${Python3_EXECUTABLE}
scripts/python/docs_generate.py
--input
docs
--output
docs
WORKING_DIRECTORY ${BUILD_ROOT_FOLDER}
DEPENDS
copy_files
copy_scripts
COMMENT "Generate Markdown documentation from YAML"
)
set_target_properties(
generate_doc_sources
PROPERTIES
FOLDER
"docs"
)
# Step 3: render the HTML site with mkdocs.
#
# Only the Windows installer ships it (the install() below, and the
# installer target which lists build_docs_html among its dependencies but
# is built with /p:BuildProjectReferences=false in CI - so on Windows this
# has to be part of `ALL`). Everywhere else the site was built on every
# single build and then thrown away, and because it sat in `ALL` a mkdocs
# hiccup failed the entire build rather than just the docs.
#
# The target itself still exists on every platform: run
# `cmake --build . --target build_docs_html` when you want the site.
if(WIN32)
set(NSCP_BUILD_DOCS_HTML_DEFAULT ON)
else()
set(NSCP_BUILD_DOCS_HTML_DEFAULT OFF)
endif()
option(
NSCP_BUILD_DOCS_HTML
"Build the mkdocs HTML site as part of the default build target"
${NSCP_BUILD_DOCS_HTML_DEFAULT}
)
set(DOCS_HTML_ALL)
if(NSCP_BUILD_DOCS_HTML)
set(DOCS_HTML_ALL ALL)
message(STATUS "HTML documentation will be built as part of ALL")
else()
message(
STATUS
"HTML documentation is available via the build_docs_html target (not part of ALL)"
)
endif()
add_custom_target(
build_docs_html
${DOCS_HTML_ALL}
${MKDOCS_EXECUTABLE} build --site-dir "${CMAKE_CURRENT_BINARY_DIR}/html"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Building HTML documentation"
)
add_dependencies(build_docs_html generate_doc_sources)
set_target_properties(
build_docs_html
PROPERTIES
FOLDER
"docs"
)
# Guarded by the option as well: with the site not built there is no
# directory to install, and install(DIRECTORY) on a missing source is a
# hard error at package time.
if(WIN32 AND NSCP_BUILD_DOCS_HTML)
install(
DIRECTORY
"${CMAKE_CURRENT_BINARY_DIR}/html/"
DESTINATION "${INSTALL_FILES_BASE}web/help"
)
endif()
else(MKDOCS_FOUND)
message(STATUS "mkdocs not found: No documentation will be built")
endif(MKDOCS_FOUND)