@@ -82,16 +82,14 @@ if (LLVM_ENABLE_DOXYGEN)
8282endif ()
8383endif ()
8484
85- function (gen_rst_file_from_td output_file td_option source docs_target )
85+ function (gen_rst_file_from_td output_file td_option source )
8686 if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR} /${source} " )
8787 message (FATAL_ERROR "Cannot find source file: ${source} in ${CMAKE_CURRENT_SOURCE_DIR} " )
8888 endif ()
8989 get_filename_component (TABLEGEN_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR} /${source} " DIRECTORY )
9090 list (APPEND LLVM_TABLEGEN_FLAGS "-I${TABLEGEN_INCLUDE_DIR} " )
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} " )
93- add_dependencies (${docs_target} "gen-${output_file} " )
94-
9593 # clang_tablegen() does not create the output directory automatically,
9694 # so we have to create it explicitly. Note that copy-flang-src-docs below
9795 # does create the output directory, but it is not necessarily run
@@ -105,32 +103,34 @@ endfunction()
105103if (LLVM_ENABLE_SPHINX)
106104 include (AddSphinxTarget)
107105 if (SPHINX_FOUND)
106+
107+ # CLANG_TABLEGEN_EXE variable needs to be set for clang_tablegen to run without error
108+ find_program (CLANG_TABLEGEN_EXE "clang-tblgen" ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
109+
110+ # Generate the RST file from TableGen (shared by both HTML and MAN builds)
111+ gen_rst_file_from_td(FlangCommandLineReference.rst -gen-opt-docs FlangOptionsDocs.td)
112+
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+
108127 if (${SPHINX_OUTPUT_HTML} )
109128 add_sphinx_target(html flang SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR} /Source" )
110-
111- add_dependencies (docs-flang-html copy-flang-src-docs)
112-
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 )
121-
122- # Runs a python script prior to HTML generation to prepend a header to FIRLangRef,
123- # Without the header, the page is incorrectly formatted, as it assumes the first entry is the page title.
124- add_custom_command (TARGET copy-flang-src-docs
125- COMMAND "${Python3_EXECUTABLE} "
126- ARGS ${CMAKE_CURRENT_BINARY_DIR} /Source /FIR/CreateFIRLangRef.py)
127-
128- # CLANG_TABLEGEN_EXE variable needs to be set for clang_tablegen to run without error
129- find_program (CLANG_TABLEGEN_EXE "clang-tblgen" ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
130- gen_rst_file_from_td(FlangCommandLineReference.rst -gen-opt-docs FlangOptionsDocs.td docs-flang-html)
131129 endif ()
132130 if (${SPHINX_OUTPUT_MAN} )
133- add_sphinx_target(man flang)
131+ add_sphinx_target(man flang SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR} /Source" )
132+ add_dependencies (docs-flang-man gen-FlangCommandLineReference.rst)
133+ add_dependencies (docs-flang-man copy-flang-src-docs)
134134 endif ()
135135 endif ()
136136endif ()
0 commit comments