FindDoxygen.cmake 51 KB

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