Skip to content

Commit 25fc286

Browse files
committed
Modify CMake to support man page build
Separate html and man page builds in CMakeLists.txt
1 parent 418c89d commit 25fc286

File tree

3 files changed

+66
-22
lines changed

3 files changed

+66
-22
lines changed

flang/docs/CMakeLists.txt

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ function (gen_rst_file_from_td output_file td_option source)
9191
list(APPEND LLVM_TABLEGEN_FLAGS "-I${CMAKE_CURRENT_SOURCE_DIR}/../../clang/include/clang/Driver/")
9292
clang_tablegen(Source/${output_file} ${td_option} SOURCE ${source} TARGET "gen-${output_file}")
9393
# clang_tablegen() does not create the output directory automatically,
94-
# so we have to create it explicitly. Note that copy-flang-src-docs below
95-
# does create the output directory, but it is not necessarily run
96-
# before RST generation.
94+
# so we have to create it explicitly.
9795
add_custom_target(create-flang-rst-output-dir
9896
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/Source
9997
)
@@ -110,28 +108,56 @@ if (LLVM_ENABLE_SPHINX)
110108
# Generate the RST file from TableGen (shared by both HTML and MAN builds)
111109
gen_rst_file_from_td(FlangCommandLineReference.rst -gen-opt-docs FlangOptionsDocs.td)
112110

113-
# Copy the flang/docs directory and the generated FIRLangRef.md file to a place in the binary directory.
114-
# Having all the files in a single directory makes it possible for Sphinx to process them together.
115-
# Add a dependency to the flang-doc target to ensure that the FIRLangRef.md file is generated before the copying happens.
116-
add_custom_target(copy-flang-src-docs
117-
COMMAND "${CMAKE_COMMAND}" -E copy_directory
118-
"${CMAKE_CURRENT_SOURCE_DIR}"
119-
"${CMAKE_CURRENT_BINARY_DIR}/Source"
120-
DEPENDS flang-doc gen-FlangCommandLineReference.rst)
121-
122-
# Run Python preprocessing to prepend header to FIRLangRef.md
123-
add_custom_command(TARGET copy-flang-src-docs
124-
COMMAND "${Python3_EXECUTABLE}"
125-
ARGS ${CMAKE_CURRENT_BINARY_DIR}/Source/FIR/CreateFIRLangRef.py)
126-
127111
if (${SPHINX_OUTPUT_HTML})
112+
message(STATUS "Using index.md for html build")
113+
114+
# Copy the entire flang/docs directory to the build Source dir,
115+
# then remove the index.rst file, to avoid clash with index.md
116+
# which is used for the HTML build.
117+
add_custom_target(copy-flang-src-docs-html
118+
COMMAND "${CMAKE_COMMAND}" -E copy_directory
119+
"${CMAKE_CURRENT_SOURCE_DIR}"
120+
"${CMAKE_CURRENT_BINARY_DIR}/Source"
121+
COMMAND "${CMAKE_COMMAND}" -E remove
122+
"${CMAKE_CURRENT_BINARY_DIR}/Source/index.rst"
123+
DEPENDS flang-doc gen-FlangCommandLineReference.rst)
124+
125+
# Run Python preprocessing ONLY for HTML build
126+
# This script prepends headers to FIRLangRef.md for proper formatting
127+
add_custom_command(TARGET copy-flang-src-docs-html
128+
COMMAND "${Python3_EXECUTABLE}"
129+
ARGS ${CMAKE_CURRENT_BINARY_DIR}/Source/FIR/CreateFIRLangRef.py)
130+
128131
add_sphinx_target(html flang SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/Source")
129-
add_dependencies(docs-flang-html copy-flang-src-docs)
132+
add_dependencies(docs-flang-html copy-flang-src-docs-html)
130133
endif()
134+
135+
# ----------------------------
136+
# MAN BUILD SETUP
137+
# ----------------------------
131138
if (${SPHINX_OUTPUT_MAN})
132139
message(STATUS "NOTE: The Flang man page is currently a placeholder with a TODO. See docs/index.rst for details")
140+
141+
# Create minimal Source dir with ONLY the files needed for man build:
142+
# - conf.py (Sphinx config)
143+
# - index.rst (top-level man page)
144+
# - FlangCommandLineReference.rst (generated reference)
145+
add_custom_target(copy-flang-src-docs-man
146+
COMMAND "${CMAKE_COMMAND}" -E make_directory
147+
"${CMAKE_CURRENT_BINARY_DIR}/Source"
148+
COMMAND "${CMAKE_COMMAND}" -E copy
149+
"${CMAKE_CURRENT_SOURCE_DIR}/conf.py"
150+
"${CMAKE_CURRENT_BINARY_DIR}/Source/conf.py"
151+
COMMAND "${CMAKE_COMMAND}" -E copy
152+
"${CMAKE_CURRENT_SOURCE_DIR}/index.rst"
153+
"${CMAKE_CURRENT_BINARY_DIR}/Source/index.rst"
154+
COMMAND "${CMAKE_COMMAND}" -E copy
155+
"${CMAKE_CURRENT_BINARY_DIR}/Source/FlangCommandLineReference.rst"
156+
"${CMAKE_CURRENT_BINARY_DIR}/Source/FlangCommandLineReference.rst"
157+
DEPENDS flang-doc gen-FlangCommandLineReference.rst)
158+
133159
add_sphinx_target(man flang SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/Source")
134-
add_dependencies(docs-flang-man copy-flang-src-docs)
160+
add_dependencies(docs-flang-man copy-flang-src-docs-man)
135161
endif()
136162
endif()
137163
endif()

flang/docs/conf.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,15 @@
231231

232232
# One entry per manual page. List of tuples
233233
# (source start file, name, description, authors, manual section).
234-
man_pages = [("index", "flang", "Flang Documentation (In Progress)", ["Flang Contributors"], 1)]
234+
man_pages = [
235+
(
236+
"index",
237+
"flang",
238+
"Flang Documentation (In Progress)",
239+
["Flang Contributors"],
240+
1,
241+
)
242+
]
235243

236244
# If true, show URL addresses after external links.
237245
# man_show_urls = False

flang/docs/index.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ Flang Manual Page (In Progress)
66

77
For full documentation, please see the online HTML docs:
88

9-
https://flang.llvm.org/docs/FlangCommandLineReference.html
9+
https://flang.llvm.org/docs/
1010

11-
TODO: Replace this placeholder with finalized man page content.
11+
TODO: This man page currently shows FlangCommandLineReference this with finalized man page content.
12+
13+
----
14+
15+
Flang Command Line Reference
16+
----------------------------
17+
18+
.. toctree::
19+
:maxdepth: 1
20+
21+
FlangCommandLineReference

0 commit comments

Comments
 (0)