2
2
3
3
find_package (Doxygen)
4
4
find_program (SPHINX_BUILD sphinx-build )
5
- find_program (MAKE_EXECUTABLE make)
6
5
7
- if ( UNIX
8
- AND (NOT "${CMAKE_BINARY_DIR} " STREQUAL "${CMAKE_SOURCE_DIR} " )
6
+
7
+ if ( (NOT "${CMAKE_BINARY_DIR} " STREQUAL "${CMAKE_SOURCE_DIR} " )
9
8
AND DOXYGEN_FOUND
10
- AND SPHINX_BUILD
11
- AND MAKE_EXECUTABLE)
9
+ AND SPHINX_BUILD)
12
10
set (BUILD_DOCS_DEFAULT ON )
13
11
else ()
14
12
set (BUILD_DOCS_DEFAULT OFF )
15
13
endif ()
16
- option (BUILD_DOCS "Set to ON to define documentation targets: 'html', 'latexpdf', 'man', 'doxygen', 'doxygen_check_warnings', 'spelling', 'clean_doc'" ${BUILD_DOCS_DEFAULT} )
14
+
15
+ option (BUILD_DOCS "Set to ON to define documentation targets: 'html', 'latexpdf', 'man', 'doxygen_xml', 'doxygen_html' " ${BUILD_DOCS_DEFAULT} )
17
16
18
17
if (BUILD_DOCS)
19
- if (NOT UNIX )
20
- message (FATAL_ERROR "BUILD_DOCS=ON requires a UNIX environment" )
21
- endif ()
22
18
if ("${CMAKE_BINARY_DIR} " STREQUAL "${CMAKE_SOURCE_DIR} " )
23
19
message (FATAL_ERROR "BUILD_DOCS=ON not compatible of in-source builds (CMAKE_SOURCE_DIR=CMAKE_BINARY_DIR)" )
24
20
endif ()
@@ -28,49 +24,145 @@ if (BUILD_DOCS)
28
24
if (NOT SPHINX_BUILD)
29
25
message (FATAL_ERROR "BUILD_DOCS=ON requires sphinx-build" )
30
26
endif ()
31
- if (NOT MAKE_EXECUTABLE)
32
- message (FATAL_ERROR "BUILD_DOCS=ON requires 'make' executable" )
33
- endif ()
34
27
35
- set (DOC_BUILDDIR "${CMAKE_CURRENT_BINARY_DIR} /build" )
36
-
37
- add_custom_target (
38
- doxygen
39
- COMMAND ${MAKE_EXECUTABLE} doxygen BUILDDIR=${DOC_BUILDDIR}
40
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
41
-
42
- add_custom_target (
43
- doxygen_check_warnings
44
- COMMAND ${MAKE_EXECUTABLE} doxygen_check_warnings BUILDDIR=${DOC_BUILDDIR}
45
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
46
-
47
- add_custom_target (
48
- html
49
- COMMAND ${MAKE_EXECUTABLE} html BUILDDIR=${DOC_BUILDDIR}
50
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
51
-
52
- add_custom_target (
53
- latexpdf
54
- COMMAND ${MAKE_EXECUTABLE} latexpdf BUILDDIR=${DOC_BUILDDIR}
55
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
56
-
57
- add_custom_target (
58
- man
59
- COMMAND ${MAKE_EXECUTABLE} man BUILDDIR=${DOC_BUILDDIR}
60
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
61
-
62
- add_custom_target (
63
- spelling
64
- COMMAND ${MAKE_EXECUTABLE} spelling BUILDDIR=${DOC_BUILDDIR}
65
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
66
-
67
- add_custom_target (
68
- clean_doc
69
- COMMAND ${MAKE_EXECUTABLE} clean BUILDDIR=${DOC_BUILDDIR}
70
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
71
-
72
- set_property (
73
- TARGET clean_doc
74
- APPEND
75
- PROPERTY ADDITIONAL_CLEAN_FILES ${DOC_BUILDDIR} )
28
+ ####################################################################################################
29
+ # Sphinx configuration
30
+ ####################################################################################################
31
+
32
+ # Determine environment variables so that Sphinx can load the gdal Python module without installing it.
33
+ include (GdalSetRuntimeEnv)
34
+ gdal_set_runtime_env(PYTHON_RUN_ENV)
35
+
36
+ set (SPHINX_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR} /build )
37
+ set (SPHINX_BUILD_OPTS "--jobs=auto" "--fail-on-warning" "--show-traceback" )
38
+ file (MAKE_DIRECTORY ${SPHINX_BUILD_DIR} )
39
+ file (MAKE_DIRECTORY ${SPHINX_BUILD_DIR} /html_extra)
40
+
41
+ file (GLOB_RECURSE SPHINX_SOURCE_FILES CONFIGURE_DEPENDS
42
+ ${CMAKE_CURRENT_SOURCE_DIR} /source /**/*.rst
43
+ ${CMAKE_CURRENT_SOURCE_DIR} /source /**/*.py)
44
+
45
+ ####################################################################################################
46
+ # Doxygen XML and HTML outputs
47
+ ####################################################################################################
48
+
49
+ # Create a dependency between source files and Doxygen
50
+ # This is more aggressive than needed, because we only build Doxygen for a subset of the source tree
51
+ file (GLOB_RECURSE DOXYGEN_SOURCE_FILES CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR} /**/*.cpp)
52
+
53
+ # Use configure_file to copy the Doxygen file into our build directory.
54
+ # This causes CMake to re-run if the contents of the Doxyfile change.
55
+ configure_file (${CMAKE_SOURCE_DIR} /Doxyfile ${CMAKE_CURRENT_BINARY_DIR} /Doxyfile_base)
56
+
57
+ # Read the contents of the copied Doxyfile, so that we can write modified versions
58
+ # for XML and HTML outputs
59
+ file (READ ${CMAKE_CURRENT_BINARY_DIR} /Doxyfile_base DOXYFILE_CONTENTS)
60
+
61
+ # Doxygen XML outputs
62
+ # TODO <ndash> replacement?
63
+ string (JOIN "\n " DOXYFILE_XML_CONTENTS
64
+ ${DOXYFILE_CONTENTS}
65
+ "FAIL_ON_WARNINGS=YES"
66
+ "WARN_AS_ERROR=FAIL_ON_WARNINGS_PRINT"
67
+ "GENERATE_HTML=NO"
68
+ "GENERATE_XML=YES"
69
+ "XML_OUTPUT=${SPHINX_BUILD_DIR} /xml"
70
+ "XML_PROGRAMLISTING=NO"
71
+ "PREDEFINED+=DOXYGEN_XML"
72
+ )
73
+ file (WRITE ${CMAKE_CURRENT_BINARY_DIR} /Doxyfile_xml ${DOXYFILE_XML_CONTENTS} )
74
+ add_custom_command (
75
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /doxygen_xml.stamp
76
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /Doxyfile_xml ${DOXYGEN_SOURCE_FILES}
77
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
78
+ COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR} /Doxyfile_xml
79
+ COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR} /doxygen_xml.stamp
80
+ )
81
+
82
+ add_custom_target (doxygen_xml
83
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /doxygen_xml.stamp
84
+ )
85
+
86
+ # Doxygen HTML outputs
87
+ string (JOIN "\n " DOXYFILE_HTML_CONTENTS
88
+ "${DOXYFILE_CONTENTS} "
89
+ "FAIL_ON_WARNINGS=YES"
90
+ "WARN_AS_ERROR=FAIL_ON_WARNINGS_PRINT"
91
+ "HTML_OUTPUT=${SPHINX_BUILD_DIR} /html_extra/doxygen"
92
+ "INLINE_INHERITED_MEMB=YES"
93
+ )
94
+ file (WRITE ${CMAKE_CURRENT_BINARY_DIR} /Doxyfile_html ${DOXYFILE_HTML_CONTENTS} )
95
+ add_custom_command (
96
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /doxygen_html.stamp
97
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
98
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /Doxyfile_html ${DOXYGEN_SOURCE_FILES}
99
+ COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR} /Doxyfile_html
100
+ COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR} /doxygen_html.stamp
101
+ )
102
+ add_custom_target (doxygen_html
103
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /doxygen_html.stamp
104
+ )
105
+
106
+ ####################################################################################################
107
+ # Sphinx outputs
108
+ ####################################################################################################
109
+
110
+ # Sphinx HTML documentation
111
+ add_custom_command (
112
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR} /html.stamp"
113
+ DEPENDS doxygen_xml python_binding
114
+ ${SPHINX_SOURCE_FILES}
115
+ COMMAND ${CMAKE_COMMAND} -E env ${PYTHON_RUN_ENV} BUILDDIR=${SPHINX_BUILD_DIR}
116
+ ${SPHINX_BUILD} -M html
117
+ ${CMAKE_CURRENT_SOURCE_DIR} /source
118
+ ${CMAKE_CURRENT_BINARY_DIR} /build
119
+ ${SPHINX_BUILD_OPTS}
120
+ COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR} /html.stamp"
121
+ )
122
+
123
+ add_custom_target (html
124
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /html.stamp
125
+ )
126
+
127
+ # Sphinx PDF documentation
128
+ add_custom_command (
129
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /build /gdal.pdf
130
+ DEPENDS ${SPHINX_SOURCE_FILES}
131
+ COMMAND ${CMAKE_COMMAND} -E env BUILDDIR=${SPHINX_BUILD_DIR}
132
+ ${SPHINX_BUILD} -M latexpdf
133
+ ${CMAKE_CURRENT_SOURCE_DIR} /source
134
+ ${CMAKE_CURRENT_BINARY_DIR} /build
135
+ ${SPHINX_BUILD_OPTS}
136
+ )
137
+
138
+ add_custom_target (latexpdf DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /build /gdal.pdf)
139
+
140
+ # Sphinx manpage documentation
141
+ add_custom_command (
142
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR} /man.stamp"
143
+ DEPENDS ${SPHINX_SOURCE_FILES}
144
+ COMMAND ${CMAKE_COMMAND} -E env BUILDDIR=${SPHINX_BUILD_DIR}
145
+ ${SPHINX_BUILD} -M man
146
+ ${CMAKE_CURRENT_SOURCE_DIR} /source
147
+ ${CMAKE_CURRENT_BINARY_DIR} /build
148
+ ${SPHINX_BUILD_OPTS}
149
+ COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR} /man.stamp"
150
+ )
151
+
152
+ add_custom_target (man DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /man.stamp)
153
+
154
+ ####################################################################################################
155
+ # Documentation tests
156
+ ####################################################################################################
157
+
158
+ # Spell check
159
+ add_test (NAME doc -spelling
160
+ COMMAND ${CMAKE_COMMAND} -E env ${PYTHON_RUN_ENV} BUILDDIR=${SPHINX_BUILD_DIR}
161
+ ${SPHINX_BUILD} -b spelling
162
+ ${CMAKE_CURRENT_SOURCE_DIR} /source
163
+ ${CMAKE_CURRENT_BINARY_DIR} /build
164
+ ${SPHINX_BUILD_OPTS}
165
+ -D html_extra_path=extra_path
166
+ )
167
+
76
168
endif ()
0 commit comments