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