Fix test failures introduced by PR #113697 (#116941)
[llvm-project.git] / clang / docs / CMakeLists.txt
blob4fecc007f599541bbdd56e3d075fbc6a7fb52b4b
2 if (DOXYGEN_FOUND)
3 if (LLVM_ENABLE_DOXYGEN)
4   set(abs_srcdir ${CMAKE_CURRENT_SOURCE_DIR})
5   set(abs_builddir ${CMAKE_CURRENT_BINARY_DIR})
7   if (HAVE_DOT)
8     set(DOT ${LLVM_PATH_DOT})
9   endif()
11   if (LLVM_DOXYGEN_EXTERNAL_SEARCH)
12     set(enable_searchengine "YES")
13     set(searchengine_url "${LLVM_DOXYGEN_SEARCHENGINE_URL}")
14     set(enable_server_based_search "YES")
15     set(enable_external_search "YES")
16     set(extra_search_mappings "${LLVM_DOXYGEN_SEARCH_MAPPINGS}")
17   else()
18     set(enable_searchengine "NO")
19     set(searchengine_url "")
20     set(enable_server_based_search "NO")
21     set(enable_external_search "NO")
22     set(extra_search_mappings "")
23   endif()
25   # If asked, configure doxygen for the creation of a Qt Compressed Help file.
26   if (LLVM_ENABLE_DOXYGEN_QT_HELP)
27     set(CLANG_DOXYGEN_QCH_FILENAME "org.llvm.clang.qch" CACHE STRING
28       "Filename of the Qt Compressed help file")
29     set(CLANG_DOXYGEN_QHP_NAMESPACE "org.llvm.clang" CACHE STRING
30       "Namespace under which the intermediate Qt Help Project file lives")
31     set(CLANG_DOXYGEN_QHP_CUST_FILTER_NAME "Clang ${CLANG_VERSION}" CACHE STRING
32       "See http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-filters")
33     set(CLANG_DOXYGEN_QHP_CUST_FILTER_ATTRS "Clang,${CLANG_VERSION}" CACHE STRING
34       "See http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes")
35     set(clang_doxygen_generate_qhp "YES")
36     set(clang_doxygen_qch_filename "${CLANG_DOXYGEN_QCH_FILENAME}")
37     set(clang_doxygen_qhp_namespace "${CLANG_DOXYGEN_QHP_NAMESPACE}")
38     set(clang_doxygen_qhelpgenerator_path "${LLVM_DOXYGEN_QHELPGENERATOR_PATH}")
39     set(clang_doxygen_qhp_cust_filter_name "${CLANG_DOXYGEN_QHP_CUST_FILTER_NAME}")
40     set(clang_doxygen_qhp_cust_filter_attrs "${CLANG_DOXYGEN_QHP_CUST_FILTER_ATTRS}")
41   else()
42     set(clang_doxygen_generate_qhp "NO")
43     set(clang_doxygen_qch_filename "")
44     set(clang_doxygen_qhp_namespace "")
45     set(clang_doxygen_qhelpgenerator_path "")
46     set(clang_doxygen_qhp_cust_filter_name "")
47     set(clang_doxygen_qhp_cust_filter_attrs "")
48   endif()
50   option(LLVM_DOXYGEN_SVG
51     "Use svg instead of png files for doxygen graphs." OFF)
52   if (LLVM_DOXYGEN_SVG)
53     set(DOT_IMAGE_FORMAT "svg")
54   else()
55     set(DOT_IMAGE_FORMAT "png")
56   endif()
58   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen.cfg.in
59     ${CMAKE_CURRENT_BINARY_DIR}/doxygen.cfg @ONLY)
61   set(abs_top_srcdir)
62   set(abs_top_builddir)
63   set(DOT)
64   set(enable_searchengine)
65   set(searchengine_url)
66   set(enable_server_based_search)
67   set(enable_external_search)
68   set(extra_search_mappings)
69   set(clang_doxygen_generate_qhp)
70   set(clang_doxygen_qch_filename)
71   set(clang_doxygen_qhp_namespace)
72   set(clang_doxygen_qhelpgenerator_path)
73   set(clang_doxygen_qhp_cust_filter_name)
74   set(clang_doxygen_qhp_cust_filter_attrs)
75   set(DOT_IMAGE_FORMAT)
77   add_custom_target(doxygen-clang
78     COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxygen.cfg
79     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
80     COMMENT "Generating clang doxygen documentation." VERBATIM)
81   set_target_properties(doxygen-clang PROPERTIES FOLDER "Clang/Docs")
83   if (LLVM_BUILD_DOCS)
84     add_dependencies(doxygen doxygen-clang)
85   endif()
87   if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
88     install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html
89       DESTINATION docs/html)
90   endif()
91 endif()
92 endif()
94 function (gen_rst_file_from_td output_file td_option source docs_targets)
95   if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${source}")
96     message(FATAL_ERROR "Cannot find source file: ${source} in ${CMAKE_CURRENT_SOURCE_DIR}")
97   endif()
98   get_filename_component(TABLEGEN_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${source}" DIRECTORY)
99   list(APPEND LLVM_TABLEGEN_FLAGS "-I${TABLEGEN_INCLUDE_DIR}")
100   clang_tablegen(${output_file} ${td_option} SOURCE ${source} TARGET "gen-${output_file}")
101   foreach(target ${docs_targets})
102     add_dependencies(${target} gen-${output_file})
103   endforeach()
104 endfunction()
106 if (LLVM_ENABLE_SPHINX)
107   include(AddSphinxTarget)
108   if (SPHINX_FOUND AND (${SPHINX_OUTPUT_HTML} OR ${SPHINX_OUTPUT_MAN}))
109     # Copy rst files to build directory before generating the html
110     # documentation.  Some of the rst files are generated, so they
111     # only exist in the build directory.  Sphinx needs all files in
112     # the same directory in order to generate the html, so we need to
113     # copy all the non-gnerated rst files from the source to the build
114     # directory before we run sphinx.
115     add_custom_target(copy-clang-rst-docs
116       COMMAND "${CMAKE_COMMAND}" -E copy_directory
117       "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}"
119       COMMAND "${CMAKE_COMMAND}" -E copy_if_different
120       "${CMAKE_CURRENT_SOURCE_DIR}/../Maintainers.rst"
121       "${CMAKE_CURRENT_BINARY_DIR}"
122     )
124     set(docs_targets "")
126     if (${SPHINX_OUTPUT_HTML})
127       add_sphinx_target(html clang SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
129       add_custom_command(TARGET docs-clang-html POST_BUILD
130         COMMAND "${CMAKE_COMMAND}" -E copy
131         "${CMAKE_CURRENT_SOURCE_DIR}/LibASTMatchersReference.html"
132         "${CMAKE_CURRENT_BINARY_DIR}/html/LibASTMatchersReference.html")
134       list(APPEND docs_targets "docs-clang-html")
135     endif()
136     if (${SPHINX_OUTPUT_MAN})
137       add_sphinx_target(man clang SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
138       list(APPEND docs_targets "docs-clang-man")
139     endif()
141     # Generated files
142     gen_rst_file_from_td(AttributeReference.rst -gen-attr-docs ../include/clang/Basic/Attr.td "${docs_targets}")
143     gen_rst_file_from_td(DiagnosticsReference.rst -gen-diag-docs ../include/clang/Basic/Diagnostic.td "${docs_targets}")
144     gen_rst_file_from_td(ClangCommandLineReference.rst -gen-opt-docs ../include/clang/Driver/ClangOptionDocs.td "${docs_targets}")
146     foreach(target ${docs_targets})
147       add_dependencies(${target} copy-clang-rst-docs)
148     endforeach()
149   endif()
150 endif()