FindDoxygen.cmake 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindDoxygen
  5. -----------
  6. Finds `Doxygen <https://www.doxygen.nl>`_, a source code documentation
  7. generator, along with some optional supporting tools, and provides a command
  8. for integrating Doxygen-based documentation into CMake projects:
  9. .. code-block:: cmake
  10. find_package(Doxygen [<version>] [COMPONENTS <components>...] [...])
  11. Components
  12. ^^^^^^^^^^
  13. Additional Doxygen supporting tools, can be specified as components with the
  14. :command:`find_package()` command:
  15. .. code-block:: cmake
  16. find_package(Doxygen [COMPONENTS <components>...])
  17. Supported components include:
  18. ``doxygen``
  19. .. versionadded:: 3.9
  20. Finds the ``doxygen`` executable. This component is always automatically
  21. implied, even if not requested.
  22. ``dot``
  23. .. versionadded:: 3.9
  24. Finds the `Graphviz <https://graphviz.org>`_ ``dot`` utility, used for
  25. rendering graphs and diagrams as part of the documentation.
  26. ``mscgen``
  27. .. versionadded:: 3.9
  28. Finds the `Message Chart Generator <https://www.mcternan.me.uk/mscgen/>`_
  29. utility used by Doxygen's ``\msc`` and ``\mscfile`` commands.
  30. ``dia``
  31. .. versionadded:: 3.9
  32. Finds the `Dia <https://wiki.gnome.org/Apps/Dia>`_ diagram editor used by
  33. Doxygen's ``\diafile`` command.
  34. Imported Targets
  35. ^^^^^^^^^^^^^^^^
  36. This module provides the following :ref:`Imported Targets`, each of which is
  37. defined if the corresponding component was requested and its associated
  38. executable was found:
  39. ``Doxygen::doxygen``
  40. .. versionadded:: 3.9
  41. Imported executable target encapsulating the ``doxygen`` executable usage
  42. requirements, available if Doxygen is found.
  43. ``Doxygen::dot``
  44. .. versionadded:: 3.9
  45. Imported executable target encapsulating the ``dot`` executable usage
  46. requirements, available if the above ``dot`` component is found.
  47. ``Doxygen::mscgen``
  48. .. versionadded:: 3.9
  49. Imported executable target encapsulating the ``mscgen`` executable usage
  50. requirements, available if the above ``mscgen`` component is found.
  51. ``Doxygen::dia``
  52. .. versionadded:: 3.9
  53. Imported executable target encapsulating the ``dia`` executable usage
  54. requirements, available if the above ``dia`` component is found.
  55. These targets can be used in commands such as :command:`add_custom_command`
  56. and are preferred over the older, now-deprecated variables like
  57. ``DOXYGEN_EXECUTABLE``.
  58. Result Variables
  59. ^^^^^^^^^^^^^^^^
  60. This module defines the following variables:
  61. ``Doxygen_FOUND``
  62. Boolean indicating whether (the requested version of) ``doxygen`` executable
  63. and all requested required components are found. For backward compatibility,
  64. the ``DOXYGEN_FOUND`` variable is also set, except it has boolean value of
  65. ``YES`` or ``NO``.
  66. ``Doxygen_VERSION``
  67. .. versionadded:: 4.2
  68. The version of Doxygen found (as reported by ``doxygen --version``).
  69. Commands
  70. ^^^^^^^^
  71. This module provides the following command:
  72. .. command:: doxygen_add_docs
  73. .. versionadded:: 3.9
  74. Adds a custom target for generating documentation with Doxygen during the
  75. build phase:
  76. .. code-block:: cmake
  77. doxygen_add_docs(
  78. <target-name>
  79. [<files-or-dirs>...]
  80. [ALL]
  81. [USE_STAMP_FILE]
  82. [WORKING_DIRECTORY <dir>]
  83. [COMMENT <comment>]
  84. [CONFIG_FILE <file>]
  85. )
  86. By default, this convenience command also generates a configuration file
  87. named ``Doxyfile.<target-name>`` in the current binary directory at
  88. CMake configuration phase. It provides sensible defaults, so most projects
  89. only need to specify input files or directories. Additional behavior and
  90. configuration can be customized using variables described in the following
  91. sections.
  92. .. rubric:: The arguments are:
  93. ``<target-name>``
  94. The name of the target to be created for generating documentation with
  95. Doxygen.
  96. ``<files-or-dirs>...``
  97. One or more paths (files or directories) that serve as input sources for
  98. documentation.
  99. These are passed to the ``INPUT`` Doxygen configuration tag in the
  100. generated ``Doxyfile.<target-name>``. Files listed here are also added
  101. as ``SOURCES`` argument of the underlying :command:`add_custom_target`
  102. command so they appear in IDE project's source list.
  103. When using the ``USE_STAMP_FILE`` option, only files (not directories,
  104. symlinks, or wildcards) are allowed, and each must exist when this
  105. command is called.
  106. ``ALL``
  107. .. versionadded:: 3.12
  108. Adds the created documentation target to the default build target so
  109. that it runs automatically as part of the build phase.
  110. ``USE_STAMP_FILE``
  111. .. versionadded:: 3.16
  112. Enables use of a stamp file to avoid regenerating documentation unless
  113. source files have changed.
  114. Stamp file named ``<target-name>.stamp`` is created in the current binary
  115. directory by an underlying custom command.
  116. With this option present, all entries in ``<files-or-dirs>`` must be
  117. existing files (i.e. no directories, symlinks or wildcards) when this
  118. command is called. An error is raised if any listed path is invalid.
  119. Without this option, CMake will re-run Doxygen every time the
  120. ``<target-name>`` target is built, regardless of whether any input source
  121. file listed in ``<files-or-dirs>`` has changed.
  122. ``WORKING_DIRECTORY <dir>``
  123. By default, the Doxygen working directory is the current source directory
  124. (:variable:`CMAKE_CURRENT_SOURCE_DIR`). This aligns with using relative
  125. input paths.
  126. Use this option, to change and override the directory where Doxygen is
  127. being run. The absolute path ``<dir>`` will then be used as the base
  128. point for relative paths.
  129. Note also that Doxygen's default behavior is to strip the working
  130. directory from relative paths in the generated documentation. See the
  131. ``STRIP_FROM_PATH`` config tag in the `Doxygen manual
  132. <https://www.doxygen.nl/manual/config.html>`_ for more details.
  133. ``COMMENT <comment>``
  134. If provided, the ``<comment>`` string will be passed as the ``COMMENT``
  135. argument to the underlying :command:`add_custom_target` command used to
  136. create the custom target internally. This appears in the build system
  137. output, when the target is built.
  138. ``CONFIG_FILE <file>``
  139. .. versionadded:: 3.27
  140. If specified, the given file provided with full-path will be used as
  141. Doxygen configuration file instead of the default
  142. ``Doxyfile.<target-name>``.
  143. .. rubric:: Variables for customizing Doxygen configuration
  144. The ``doxygen_add_docs()`` command generates a Doxygen configuration file
  145. containing configuration tags. For example:
  146. .. code-block:: text
  147. :caption: ``Doxygen.<target-name>``
  148. DOXYFILE_ENCODING = UTF-8
  149. PROJECT_NAME = DoxygenExample
  150. PROJECT_NUMBER = 1.2.3
  151. PROJECT_BRIEF = "Example project using Doxygen"
  152. PROJECT_LOGO =
  153. OUTPUT_DIRECTORY = /home/user/doxygen-example/build
  154. GENERATE_HTML = YES
  155. GENERATE_MAN = NO
  156. # ...
  157. In CMake, these tags can be modified by setting input variables in form
  158. of ``DOXYGEN_<tag>``, where ``<tag>`` is one of the configuration tags
  159. listed in the `Doxygen manual
  160. <https://www.doxygen.nl/manual/config.html>`_.
  161. For example, to modify the ``GENERATE_HTML`` and ``GENERATE_MAN``
  162. configuration tags, the following variables can be set before calling
  163. ``doxygen_add_docs()``:
  164. .. code-block:: cmake
  165. :caption: ``CMakeLists.txt``
  166. find_package(Doxygen)
  167. if(Doxygen_FOUND)
  168. set(DOXYGEN_GENERATE_HTML NO)
  169. set(DOXYGEN_GENERATE_MAN YES)
  170. doxygen_add_docs(project_docs ${PROJECT_SOURCE_DIR})
  171. endif()
  172. .. rubric:: Default configuration
  173. By default, ``doxygen_add_docs()`` overrides several of Doxygen's settings
  174. to better suit typical CMake projects. Each of the following variables is
  175. explicitly set unless already defined prior to calling
  176. ``doxygen_add_docs()``, with a few exceptions noted below:
  177. ``DOXYGEN_HAVE_DOT``
  178. Set to ``YES`` if the ``dot`` component was requested and found, ``NO``
  179. otherwise. Any existing value of ``DOXYGEN_HAVE_DOT`` is ignored.
  180. ``DOXYGEN_DOT_MULTI_TARGETS``
  181. Set to ``YES`` by this module (note that this requires a ``dot`` version
  182. newer than 1.8.10). This option is only meaningful if ``DOXYGEN_HAVE_DOT``
  183. is also set to ``YES``.
  184. ``DOXYGEN_GENERATE_LATEX``
  185. Set to ``NO`` by this module.
  186. ``DOXYGEN_WARN_FORMAT``
  187. For Visual Studio based generators, this is set to the form recognized by
  188. the Visual Studio IDE: ``$file($line) : $text``. For all other generators,
  189. Doxygen's default value is not overridden.
  190. ``DOXYGEN_PROJECT_NAME``
  191. Populated with the name of the current project (i.e.
  192. :variable:`PROJECT_NAME`).
  193. ``DOXYGEN_PROJECT_NUMBER``
  194. Populated with the version of the current project (i.e.
  195. :variable:`PROJECT_VERSION`).
  196. ``DOXYGEN_PROJECT_BRIEF``
  197. Populated with the description of the current project (i.e.
  198. :variable:`PROJECT_DESCRIPTION`).
  199. ``DOXYGEN_INPUT``
  200. This variable is automatically populated with the list of files and
  201. directories passed to ``doxygen_add_docs()``. For consistent behavior
  202. with other built-in commands like :command:`add_executable`,
  203. :command:`add_library`, and :command:`add_custom_target`, projects should
  204. not set this variable manually. If a variable named ``DOXYGEN_INPUT``
  205. is set by the project, it will be ignored and a warning will be issued.
  206. ``DOXYGEN_RECURSIVE``
  207. Set to ``YES`` by this module.
  208. ``DOXYGEN_EXCLUDE_PATTERNS``
  209. If the ``<files-or-dirs>`` argument of ``doxygen_add_docs()`` contains
  210. directories, this variable will specify patterns used to exclude files
  211. from them. The following patterns are added by default to ensure
  212. CMake-specific files and directories are not included in the input. If
  213. the project sets this variable, those contents are merged with these
  214. additional patterns rather than replacing them:
  215. ::
  216. */.git/*
  217. */.svn/*
  218. */.hg/*
  219. */CMakeFiles/*
  220. */_CPack_Packages/*
  221. DartConfiguration.tcl
  222. CMakeLists.txt
  223. CMakeCache.txt
  224. ``DOXYGEN_OUTPUT_DIRECTORY``
  225. Set to :variable:`CMAKE_CURRENT_BINARY_DIR` by this module. If the
  226. project provides its own value for this and it is a relative path, it
  227. will be interpreted relative to the current binary directory
  228. (:variable:`CMAKE_CURRENT_BINARY_DIR`). This is necessary because
  229. Doxygen will normally be run from a directory within the source tree so
  230. that relative source paths work as expected. If this directory does not
  231. exist, it will be recursively created prior to executing Doxygen.
  232. .. rubric:: Lists
  233. A number of Doxygen config tags accept lists of values, and Doxygen
  234. requires them to be separated by whitespace, while in CMake a list is a
  235. string with items separated by :ref:`semicolons <CMake Language Lists>`.
  236. The ``doxygen_add_docs()`` specifically checks for the following Doxygen
  237. config tags and converts their associated CMake ``DOXYGEN_<tag>`` variable
  238. values into the Doxygen-formatted lists if set:
  239. .. hlist::
  240. - ``ABBREVIATE_BRIEF``
  241. - ``ALIASES``
  242. - ``CITE_BIB_FILES``
  243. - ``DIAFILE_DIRS``
  244. - ``DOTFILE_DIRS``
  245. - ``DOT_FONTPATH``
  246. - ``ENABLED_SECTIONS``
  247. - ``EXAMPLE_PATH``
  248. - ``EXAMPLE_PATTERNS``
  249. - ``EXCLUDE``
  250. - ``EXCLUDE_PATTERNS``
  251. - ``EXCLUDE_SYMBOLS``
  252. - ``EXPAND_AS_DEFINED``
  253. - ``EXTENSION_MAPPING``
  254. - ``EXTRA_PACKAGES``
  255. - ``EXTRA_SEARCH_MAPPINGS``
  256. - ``FILE_PATTERNS``
  257. - ``FILTER_PATTERNS``
  258. - ``FILTER_SOURCE_PATTERNS``
  259. - ``HTML_EXTRA_FILES``
  260. - ``HTML_EXTRA_STYLESHEET``
  261. - ``IGNORE_PREFIX``
  262. - ``IMAGE_PATH``
  263. - ``INCLUDE_FILE_PATTERNS``
  264. - ``INCLUDE_PATH``
  265. - ``INPUT``
  266. - ``LATEX_EXTRA_FILES``
  267. - ``LATEX_EXTRA_STYLESHEET``
  268. - ``MATHJAX_EXTENSIONS``
  269. - ``MSCFILE_DIRS``
  270. - ``PLANTUML_INCLUDE_PATH``
  271. - ``PREDEFINED``
  272. - ``QHP_CUST_FILTER_ATTRS``
  273. - ``QHP_SECT_FILTER_ATTRS``
  274. - ``STRIP_FROM_INC_PATH``
  275. - ``STRIP_FROM_PATH``
  276. - ``TAGFILES``
  277. - ``TCL_SUBST``
  278. For example, to customize the Doxygen file patterns, a usual
  279. :ref:`semicolon-separated list <CMake Language Lists>` can be set in CMake:
  280. .. code-block:: cmake
  281. :caption: ``CMakeLists.txt``
  282. find_package(Doxygen)
  283. if(Doxygen_FOUND)
  284. set(DOXYGEN_FILE_PATTERNS *.c *.cxx *.h *.hxx)
  285. doxygen_add_docs(example_docs ${CMAKE_CURRENT_SOURCE_DIR} ALL)
  286. endif()
  287. Which will produce a Doxygen list of patterns separated by spaces in the
  288. generated configuration file:
  289. .. code-block:: text
  290. :caption: ``Doxyfile.<target-name>``
  291. # ...
  292. FILE_PATTERNS = *.c *.cxx *.h *.hxx
  293. .. rubric:: Automatic quoting
  294. If a Doxygen single-value tag contains spaces, their values must be
  295. surrounded by double quotes (``"..."``). ``doxygen_add_docs()``
  296. automatically quotes values of the following Doxygen tags when generating
  297. the ``Doxyfile``, if they contain at least one space:
  298. .. hlist::
  299. - ``CHM_FILE``
  300. - ``DIA_PATH``
  301. - ``DOCBOOK_OUTPUT``
  302. - ``DOCSET_FEEDNAME``
  303. - ``DOCSET_PUBLISHER_NAME``
  304. - ``DOT_FONTNAME``
  305. - ``DOT_PATH``
  306. - ``EXTERNAL_SEARCH_ID``
  307. - ``FILE_VERSION_FILTER``
  308. - ``GENERATE_TAGFILE``
  309. - ``HHC_LOCATION``
  310. - ``HTML_FOOTER``
  311. - ``HTML_HEADER``
  312. - ``HTML_OUTPUT``
  313. - ``HTML_STYLESHEET``
  314. - ``INPUT_FILTER``
  315. - ``LATEX_FOOTER``
  316. - ``LATEX_HEADER``
  317. - ``LATEX_OUTPUT``
  318. - ``LAYOUT_FILE``
  319. - ``MAN_OUTPUT``
  320. - ``MAN_SUBDIR``
  321. - ``MATHJAX_CODEFILE``
  322. - ``MSCGEN_PATH``
  323. - ``OUTPUT_DIRECTORY``
  324. - ``PERL_PATH``
  325. - ``PLANTUML_JAR_PATH``
  326. - ``PROJECT_BRIEF``
  327. - ``PROJECT_LOGO``
  328. - ``PROJECT_NAME``
  329. - ``QCH_FILE``
  330. - ``QHG_LOCATION``
  331. - ``QHP_CUST_FILTER_NAME``
  332. - ``QHP_VIRTUAL_FOLDER``
  333. - ``RTF_EXTENSIONS_FILE``
  334. - ``RTF_OUTPUT``
  335. - ``RTF_STYLESHEET_FILE``
  336. - ``SEARCHDATA_FILE``
  337. - ``USE_MDFILE_AS_MAINPAGE``
  338. - ``WARN_FORMAT``
  339. - ``WARN_LOGFILE``
  340. - ``XML_OUTPUT``
  341. ``DOXYGEN_VERBATIM_VARS``
  342. .. versionadded:: 3.11
  343. A CMake input variable used by ``doxygen_add_docs()`` to specify a list
  344. of Doxygen input variables (including their leading ``DOXYGEN_`` prefix)
  345. whose values should be passed to the generated ``Doxyfile`` configuration
  346. without automatic quoting.
  347. When using this variable, the project is then responsible for ensuring
  348. that those variables' values make sense when placed directly in the
  349. generated ``Doxyfile`` configuration. For list variables, items are
  350. still separated by spaces in the output, but no quoting is applied to the
  351. individual items.
  352. For certain Doxygen tags, such as ``ALIASES``, automatic quoting done by
  353. ``doxygen_add_docs()`` may interfere with correct syntax (e.g., embedded
  354. quotes).
  355. For example, the following will quote ``DOXYGEN_PROJECT_BRIEF``, but skip
  356. each item in the ``DOXYGEN_ALIASES`` list (:ref:`bracket syntax
  357. <Bracket Argument>` is used to make working with embedded quotes easier):
  358. .. code-block:: cmake
  359. :caption: ``CMakeLists.txt``
  360. find_package(Doxygen)
  361. if(Doxygen_FOUND)
  362. set(DOXYGEN_PROJECT_BRIEF "String with spaces")
  363. set(
  364. DOXYGEN_ALIASES
  365. [[somealias="@some_command param"]]
  366. "anotherAlias=@foobar"
  367. )
  368. set(DOXYGEN_VERBATIM_VARS DOXYGEN_ALIASES)
  369. add_doxygen_docs(project_docs ${PROJECT_SOURCE_DIR})
  370. endif()
  371. The resultant ``Doxyfile`` configuration will contain the following lines:
  372. .. code-block:: text
  373. :caption: ``Doxyfile.project_docs``
  374. PROJECT_BRIEF = "String with spaces"
  375. ALIASES = somealias="@some_command param" anotherAlias=@foobar
  376. Deprecated Variables
  377. ^^^^^^^^^^^^^^^^^^^^
  378. For compatibility with previous versions of CMake, the following variables
  379. are also defined but they are deprecated and should no longer be used:
  380. ``DOXYGEN_EXECUTABLE``
  381. .. deprecated:: 3.9
  382. Use ``Doxygen::doxygen`` imported target instead of referring to the
  383. ``doxygen`` executable directly.
  384. Cache variable containing the path to the ``doxygen`` command.
  385. ``DOXYGEN_DOT_FOUND``
  386. .. deprecated:: 3.9
  387. Boolean result variable indicating whether ``dot`` executable is found.
  388. ``DOXYGEN_DOT_EXECUTABLE``
  389. .. deprecated:: 3.9
  390. Use ``Doxygen::dot`` imported target instead of referring to the ``dot``
  391. executable directly.
  392. Cache variable containing the path to the ``dot`` command-line executable.
  393. ``DOXYGEN_DOT_PATH``
  394. .. deprecated:: 3.9
  395. Result variable containing the path to the directory where the ``dot``
  396. executable is located as reported in ``DOXYGEN_DOT_EXECUTABLE``. The path
  397. may have forward slashes even on Windows and is not suitable for direct
  398. substitution into a ``Doxyfile.in`` template. If this value is needed, get
  399. the :prop_tgt:`IMPORTED_LOCATION` property of the ``Doxygen::dot`` target
  400. and use :command:`get_filename_component` to extract the directory part of
  401. that path. Consider also using :command:`file(TO_NATIVE_PATH)` to prepare
  402. the path for a Doxygen configuration file.
  403. ``DOXYGEN_SKIP_DOT``
  404. .. deprecated:: 3.9
  405. This hint variable has no effect when specifying components in
  406. ``find_package(Doxygen COMPONENTS ...)``. In backward-compatibility mode
  407. (i.e. without specifying components) it prevents this find module from
  408. searching for Graphviz's ``dot`` utility.
  409. ``DOXYGEN_VERSION``
  410. .. deprecated:: 4.2
  411. Superseded by the ``Doxygen_VERSION``.
  412. The version of Doxygen found.
  413. Examples
  414. ^^^^^^^^
  415. Examples: Finding Doxygen
  416. """""""""""""""""""""""""
  417. Finding Doxygen:
  418. .. code-block:: cmake
  419. find_package(Doxygen)
  420. Or, finding Doxygen and specifying a minimum required version:
  421. .. code-block:: cmake
  422. find_package(Doxygen 1.9)
  423. Or, finding Doxygen and making it required (if not found, processing stops
  424. with an error message):
  425. .. code-block:: cmake
  426. find_package(Doxygen REQUIRED)
  427. Or, finding Doxygen as required and specifying ``dot`` tool as required
  428. component and ``mscgen`` and ``dia`` tools as optional components:
  429. .. code-block:: cmake
  430. find_package(Doxygen REQUIRED COMPONENTS dot OPTIONAL_COMPONENTS mscgen dia)
  431. Example: Using Doxygen in CMake
  432. """""""""""""""""""""""""""""""
  433. The following example demonstrates how to find Doxygen and create documentation
  434. from source files at build phase. Once project is built, generated
  435. documentation files will be located in the ``html`` directory inside the
  436. project binary directory:
  437. .. code-block:: cmake
  438. :caption: ``CMakeLists.txt``
  439. cmake_minimum_required(VERSION 3.24)
  440. project(
  441. DoxygenExample
  442. DESCRIPTION "Example project using Doxygen"
  443. VERSION 1.2.3
  444. )
  445. add_executable(example example.c)
  446. find_package(Doxygen)
  447. if(Doxygen_FOUND)
  448. doxygen_add_docs(project_docs example.c ALL USE_STAMP_FILE)
  449. endif()
  450. .. code-block:: c
  451. :caption: ``example.c``
  452. /**
  453. * @file example.c
  454. * @brief A simple example to demonstrate Doxygen.
  455. */
  456. #include <stdio.h>
  457. /**
  458. * @brief Calculates the sum of two integers.
  459. *
  460. * @param a First integer.
  461. * @param b Second integer.
  462. * @return Sum of a and b.
  463. *
  464. * @par Example
  465. * @code
  466. * int result = sum(3, 4);
  467. * printf("%d\n", result); // Outputs: 7
  468. * @endcode
  469. */
  470. int sum(int a, int b) { return a + b; }
  471. /**
  472. * @brief Main function.
  473. *
  474. * @return 0 on success.
  475. */
  476. int main(void)
  477. {
  478. int result = sum(5, 7);
  479. printf("Result: %d\n", result);
  480. return 0;
  481. }
  482. Example: Configuring Doxygen With Variables
  483. """""""""""""""""""""""""""""""""""""""""""
  484. In the following example, Doxygen configuration is customized using CMake
  485. variables. The configuration sets file patterns when using a directory as
  486. the source input (:variable:`CMAKE_CURRENT_SOURCE_DIR`), enables a theme
  487. toggle for switching between light and dark modes, suppresses Doxygen's
  488. standard output during the build phase, specifies a Markdown file as the
  489. main page, and disables warnings about undocumented code:
  490. .. code-block:: cmake
  491. find_package(Doxygen)
  492. if(Doxygen_FOUND)
  493. set(DOXYGEN_FILE_PATTERNS *.c *.cxx *.md)
  494. set(DOXYGEN_HTML_COLORSTYLE "TOGGLE")
  495. set(DOXYGEN_QUIET YES)
  496. set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
  497. set(DOXYGEN_WARN_IF_UNDOCUMENTED NO)
  498. doxygen_add_docs(example_docs ${CMAKE_CURRENT_SOURCE_DIR} ALL)
  499. endif()
  500. Example: Custom Configuration File
  501. """"""""""""""""""""""""""""""""""
  502. In the following example, a custom ``Doxyfile`` configuration file is created
  503. in the current binary directory (:variable:`CMAKE_CURRENT_BINARY_DIR`) prior
  504. to calling the ``doxygen_add_docs()``. This allows project-specific
  505. configuration tags to be customized as needed:
  506. .. code-block:: cmake
  507. :caption: ``CMakeLists.txt``
  508. find_package(Doxygen)
  509. if(Doxygen_FOUND)
  510. configure_file(Doxyfile.in Doxyfile)
  511. doxygen_add_docs(
  512. example_docs
  513. foo.c bar.c
  514. ALL
  515. USE_STAMP_FILE
  516. COMMENT "Generating project documentation with custom Doxyfile"
  517. CONFIG_FILE ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
  518. )
  519. endif()
  520. .. code-block:: text
  521. :caption: ``Doxyfile.in``
  522. PROJECT_NAME = "Customized project name"
  523. OUTPUT_DIRECTORY = "@CMAKE_CURRENT_BINARY_DIR@"
  524. # ...
  525. #]=======================================================================]
  526. # For backwards compatibility support
  527. if(Doxygen_FIND_QUIETLY)
  528. set(DOXYGEN_FIND_QUIETLY TRUE)
  529. endif()
  530. # ===== Rationale for OS X AppBundle mods below =====
  531. # With the OS X GUI version, Doxygen likes to be installed to /Applications
  532. # and it contains the doxygen executable in the bundle. In the versions I've
  533. # seen, it is located in Resources, but in general, more often binaries are
  534. # located in MacOS.
  535. #
  536. # NOTE: The official Doxygen.app distributed for OS X uses non-standard
  537. # conventions. Instead of the command-line "doxygen" tool being placed in
  538. # Doxygen.app/Contents/MacOS, "Doxywizard" is placed there instead and
  539. # "doxygen" is placed in Contents/Resources. This is most likely done
  540. # so that something happens when people double-click on the Doxygen.app
  541. # package. Unfortunately, CMake gets confused by this as when it sees the
  542. # bundle it uses "Doxywizard" as the executable to use instead of
  543. # "doxygen". Therefore to work-around this issue we temporarily disable
  544. # the app-bundle feature, just for this CMake module:
  545. #
  546. if(APPLE)
  547. # Save the old setting
  548. set(TEMP_DOXYGEN_SAVE_CMAKE_FIND_APPBUNDLE ${CMAKE_FIND_APPBUNDLE})
  549. # Disable the App-bundle detection feature
  550. set(CMAKE_FIND_APPBUNDLE "NEVER")
  551. endif()
  552. # FYI:
  553. # In older versions of OS X Doxygen, dot was included with the Doxygen bundle,
  554. # but newer versions require you to download Graphviz.app which contains "dot"
  555. # or use something like homebrew.
  556. # ============== End OSX stuff ================
  557. include(FindPackageHandleStandardArgs)
  558. #
  559. # Find Doxygen...
  560. #
  561. function(_Doxygen_get_version doxy_version result_var doxy_path)
  562. execute_process(
  563. COMMAND "${doxy_path}" --version
  564. OUTPUT_VARIABLE full_doxygen_version
  565. OUTPUT_STRIP_TRAILING_WHITESPACE
  566. RESULT_VARIABLE version_result
  567. )
  568. # Ignore any commit hashes, etc.
  569. string(REGEX MATCH [[^[0-9]+\.[0-9]+\.[0-9]+]] sem_doxygen_version "${full_doxygen_version}")
  570. set(${result_var} ${version_result} PARENT_SCOPE)
  571. set(${doxy_version} ${sem_doxygen_version} PARENT_SCOPE)
  572. endfunction()
  573. function(_Doxygen_version_validator version_match doxy_path)
  574. if(NOT DEFINED Doxygen_FIND_VERSION)
  575. set(${is_valid_version} TRUE PARENT_SCOPE)
  576. else()
  577. _Doxygen_get_version(candidate_version version_result "${doxy_path}")
  578. find_package_check_version("${candidate_version}" valid_doxy_version
  579. HANDLE_VERSION_RANGE
  580. )
  581. set(${version_match} "${valid_doxy_version}" PARENT_SCOPE)
  582. endif()
  583. endfunction()
  584. macro(_Doxygen_find_doxygen)
  585. find_program(
  586. DOXYGEN_EXECUTABLE
  587. NAMES doxygen
  588. PATHS
  589. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\doxygen_is1;Inno Setup: App Path]/bin"
  590. /Applications/Doxygen.app/Contents/Resources
  591. /Applications/Doxygen.app/Contents/MacOS
  592. /Applications/Utilities/Doxygen.app/Contents/Resources
  593. /Applications/Utilities/Doxygen.app/Contents/MacOS
  594. DOC "Doxygen documentation generation tool (https://www.doxygen.nl)"
  595. VALIDATOR _Doxygen_version_validator
  596. )
  597. mark_as_advanced(DOXYGEN_EXECUTABLE)
  598. if(DOXYGEN_EXECUTABLE)
  599. _Doxygen_get_version(Doxygen_VERSION _Doxygen_version_result "${DOXYGEN_EXECUTABLE}")
  600. set(DOXYGEN_VERSION "${Doxygen_VERSION}")
  601. if(_Doxygen_version_result)
  602. if(NOT Doxygen_FIND_QUIETLY)
  603. message(WARNING "Doxygen executable failed unexpected while determining version (exit status: ${_Doxygen_version_result}). Disabling Doxygen.")
  604. endif()
  605. set(DOXYGEN_EXECUTABLE "${DOXYGEN_EXECUTABLE}-FAILED_EXECUTION-NOTFOUND")
  606. else()
  607. # Create an imported target for Doxygen
  608. if(NOT TARGET Doxygen::doxygen)
  609. add_executable(Doxygen::doxygen IMPORTED GLOBAL)
  610. set_target_properties(Doxygen::doxygen PROPERTIES
  611. IMPORTED_LOCATION "${DOXYGEN_EXECUTABLE}"
  612. )
  613. endif()
  614. endif()
  615. endif()
  616. endmacro()
  617. #
  618. # Find Diagram Editor...
  619. #
  620. macro(_Doxygen_find_dia)
  621. set(_x86 "(x86)")
  622. find_program(
  623. DOXYGEN_DIA_EXECUTABLE
  624. NAMES dia
  625. PATHS
  626. "$ENV{ProgramFiles}/Dia"
  627. "$ENV{ProgramFiles${_x86}}/Dia"
  628. DOC "Diagram Editor tool for use with Doxygen"
  629. )
  630. mark_as_advanced(DOXYGEN_DIA_EXECUTABLE)
  631. if(DOXYGEN_DIA_EXECUTABLE)
  632. # The Doxyfile wants the path to the utility, not the entire path
  633. # including file name
  634. get_filename_component(DOXYGEN_DIA_PATH
  635. "${DOXYGEN_DIA_EXECUTABLE}"
  636. DIRECTORY)
  637. if(WIN32)
  638. file(TO_NATIVE_PATH "${DOXYGEN_DIA_PATH}" DOXYGEN_DIA_PATH)
  639. endif()
  640. # Create an imported target for component
  641. if(NOT TARGET Doxygen::dia)
  642. add_executable(Doxygen::dia IMPORTED GLOBAL)
  643. set_target_properties(Doxygen::dia PROPERTIES
  644. IMPORTED_LOCATION "${DOXYGEN_DIA_EXECUTABLE}"
  645. )
  646. endif()
  647. endif()
  648. unset(_x86)
  649. endmacro()
  650. #
  651. # Find Graphviz Dot...
  652. #
  653. macro(_Doxygen_find_dot)
  654. if(WIN32)
  655. set(_x86 "(x86)")
  656. file(
  657. GLOB _Doxygen_GRAPHVIZ_BIN_DIRS
  658. "$ENV{ProgramFiles}/Graphviz*/bin"
  659. "$ENV{ProgramFiles${_x86}}/Graphviz*/bin"
  660. )
  661. unset(_x86)
  662. else()
  663. set(_Doxygen_GRAPHVIZ_BIN_DIRS "")
  664. endif()
  665. find_program(
  666. DOXYGEN_DOT_EXECUTABLE
  667. NAMES dot
  668. PATHS
  669. ${_Doxygen_GRAPHVIZ_BIN_DIRS}
  670. "$ENV{ProgramFiles}/ATT/Graphviz/bin"
  671. "C:/Program Files/ATT/Graphviz/bin"
  672. [HKEY_LOCAL_MACHINE\\SOFTWARE\\ATT\\Graphviz;InstallPath]/bin
  673. /Applications/Graphviz.app/Contents/MacOS
  674. /Applications/Utilities/Graphviz.app/Contents/MacOS
  675. /Applications/Doxygen.app/Contents/Resources
  676. /Applications/Doxygen.app/Contents/MacOS
  677. /Applications/Utilities/Doxygen.app/Contents/Resources
  678. /Applications/Utilities/Doxygen.app/Contents/MacOS
  679. DOC "Dot tool for use with Doxygen"
  680. )
  681. mark_as_advanced(DOXYGEN_DOT_EXECUTABLE)
  682. if(DOXYGEN_DOT_EXECUTABLE)
  683. # The Doxyfile wants the path to the utility, not the entire path
  684. # including file name
  685. get_filename_component(DOXYGEN_DOT_PATH
  686. "${DOXYGEN_DOT_EXECUTABLE}"
  687. DIRECTORY)
  688. if(WIN32)
  689. file(TO_NATIVE_PATH "${DOXYGEN_DOT_PATH}" DOXYGEN_DOT_PATH)
  690. endif()
  691. # Create an imported target for component
  692. if(NOT TARGET Doxygen::dot)
  693. add_executable(Doxygen::dot IMPORTED GLOBAL)
  694. set_target_properties(Doxygen::dot PROPERTIES
  695. IMPORTED_LOCATION "${DOXYGEN_DOT_EXECUTABLE}"
  696. )
  697. endif()
  698. endif()
  699. unset(_Doxygen_GRAPHVIZ_BIN_DIRS)
  700. endmacro()
  701. #
  702. # Find Message Sequence Chart...
  703. #
  704. macro(_Doxygen_find_mscgen)
  705. set(_x86 "(x86)")
  706. find_program(
  707. DOXYGEN_MSCGEN_EXECUTABLE
  708. NAMES mscgen
  709. PATHS
  710. "$ENV{ProgramFiles}/Mscgen"
  711. "$ENV{ProgramFiles${_x86}}/Mscgen"
  712. DOC "Message sequence chart tool for use with Doxygen"
  713. )
  714. mark_as_advanced(DOXYGEN_MSCGEN_EXECUTABLE)
  715. if(DOXYGEN_MSCGEN_EXECUTABLE)
  716. # The Doxyfile wants the path to the utility, not the entire path
  717. # including file name
  718. get_filename_component(DOXYGEN_MSCGEN_PATH
  719. "${DOXYGEN_MSCGEN_EXECUTABLE}"
  720. DIRECTORY)
  721. if(WIN32)
  722. file(TO_NATIVE_PATH "${DOXYGEN_MSCGEN_PATH}" DOXYGEN_MSCGEN_PATH)
  723. endif()
  724. # Create an imported target for component
  725. if(NOT TARGET Doxygen::mscgen)
  726. add_executable(Doxygen::mscgen IMPORTED GLOBAL)
  727. set_target_properties(Doxygen::mscgen PROPERTIES
  728. IMPORTED_LOCATION "${DOXYGEN_MSCGEN_EXECUTABLE}"
  729. )
  730. endif()
  731. endif()
  732. unset(_x86)
  733. endmacro()
  734. # Make sure `doxygen` is one of the components to find
  735. set(_Doxygen_keep_backward_compat FALSE)
  736. if(NOT Doxygen_FIND_COMPONENTS)
  737. # Search at least for `doxygen` executable
  738. set(Doxygen_FIND_COMPONENTS doxygen)
  739. # Preserve backward compatibility:
  740. # search for `dot` also if `DOXYGEN_SKIP_DOT` is not explicitly disable this.
  741. if(NOT DOXYGEN_SKIP_DOT)
  742. list(APPEND Doxygen_FIND_COMPONENTS dot)
  743. endif()
  744. set(_Doxygen_keep_backward_compat TRUE)
  745. elseif(NOT doxygen IN_LIST Doxygen_FIND_COMPONENTS)
  746. list(INSERT Doxygen_FIND_COMPONENTS 0 doxygen)
  747. endif()
  748. #
  749. # Find all requested components of Doxygen...
  750. #
  751. foreach(_comp IN LISTS Doxygen_FIND_COMPONENTS)
  752. if(_comp STREQUAL "doxygen")
  753. _Doxygen_find_doxygen()
  754. elseif(_comp STREQUAL "dia")
  755. _Doxygen_find_dia()
  756. elseif(_comp STREQUAL "dot")
  757. _Doxygen_find_dot()
  758. elseif(_comp STREQUAL "mscgen")
  759. _Doxygen_find_mscgen()
  760. else()
  761. message(WARNING "${_comp} is not a valid Doxygen component")
  762. set(Doxygen_${_comp}_FOUND FALSE)
  763. continue()
  764. endif()
  765. if(TARGET Doxygen::${_comp})
  766. set(Doxygen_${_comp}_FOUND TRUE)
  767. else()
  768. set(Doxygen_${_comp}_FOUND FALSE)
  769. endif()
  770. endforeach()
  771. unset(_comp)
  772. # Verify find results
  773. find_package_handle_standard_args(
  774. Doxygen
  775. REQUIRED_VARS DOXYGEN_EXECUTABLE
  776. VERSION_VAR Doxygen_VERSION
  777. HANDLE_VERSION_RANGE
  778. HANDLE_COMPONENTS
  779. )
  780. #
  781. # Backwards compatibility...
  782. #
  783. if(APPLE)
  784. # Restore the old app-bundle setting
  785. set(CMAKE_FIND_APPBUNDLE ${TEMP_DOXYGEN_SAVE_CMAKE_FIND_APPBUNDLE})
  786. endif()
  787. # Maintain the _FOUND variables as "YES" or "NO" for backwards
  788. # compatibility. This allows people to substitute them directly into
  789. # Doxyfile with configure_file().
  790. if(Doxygen_FOUND)
  791. set(DOXYGEN_FOUND "YES")
  792. else()
  793. set(DOXYGEN_FOUND "NO")
  794. endif()
  795. if(_Doxygen_keep_backward_compat)
  796. if(Doxygen_dot_FOUND)
  797. set(DOXYGEN_DOT_FOUND "YES")
  798. else()
  799. set(DOXYGEN_DOT_FOUND "NO")
  800. endif()
  801. # For backwards compatibility support for even older CMake versions
  802. set(DOXYGEN ${DOXYGEN_EXECUTABLE})
  803. set(DOT ${DOXYGEN_DOT_EXECUTABLE})
  804. # No need to keep any backward compatibility for `DOXYGEN_MSCGEN_XXX`
  805. # and `DOXYGEN_DIA_XXX` since they were not supported before component
  806. # support was added
  807. endif()
  808. unset(_Doxygen_keep_backward_compat)
  809. #
  810. # Allow full control of Doxygen from CMakeLists.txt
  811. #
  812. # Prepare a template Doxyfile and Doxygen's default values CMake file
  813. if(TARGET Doxygen::doxygen)
  814. # If doxygen was found, use it to generate a minimal default Doxyfile.
  815. # We will delete this file after we have finished using it below to
  816. # generate the other files that doxygen_add_docs() will use.
  817. set(_Doxygen_tpl "${CMAKE_BINARY_DIR}/CMakeDoxyfile.tpl")
  818. execute_process(
  819. COMMAND "${DOXYGEN_EXECUTABLE}" -s -g "${_Doxygen_tpl}"
  820. OUTPUT_QUIET
  821. RESULT_VARIABLE _Doxygen_tpl_result
  822. )
  823. if(_Doxygen_tpl_result)
  824. message(FATAL_ERROR
  825. "Unable to generate Doxyfile template: ${_Doxygen_tpl_result}")
  826. elseif(NOT EXISTS "${_Doxygen_tpl}")
  827. message(FATAL_ERROR
  828. "Doxygen has failed to generate a Doxyfile template")
  829. endif()
  830. # Write a do-not-edit header to files we are going to generate...
  831. set(_Doxygen_do_not_edit_header
  832. [[
  833. #
  834. # DO NOT EDIT! THIS FILE WAS GENERATED BY CMAKE!
  835. #
  836. ]]
  837. )
  838. # We only need one copy of these across the whole build, since their
  839. # content is only dependent on the version of Doxygen being used. Therefore
  840. # we always put them at the top of the build tree so that they are in a
  841. # predictable location.
  842. set(_doxyfile_in "${CMAKE_BINARY_DIR}/CMakeDoxyfile.in")
  843. set(_doxyfile_defaults "${CMAKE_BINARY_DIR}/CMakeDoxygenDefaults.cmake")
  844. set(_doxyfile_in_contents "")
  845. set(_doxyfile_defaults_contents "")
  846. # Get strings containing a configuration key from the template Doxyfile
  847. # we obtained from this version of Doxygen. Because some options are split
  848. # across multiple lines by ending lines with backslashes, we cannot just
  849. # use file(STRINGS...) with a REGEX. Instead, read lines without a REGEX
  850. # so that file(STRINGS...) handles the trailing backslash as a line
  851. # continuation. It stores multi-lines as lists, so we then have to replace
  852. # the ";" list separator with backslashed newlines again so that we get the
  853. # original content stored back as the value part.
  854. file(STRINGS "${_Doxygen_tpl}" _file_lines)
  855. unset(_Doxygen_tpl_params)
  856. foreach(_line IN LISTS _file_lines)
  857. if(_line MATCHES "([A-Z][A-Z0-9_]+)( *=)(.*)")
  858. set(_key "${CMAKE_MATCH_1}")
  859. set(_eql "${CMAKE_MATCH_2}")
  860. set(_value "${CMAKE_MATCH_3}")
  861. string(REPLACE "\\" "\\\\" _value "${_value}")
  862. string(REPLACE ";" "\\\n" _value "${_value}")
  863. list(APPEND _Doxygen_tpl_params "${_key}${_eql}${_value}")
  864. endif()
  865. endforeach()
  866. # Build up a Doxyfile that provides @configVar@ substitutions for each
  867. # Doxygen config option as well as a separate CMake script which provides
  868. # the default value for each of those options if the project doesn't supply
  869. # them. Each config option will support substitution of a CMake variable
  870. # of the same name except with DOXYGEN_ prepended.
  871. foreach(_Doxygen_param IN LISTS _Doxygen_tpl_params)
  872. if(_Doxygen_param MATCHES "([A-Z][A-Z0-9_]+)( *)=( (.*))?")
  873. # Ok, this is a config key with a value
  874. if(CMAKE_MATCH_COUNT EQUAL 4)
  875. string(APPEND _doxyfile_in_contents
  876. "${CMAKE_MATCH_1}${CMAKE_MATCH_2}= @DOXYGEN_${CMAKE_MATCH_1}@\n")
  877. # Remove the backslashes we had to preserve to handle newlines
  878. string(REPLACE "\\\n" "\n" _value "${CMAKE_MATCH_4}")
  879. string(APPEND _doxyfile_defaults_contents
  880. "if(NOT DEFINED DOXYGEN_${CMAKE_MATCH_1})
  881. set(DOXYGEN_${CMAKE_MATCH_1} ${_value})
  882. endif()
  883. ")
  884. # Ok, this is a config key with empty default value
  885. elseif(CMAKE_MATCH_COUNT EQUAL 2)
  886. string(APPEND _doxyfile_in_contents
  887. "${CMAKE_MATCH_1}${CMAKE_MATCH_2}= @DOXYGEN_${CMAKE_MATCH_1}@\n")
  888. else()
  889. message(AUTHOR_WARNING
  890. "Unexpected line format! Code review required!\nFault line: ${_Doxygen_param}")
  891. endif()
  892. else()
  893. message(AUTHOR_WARNING
  894. "Unexpected line format! Code review required!\nFault line: ${_Doxygen_param}")
  895. endif()
  896. endforeach()
  897. file(WRITE "${_doxyfile_defaults}" "${_Doxygen_do_not_edit_header}"
  898. "${_doxyfile_defaults_contents}")
  899. file(WRITE "${_doxyfile_in}" "${_Doxygen_do_not_edit_header}"
  900. "${_doxyfile_in_contents}")
  901. # Ok, dumped defaults are not needed anymore...
  902. file(REMOVE "${_Doxygen_tpl}")
  903. unset(_Doxygen_param)
  904. unset(_Doxygen_tpl_params)
  905. unset(_Doxygen_do_not_edit_header)
  906. unset(_Doxygen_tpl)
  907. endif()
  908. function(doxygen_quote_value VARIABLE)
  909. # Quote a value of the given variable if:
  910. # - VARIABLE parameter was really given
  911. # - the variable it names is defined and is not present in the list
  912. # specified by DOXYGEN_VERBATIM_VARS (if set)
  913. # - the value of the named variable isn't already quoted
  914. # - the value has spaces
  915. if(VARIABLE AND DEFINED ${VARIABLE} AND
  916. NOT ${VARIABLE} MATCHES "^\".* .*\"$" AND ${VARIABLE} MATCHES " " AND
  917. NOT (DEFINED DOXYGEN_VERBATIM_VARS AND
  918. "${VARIABLE}" IN_LIST DOXYGEN_VERBATIM_VARS))
  919. set(${VARIABLE} "\"${${VARIABLE}}\"" PARENT_SCOPE)
  920. endif()
  921. endfunction()
  922. function(doxygen_list_to_quoted_strings LIST_VARIABLE)
  923. if(LIST_VARIABLE AND DEFINED ${LIST_VARIABLE})
  924. unset(_inputs)
  925. unset(_sep)
  926. unset(_verbatim)
  927. # Have to test if list items should be treated as verbatim here
  928. # because we lose the variable name when we pass just one list item
  929. # to doxygen_quote_value() below
  930. if(DEFINED DOXYGEN_VERBATIM_VARS AND
  931. "${LIST_VARIABLE}" IN_LIST DOXYGEN_VERBATIM_VARS)
  932. set(_verbatim True)
  933. endif()
  934. foreach(_in IN LISTS ${LIST_VARIABLE})
  935. if(NOT _verbatim)
  936. doxygen_quote_value(_in)
  937. endif()
  938. string(APPEND _inputs "${_sep}${_in}")
  939. set(_sep " ")
  940. endforeach()
  941. set(${LIST_VARIABLE} "${_inputs}" PARENT_SCOPE)
  942. endif()
  943. endfunction()
  944. function(doxygen_add_docs targetName)
  945. set(_options ALL USE_STAMP_FILE)
  946. set(_one_value_args WORKING_DIRECTORY COMMENT CONFIG_FILE)
  947. set(_multi_value_args)
  948. cmake_parse_arguments(_args
  949. "${_options}"
  950. "${_one_value_args}"
  951. "${_multi_value_args}"
  952. ${ARGN})
  953. if(NOT _args_COMMENT)
  954. set(_args_COMMENT "Generating API documentation for ${targetName}")
  955. endif()
  956. if(NOT _args_WORKING_DIRECTORY)
  957. set(_args_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
  958. endif()
  959. if(DEFINED DOXYGEN_INPUT)
  960. message(WARNING
  961. "DOXYGEN_INPUT is set but it will be ignored. Pass the files and directories \
  962. directly to the doxygen_add_docs() command instead.")
  963. endif()
  964. set(DOXYGEN_INPUT ${_args_UNPARSED_ARGUMENTS})
  965. if(NOT TARGET Doxygen::doxygen)
  966. message(FATAL_ERROR "Doxygen was not found, needed by \
  967. doxygen_add_docs() for target ${targetName}")
  968. endif()
  969. # If not already defined, set some relevant defaults based on the
  970. # assumption that the documentation is for the whole project. Details
  971. # specified in the project() command will be used to populate a number of
  972. # these defaults.
  973. if(NOT DEFINED DOXYGEN_PROJECT_NAME)
  974. # The PROJECT_NAME tag is a single word (or a sequence of words
  975. # surrounded by double-quotes, unless you are using Doxywizard) that
  976. # should identify the project for which the documentation is generated.
  977. # This name is used in the title of most generated pages and in a few
  978. # other places. The default value is: My Project.
  979. set(DOXYGEN_PROJECT_NAME ${PROJECT_NAME})
  980. endif()
  981. if(NOT DEFINED DOXYGEN_PROJECT_NUMBER)
  982. # The PROJECT_NUMBER tag can be used to enter a project or revision
  983. # number. This could be handy for archiving the generated documentation
  984. # or if some version control system is used.
  985. set(DOXYGEN_PROJECT_NUMBER ${PROJECT_VERSION})
  986. endif()
  987. if(NOT DEFINED DOXYGEN_PROJECT_BRIEF)
  988. # Using the PROJECT_BRIEF tag one can provide an optional one line
  989. # description for a project that appears at the top of each page and
  990. # should give viewer a quick idea about the purpose of the project.
  991. # Keep the description short.
  992. set(DOXYGEN_PROJECT_BRIEF "${PROJECT_DESCRIPTION}")
  993. endif()
  994. if(NOT DEFINED DOXYGEN_RECURSIVE)
  995. # The RECURSIVE tag can be used to specify whether or not
  996. # subdirectories should be searched for input files as well. CMake
  997. # projects generally evolve to span multiple directories, so it makes
  998. # more sense for this to be on by default. Doxygen's default value
  999. # has this setting turned off, so we override it.
  1000. set(DOXYGEN_RECURSIVE YES)
  1001. endif()
  1002. if(NOT DEFINED DOXYGEN_OUTPUT_DIRECTORY)
  1003. # The OUTPUT_DIRECTORY tag is used to specify the (relative or
  1004. # absolute) path into which the generated documentation will be
  1005. # written. If a relative path is used, Doxygen will interpret it as
  1006. # being relative to the location where doxygen was started, but we need
  1007. # to run Doxygen in the source tree so that relative input paths work
  1008. # intuitively. Therefore, we ensure that the output directory is always
  1009. # an absolute path and if the project provided a relative path, we
  1010. # treat it as relative to the current BINARY directory so that output
  1011. # is not generated inside the source tree.
  1012. set(DOXYGEN_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
  1013. elseif(NOT IS_ABSOLUTE "${DOXYGEN_OUTPUT_DIRECTORY}")
  1014. get_filename_component(DOXYGEN_OUTPUT_DIRECTORY
  1015. "${DOXYGEN_OUTPUT_DIRECTORY}"
  1016. ABSOLUTE
  1017. BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
  1018. endif()
  1019. if(NOT DEFINED DOXYGEN_HAVE_DOT)
  1020. # If you set the HAVE_DOT tag to YES then doxygen will assume the dot
  1021. # tool is available from the path. This tool is part of Graphviz (see:
  1022. # https://www.graphviz.org/), a graph visualization toolkit from AT&T
  1023. # and Lucent Bell Labs. The other options in this section have no
  1024. # effect if this option is set to NO.
  1025. # Doxygen's default value is: NO.
  1026. if(Doxygen_dot_FOUND)
  1027. set(DOXYGEN_HAVE_DOT "YES")
  1028. else()
  1029. set(DOXYGEN_HAVE_DOT "NO")
  1030. endif()
  1031. endif()
  1032. if(NOT DEFINED DOXYGEN_DOT_MULTI_TARGETS)
  1033. # Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate
  1034. # multiple output files in one run (i.e. multiple -o and -T options on
  1035. # the command line). This makes dot run faster, but since only newer
  1036. # versions of dot (>1.8.10) support this, Doxygen disables this feature
  1037. # by default.
  1038. # This tag requires that the tag HAVE_DOT is set to YES.
  1039. set(DOXYGEN_DOT_MULTI_TARGETS YES)
  1040. endif()
  1041. if(NOT DEFINED DOXYGEN_GENERATE_LATEX)
  1042. # If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX
  1043. # output. We only want the HTML output enabled by default, so we turn
  1044. # this off if the project hasn't specified it.
  1045. set(DOXYGEN_GENERATE_LATEX NO)
  1046. endif()
  1047. if(NOT DEFINED DOXYGEN_WARN_FORMAT)
  1048. if(CMAKE_VS_MSBUILD_COMMAND OR CMAKE_VS_DEVENV_COMMAND)
  1049. # The WARN_FORMAT tag determines the format of the warning messages
  1050. # that doxygen can produce. The string should contain the $file,
  1051. # $line and $text tags, which will be replaced by the file and line
  1052. # number from which the warning originated and the warning text.
  1053. # Optionally, the format may contain $version, which will be
  1054. # replaced by the version of the file (if it could be obtained via
  1055. # FILE_VERSION_FILTER).
  1056. # Doxygen's default value is: $file:$line: $text
  1057. set(DOXYGEN_WARN_FORMAT "$file($line) : $text ")
  1058. endif()
  1059. endif()
  1060. if(DEFINED DOXYGEN_WARN_LOGFILE AND NOT IS_ABSOLUTE "${DOXYGEN_WARN_LOGFILE}")
  1061. # The WARN_LOGFILE tag can be used to specify a file to which warning and error
  1062. # messages should be written. If left blank the output is written to standard
  1063. # error (stderr).
  1064. get_filename_component(DOXYGEN_WARN_LOGFILE
  1065. "${DOXYGEN_WARN_LOGFILE}"
  1066. ABSOLUTE
  1067. BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
  1068. endif()
  1069. # Any files from the INPUT that match any of the EXCLUDE_PATTERNS will be
  1070. # excluded from the set of input files. We provide some additional patterns
  1071. # to prevent commonly unwanted things from CMake builds being pulled in.
  1072. #
  1073. # Note that the wildcards are matched against the file with absolute path,
  1074. # so to exclude all test directories for example use the pattern */test/*
  1075. list(
  1076. APPEND
  1077. DOXYGEN_EXCLUDE_PATTERNS
  1078. "*/.git/*"
  1079. "*/.svn/*"
  1080. "*/.hg/*"
  1081. "*/CMakeFiles/*"
  1082. "*/_CPack_Packages/*"
  1083. "DartConfiguration.tcl"
  1084. "CMakeLists.txt"
  1085. "CMakeCache.txt"
  1086. )
  1087. # Now bring in Doxygen's defaults for those things the project has not
  1088. # already set and we have not provided above
  1089. include("${CMAKE_BINARY_DIR}/CMakeDoxygenDefaults.cmake" OPTIONAL)
  1090. # Cleanup built HTMLs on "make clean"
  1091. # TODO Any other dirs?
  1092. if(DOXYGEN_GENERATE_HTML)
  1093. if(IS_ABSOLUTE "${DOXYGEN_HTML_OUTPUT}")
  1094. set(_args_clean_html_dir "${DOXYGEN_HTML_OUTPUT}")
  1095. else()
  1096. set(_args_clean_html_dir
  1097. "${DOXYGEN_OUTPUT_DIRECTORY}/${DOXYGEN_HTML_OUTPUT}")
  1098. endif()
  1099. set_property(DIRECTORY APPEND PROPERTY
  1100. ADDITIONAL_CLEAN_FILES "${_args_clean_html_dir}")
  1101. endif()
  1102. # Build up a list of files we can identify from the inputs so we can list
  1103. # them as DEPENDS and SOURCES in the custom command/target (the latter
  1104. # makes them display in IDEs). This must be done before we transform the
  1105. # various DOXYGEN_... variables below because we need to process
  1106. # DOXYGEN_INPUT as a list first.
  1107. unset(_sources)
  1108. foreach(_item IN LISTS DOXYGEN_INPUT)
  1109. get_filename_component(_abs_item "${_item}" ABSOLUTE
  1110. BASE_DIR "${_args_WORKING_DIRECTORY}")
  1111. get_source_file_property(_isGenerated "${_abs_item}" GENERATED)
  1112. if(_isGenerated OR
  1113. (EXISTS "${_abs_item}" AND
  1114. NOT IS_DIRECTORY "${_abs_item}" AND
  1115. NOT IS_SYMLINK "${_abs_item}"))
  1116. list(APPEND _sources "${_abs_item}")
  1117. elseif(_args_USE_STAMP_FILE)
  1118. message(FATAL_ERROR "Source does not exist or is not a file:\n"
  1119. " ${_abs_item}\n"
  1120. "Only existing files may be specified when the "
  1121. "USE_STAMP_FILE option is given.")
  1122. endif()
  1123. endforeach()
  1124. # Transform known list type options into space separated strings.
  1125. set(_doxygen_list_options
  1126. ABBREVIATE_BRIEF
  1127. ALIASES
  1128. CITE_BIB_FILES
  1129. DIAFILE_DIRS
  1130. DOTFILE_DIRS
  1131. DOT_FONTPATH
  1132. ENABLED_SECTIONS
  1133. EXAMPLE_PATH
  1134. EXAMPLE_PATTERNS
  1135. EXCLUDE
  1136. EXCLUDE_PATTERNS
  1137. EXCLUDE_SYMBOLS
  1138. EXPAND_AS_DEFINED
  1139. EXTENSION_MAPPING
  1140. EXTRA_PACKAGES
  1141. EXTRA_SEARCH_MAPPINGS
  1142. FILE_PATTERNS
  1143. FILTER_PATTERNS
  1144. FILTER_SOURCE_PATTERNS
  1145. HTML_EXTRA_FILES
  1146. HTML_EXTRA_STYLESHEET
  1147. IGNORE_PREFIX
  1148. IMAGE_PATH
  1149. INCLUDE_FILE_PATTERNS
  1150. INCLUDE_PATH
  1151. INPUT
  1152. LATEX_EXTRA_FILES
  1153. LATEX_EXTRA_STYLESHEET
  1154. MATHJAX_EXTENSIONS
  1155. MSCFILE_DIRS
  1156. PLANTUML_INCLUDE_PATH
  1157. PREDEFINED
  1158. QHP_CUST_FILTER_ATTRS
  1159. QHP_SECT_FILTER_ATTRS
  1160. STRIP_FROM_INC_PATH
  1161. STRIP_FROM_PATH
  1162. TAGFILES
  1163. TCL_SUBST
  1164. )
  1165. foreach(_item IN LISTS _doxygen_list_options)
  1166. doxygen_list_to_quoted_strings(DOXYGEN_${_item})
  1167. endforeach()
  1168. # Transform known single value variables which may contain spaces, such as
  1169. # paths or description strings.
  1170. set(_doxygen_quoted_options
  1171. CHM_FILE
  1172. DIA_PATH
  1173. DOCBOOK_OUTPUT
  1174. DOCSET_FEEDNAME
  1175. DOCSET_PUBLISHER_NAME
  1176. DOT_FONTNAME
  1177. DOT_PATH
  1178. EXTERNAL_SEARCH_ID
  1179. FILE_VERSION_FILTER
  1180. GENERATE_TAGFILE
  1181. HHC_LOCATION
  1182. HTML_FOOTER
  1183. HTML_HEADER
  1184. HTML_OUTPUT
  1185. HTML_STYLESHEET
  1186. INPUT_FILTER
  1187. LATEX_FOOTER
  1188. LATEX_HEADER
  1189. LATEX_OUTPUT
  1190. LAYOUT_FILE
  1191. MAN_OUTPUT
  1192. MAN_SUBDIR
  1193. MATHJAX_CODEFILE
  1194. MSCGEN_PATH
  1195. OUTPUT_DIRECTORY
  1196. PERL_PATH
  1197. PLANTUML_JAR_PATH
  1198. PROJECT_BRIEF
  1199. PROJECT_LOGO
  1200. PROJECT_NAME
  1201. QCH_FILE
  1202. QHG_LOCATION
  1203. QHP_CUST_FILTER_NAME
  1204. QHP_VIRTUAL_FOLDER
  1205. RTF_EXTENSIONS_FILE
  1206. RTF_OUTPUT
  1207. RTF_STYLESHEET_FILE
  1208. SEARCHDATA_FILE
  1209. USE_MDFILE_AS_MAINPAGE
  1210. WARN_FORMAT
  1211. WARN_LOGFILE
  1212. XML_OUTPUT
  1213. )
  1214. # Store the unmodified value of DOXYGEN_OUTPUT_DIRECTORY prior to invoking
  1215. # doxygen_quote_value() below. This will mutate the string specifically for
  1216. # consumption by Doxygen's config file, which we do not want when we use it
  1217. # later in the custom target's commands.
  1218. set( _original_doxygen_output_dir ${DOXYGEN_OUTPUT_DIRECTORY} )
  1219. foreach(_item IN LISTS _doxygen_quoted_options)
  1220. doxygen_quote_value(DOXYGEN_${_item})
  1221. endforeach()
  1222. # Prepare doxygen configuration file
  1223. set(_doxyfile_template "${CMAKE_BINARY_DIR}/CMakeDoxyfile.in")
  1224. if(_args_CONFIG_FILE)
  1225. if(NOT EXISTS "${_args_CONFIG_FILE}")
  1226. message(FATAL_ERROR "Option CONFIG_FILE specifies file:\n ${_args_CONFIG_FILE}\nbut it does not exist.")
  1227. endif()
  1228. set(_target_doxyfile "${_args_CONFIG_FILE}")
  1229. else()
  1230. set(_target_doxyfile "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.${targetName}")
  1231. configure_file("${_doxyfile_template}" "${_target_doxyfile}")
  1232. endif()
  1233. unset(_all)
  1234. if(${_args_ALL})
  1235. set(_all ALL)
  1236. endif()
  1237. # Only create the stamp file if asked to. If we don't create it,
  1238. # the target will always be considered out-of-date.
  1239. if(_args_USE_STAMP_FILE)
  1240. set(__stamp_file "${CMAKE_CURRENT_BINARY_DIR}/${targetName}.stamp")
  1241. add_custom_command(
  1242. VERBATIM
  1243. OUTPUT ${__stamp_file}
  1244. COMMAND ${CMAKE_COMMAND} -E make_directory ${_original_doxygen_output_dir}
  1245. COMMAND "${DOXYGEN_EXECUTABLE}" "${_target_doxyfile}"
  1246. COMMAND ${CMAKE_COMMAND} -E touch ${__stamp_file}
  1247. WORKING_DIRECTORY "${_args_WORKING_DIRECTORY}"
  1248. DEPENDS "${_target_doxyfile}" ${_sources}
  1249. COMMENT "${_args_COMMENT}"
  1250. )
  1251. add_custom_target(${targetName} ${_all}
  1252. DEPENDS ${__stamp_file}
  1253. SOURCES ${_sources}
  1254. )
  1255. unset(__stamp_file)
  1256. else()
  1257. add_custom_target( ${targetName} ${_all} VERBATIM
  1258. COMMAND ${CMAKE_COMMAND} -E make_directory ${_original_doxygen_output_dir}
  1259. COMMAND "${DOXYGEN_EXECUTABLE}" "${_target_doxyfile}"
  1260. WORKING_DIRECTORY "${_args_WORKING_DIRECTORY}"
  1261. DEPENDS "${_target_doxyfile}" ${_sources}
  1262. COMMENT "${_args_COMMENT}"
  1263. SOURCES ${_sources}
  1264. )
  1265. endif()
  1266. endfunction()