Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Utilities/Sphinx/CMakeLists.txt
5029 views
1
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2
# file LICENSE.rst or https://cmake.org/licensing for details.
3
4
if(NOT CMake_SOURCE_DIR)
5
set(CMakeHelp_STANDALONE 1)
6
cmake_minimum_required(VERSION 3.13...4.1 FATAL_ERROR)
7
get_filename_component(tmp "${CMAKE_CURRENT_SOURCE_DIR}" PATH)
8
get_filename_component(CMake_SOURCE_DIR "${tmp}" PATH)
9
include(${CMake_SOURCE_DIR}/Modules/CTestUseLaunchers.cmake)
10
include(${CMake_SOURCE_DIR}/Source/CMakeCopyright.cmake)
11
include(${CMake_SOURCE_DIR}/Source/CMakeVersion.cmake)
12
include(${CMake_SOURCE_DIR}/Source/CMakeInstallDestinations.cmake)
13
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake @ONLY)
14
unset(CMAKE_DATA_DIR)
15
unset(CMAKE_DATA_DIR CACHE)
16
macro(CMake_OPTIONAL_COMPONENT)
17
set(COMPONENT "")
18
endmacro()
19
endif()
20
project(CMakeHelp NONE)
21
22
option(SPHINX_INFO "Build Info manual with Sphinx" OFF)
23
option(SPHINX_MAN "Build man pages with Sphinx" OFF)
24
option(SPHINX_HTML "Build html help with Sphinx" OFF)
25
option(SPHINX_SINGLEHTML "Build html single page help with Sphinx" OFF)
26
option(SPHINX_LINKCHECK "Check external links mentioned in documentation" OFF)
27
option(SPHINX_QTHELP "Build Qt help with Sphinx" OFF)
28
option(SPHINX_LATEXPDF "Build PDF help with Sphinx using LaTeX" OFF)
29
option(SPHINX_TEXT "Build text help with Sphinx (not installed)" OFF)
30
option(SPHINX_INCLUDE_IN_ALL "Build Sphinx documentation by default" ON)
31
find_program(SPHINX_EXECUTABLE
32
NAMES sphinx-build
33
DOC "Sphinx Documentation Builder (sphinx-doc.org)"
34
)
35
set(SPHINX_FLAGS "" CACHE STRING "Flags to pass to sphinx-build")
36
separate_arguments(sphinx_flags UNIX_COMMAND "${SPHINX_FLAGS}")
37
38
mark_as_advanced(SPHINX_TEXT)
39
mark_as_advanced(SPHINX_FLAGS)
40
41
if(NOT (SPHINX_INFO
42
OR SPHINX_MAN
43
OR SPHINX_HTML
44
OR SPHINX_SINGLEHTML
45
OR SPHINX_LINKCHECK
46
OR SPHINX_QTHELP
47
OR SPHINX_TEXT
48
OR SPHINX_LATEXPDF
49
))
50
return()
51
elseif(NOT SPHINX_EXECUTABLE)
52
message(FATAL_ERROR "SPHINX_EXECUTABLE (sphinx-build) is not found!")
53
endif()
54
55
if(CMake_COPYRIGHT_LINE MATCHES "^Copyright (.*)$")
56
set(conf_copyright "${CMAKE_MATCH_1}")
57
else()
58
set(conf_copyright "Kitware, Inc.")
59
endif()
60
61
if(CMake_SPHINX_CMAKE_ORG)
62
set(conf_baseurl "https://cmake.org/cmake/help/latest")
63
else()
64
set(conf_baseurl "")
65
endif()
66
67
if(CMake_SPHINX_CMAKE_ORG)
68
set(conf_cmakeorg "True")
69
else()
70
set(conf_cmakeorg "False")
71
endif()
72
73
set(conf_docs "${CMake_SOURCE_DIR}/Help")
74
set(conf_path "${CMAKE_CURRENT_SOURCE_DIR}")
75
set(conf_version "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
76
set(conf_release "${CMake_VERSION}")
77
configure_file(conf.py.in conf.py @ONLY)
78
79
set(doc_formats "")
80
if(SPHINX_HTML)
81
list(APPEND doc_formats html)
82
83
# we provide the path to the produced html output in the console
84
# for tools that support URI protocol schemes
85
set(html_post_commands
86
COMMAND ${CMAKE_COMMAND} -E echo "sphinx-build html: HTML documentation generated in file://${CMAKE_CURRENT_BINARY_DIR}/html/index.html"
87
)
88
89
endif()
90
if(SPHINX_MAN)
91
list(APPEND doc_formats man)
92
endif()
93
if(SPHINX_SINGLEHTML)
94
list(APPEND doc_formats singlehtml)
95
endif()
96
if(SPHINX_LINKCHECK)
97
list(APPEND doc_formats linkcheck)
98
#
99
set(linkcheck_post_commands
100
COMMAND ${CMAKE_COMMAND} -E echo "sphinx-build linkcheck: see checking status in file://${CMAKE_CURRENT_BINARY_DIR}/linkcheck/output.txt"
101
)
102
endif()
103
if(SPHINX_TEXT)
104
list(APPEND doc_formats text)
105
endif()
106
if(SPHINX_INFO)
107
find_program(MAKEINFO_EXECUTABLE
108
NAMES makeinfo
109
DOC "makeinfo tool"
110
)
111
if (NOT MAKEINFO_EXECUTABLE)
112
message(FATAL_ERROR "MAKEINFO_EXECUTABLE (makeinfo) not found!")
113
endif()
114
list(APPEND doc_formats texinfo)
115
116
# Sphinx texinfo builder supports .info, .txt, .html and .pdf output.
117
# SPHINX_INFO controls the .info output.
118
set(texinfo_post_commands
119
COMMAND ${MAKEINFO_EXECUTABLE} --no-split -o
120
${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.info
121
${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.texi
122
)
123
endif()
124
if(SPHINX_QTHELP)
125
find_package(Python REQUIRED)
126
127
find_program(QHELPGENERATOR_EXECUTABLE
128
NAMES qhelpgenerator-qt5 qhelpgenerator
129
DOC "qhelpgenerator tool"
130
)
131
if(NOT QHELPGENERATOR_EXECUTABLE)
132
message(FATAL_ERROR "QHELPGENERATOR_EXECUTABLE (qhelpgenerator) not found!")
133
endif()
134
list(APPEND doc_formats qthelp)
135
136
set(qthelp_post_commands
137
# Workaround for assistant prior to
138
# https://codereview.qt-project.org/#change,82250 in Qt 4.
139
COMMAND ${CMAKE_COMMAND} "-DCSS_DIR=${CMAKE_CURRENT_BINARY_DIR}/qthelp/_static"
140
-P "${CMAKE_CURRENT_SOURCE_DIR}/apply_qthelp_css_workaround.cmake"
141
# Workaround sphinx configurability:
142
# https://github.com/sphinx-doc/sphinx/issues/1448
143
COMMAND ${CMAKE_COMMAND} "-DQTHELP_DIR=${CMAKE_CURRENT_BINARY_DIR}/qthelp/"
144
-P "${CMAKE_CURRENT_SOURCE_DIR}/fixup_qthelp_names.cmake"
145
146
# Create proper identifiers. Workaround for
147
# https://github.com/sphinx-doc/sphinx/issues/1491
148
COMMAND "${Python_EXECUTABLE}"
149
"${CMAKE_CURRENT_SOURCE_DIR}/create_identifiers.py"
150
"${CMAKE_CURRENT_BINARY_DIR}/qthelp/"
151
152
COMMAND ${QHELPGENERATOR_EXECUTABLE}
153
${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qhcp
154
)
155
endif()
156
if(SPHINX_LATEXPDF)
157
list(APPEND doc_formats latexpdf)
158
endif()
159
160
set(doc_html_opts "")
161
if(CMake_SPHINX_CMAKE_ORG)
162
list(APPEND doc_html_opts
163
-A googleanalytics=1
164
-A opensearch=1
165
-A versionswitch=1
166
)
167
168
if(CMake_SPHINX_CMAKE_ORG_OUTDATED)
169
list(APPEND doc_html_opts -A outdated=1)
170
endif()
171
172
list(APPEND html_pre_commands
173
COMMAND ${CMAKE_COMMAND} -Dversion=${CMake_VERSION} -P ${CMAKE_CURRENT_SOURCE_DIR}/tutorial_archive.cmake
174
)
175
176
list(APPEND qthelp_post_commands
177
COMMAND ${CMAKE_COMMAND} -E copy
178
"${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qch"
179
"${CMAKE_CURRENT_BINARY_DIR}/html/CMake.qch"
180
)
181
endif()
182
183
# Redirect `sphinx-build` output to `build-<format>.log` file?
184
set(sphinx_use_build_log TRUE)
185
set(sphinx_verbose_levels "DEBUG;TRACE")
186
set(sphinx_no_redirect_levels "VERBOSE;${sphinx_verbose_levels}")
187
# NOTE There is no generic verbosity level for all supported generators,
188
# so lets use CMake verbosity level to control if `sphinx-build` should
189
# redirect it's output to a file or a user wants to see it at build time.
190
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.25)
191
cmake_language(GET_MESSAGE_LOG_LEVEL verbose_level)
192
else()
193
# If building under CMake < 3.25, fallback to `CMAKE_MESSAGE_LOG_LEVEL`
194
# variable. It was added in 3.17 but it's OK to set it even for older
195
# versions (w/o any effect on `message()` command of course).
196
set(verbose_level ${CMAKE_MESSAGE_LOG_LEVEL})
197
endif()
198
if(DEFINED ENV{VERBOSE} OR CMAKE_VERBOSE_MAKEFILE OR verbose_level IN_LIST sphinx_no_redirect_levels)
199
set(sphinx_use_build_log FALSE)
200
if(verbose_level IN_LIST sphinx_verbose_levels)
201
# NOTE Sphinx accept multiple `-v` options for more verbosity
202
# but the output mostly for Sphinx developers...
203
list(APPEND sphinx_flags "-v")
204
endif()
205
endif()
206
207
set(doc_format_outputs "")
208
set(doc_format_last "")
209
foreach(format IN LISTS doc_formats)
210
set(doc_format_output "doc_format_${format}")
211
set(doc_format_log "")
212
set(build_comment_tail " ...")
213
if(sphinx_use_build_log)
214
set(doc_format_log "build-${format}.log")
215
set(build_comment_tail ": see Utilities/Sphinx/${doc_format_log}")
216
list(PREPEND doc_format_log ">")
217
endif()
218
if(CMake_SPHINX_CMAKE_ORG)
219
set(doctrees "doctrees/${format}")
220
else()
221
set(doctrees "doctrees")
222
endif()
223
if(format STREQUAL "latexpdf")
224
# This format does not use builder (-b) but make_mode (-M) which expects
225
# arguments in peculiar order
226
set(_args
227
-M ${format}
228
${CMake_SOURCE_DIR}/Help
229
${CMAKE_CURRENT_BINARY_DIR}/${format}
230
-c ${CMAKE_CURRENT_BINARY_DIR}
231
-d ${CMAKE_CURRENT_BINARY_DIR}/${doctrees}
232
${sphinx_flags}
233
${doc_${format}_opts}
234
)
235
else()
236
# other formats use standard builder (-b) mode
237
set(_args
238
-c ${CMAKE_CURRENT_BINARY_DIR}
239
-d ${CMAKE_CURRENT_BINARY_DIR}/${doctrees}
240
-b ${format}
241
${sphinx_flags}
242
${doc_${format}_opts}
243
${CMake_SOURCE_DIR}/Help
244
${CMAKE_CURRENT_BINARY_DIR}/${format}
245
)
246
endif()
247
248
add_custom_command(
249
OUTPUT ${doc_format_output}
250
${${format}_pre_commands}
251
COMMAND ${SPHINX_EXECUTABLE} ${_args} ${doc_format_log}
252
${${format}_post_commands}
253
DEPENDS ${doc_format_last}
254
COMMENT "sphinx-build ${format}${build_comment_tail}"
255
VERBATIM
256
)
257
set_property(SOURCE ${doc_format_output} PROPERTY SYMBOLIC 1)
258
list(APPEND doc_format_outputs ${doc_format_output})
259
if(NOT CMake_SPHINX_CMAKE_ORG)
260
set(doc_format_last ${doc_format_output})
261
endif()
262
endforeach()
263
264
if (SPHINX_INCLUDE_IN_ALL)
265
set(add_documentation_to_all ALL)
266
endif()
267
268
add_custom_target(documentation ${add_documentation_to_all} DEPENDS ${doc_format_outputs})
269
270
if(CMake_SPHINX_DEPEND_ON_EXECUTABLES)
271
foreach(t IN ITEMS cmake ccmake cmake-gui cpack ctest)
272
if(TARGET ${t})
273
# Build documentation after main executables.
274
add_dependencies(documentation ${t})
275
endif()
276
endforeach()
277
endif()
278
279
if(CMake_SPHINX_CMAKE_ORG)
280
return()
281
endif()
282
283
if(SPHINX_INFO)
284
CMake_OPTIONAL_COMPONENT(sphinx-info)
285
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.info
286
DESTINATION ${CMake_INSTALL_INFO_DIR}
287
${COMPONENT}
288
)
289
endif()
290
291
if(SPHINX_MAN)
292
file(GLOB man_rst RELATIVE ${CMake_SOURCE_DIR}/Help/manual
293
${CMake_SOURCE_DIR}/Help/manual/*.[1-9].rst)
294
foreach(m IN LISTS man_rst)
295
if("x${m}" MATCHES "^x(.+)\\.([1-9])\\.rst$")
296
set(name "${CMAKE_MATCH_1}")
297
set(sec "${CMAKE_MATCH_2}")
298
set(skip FALSE)
299
if(NOT CMakeHelp_STANDALONE)
300
if(name STREQUAL "ccmake" AND NOT BUILD_CursesDialog)
301
set(skip TRUE)
302
elseif(name STREQUAL "cmake-gui" AND NOT BUILD_QtDialog)
303
set(skip TRUE)
304
endif()
305
endif()
306
if(NOT skip)
307
CMake_OPTIONAL_COMPONENT(sphinx-man)
308
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/${name}.${sec}
309
DESTINATION ${CMake_INSTALL_MAN_DIR}/man${sec}
310
${COMPONENT})
311
endif()
312
unset(skip)
313
endif()
314
endforeach()
315
endif()
316
317
if(SPHINX_HTML)
318
CMake_OPTIONAL_COMPONENT(sphinx-html)
319
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
320
DESTINATION ${CMake_INSTALL_DOC_DIR}
321
${COMPONENT}
322
PATTERN .buildinfo EXCLUDE
323
)
324
endif()
325
326
if(SPHINX_SINGLEHTML)
327
CMake_OPTIONAL_COMPONENT(sphinx-singlehtml)
328
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/singlehtml
329
DESTINATION ${CMake_INSTALL_DOC_DIR}
330
${COMPONENT}
331
PATTERN .buildinfo EXCLUDE
332
)
333
endif()
334
335
if(SPHINX_QTHELP)
336
CMake_OPTIONAL_COMPONENT(sphinx-qthelp)
337
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qthelp/CMake.qch
338
DESTINATION ${CMake_INSTALL_DOC_DIR} ${COMPONENT}
339
)
340
endif()
341
342
if(SPHINX_LATEXPDF)
343
CMake_OPTIONAL_COMPONENT(sphinx-latexpdf)
344
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/latexpdf/latex/CMake.pdf
345
DESTINATION ${CMake_INSTALL_DOC_DIR} ${COMPONENT}
346
)
347
endif()
348
349