# Set environment variables for doxygen\_add\_docs

**URL:** https://discourse.cmake.org/t/set-environment-variables-for-doxygen-add-docs/9634
**Category:** Usage
**Created:** [December 14, 2023, 3:06pm UTC](https://discourse.cmake.org/t/set-environment-variables-for-doxygen-add-docs/9634 "2023-12-14T15:06:07Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![KUGA2](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kuga2/32/4968_2.png) [@KUGA2](https://discourse.cmake.org/u/KUGA2)
#### Post date: [December 14, 2023, 3:06pm UTC](https://discourse.cmake.org/t/set-environment-variables-for-doxygen-add-docs/9634/1 "2023-12-14T15:06:07Z")

</div>

Hi,

in a Doxyfile (supported with CONFIG\_FILE) you can reference files via environment. e.g.

```auto
@INCLUDE_PATH = $(DOXYGEN_INCLUDE_PATH)
@INCLUDE = include.doxygen

```

S.a. [Doxygen Manual: Configuration](https://www.doxygen.nl/manual/config.html)

Can you set environment variables for doxygen\_add\_docs()?

---

<div class="post-metadata">

### Author: ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)
#### Post date: [December 14, 2023, 7:35pm UTC](https://discourse.cmake.org/t/set-environment-variables-for-doxygen-add-docs/9634/2 "2023-12-14T19:35:15Z")

</div>

You can set environment variables in a build preset, but other than that, I think the only option would be to create a custom target that runs a script which first sets the environment variables and then calls Doxygen.

---

<div class="post-metadata">

### Author: ![KUGA2](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kuga2/32/4968_2.png) [@KUGA2](https://discourse.cmake.org/u/KUGA2)
#### Post date: [December 15, 2023, 8:40am UTC](https://discourse.cmake.org/t/set-environment-variables-for-doxygen-add-docs/9634/3 "2023-12-15T08:40:51Z")

</div>

_custom target that runs … Doxygen_

That is deprecated, as `DOXYGEN_EXECUTABLE` is deprecated. I cannot run doxygen without knowing where `DOXYGEN_EXECUTABLE` is.

My current workaround is to “configure” my doxyfile and replace these `$(<var>)` things manually by `string(REPLACE)`.

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [December 15, 2023, 2:35pm UTC](https://discourse.cmake.org/t/set-environment-variables-for-doxygen-add-docs/9634/4 "2023-12-15T14:35:37Z")

</div>

> [@KUGA2](#):
>
> I cannot run doxygen without knowing where `DOXYGEN_EXECUTABLE` is.

That’s not quite true, you can specify the name of an executable target (such as `Doxygen::doxygen`) as the `COMMAND` of a custom command. And if that is not enough for you, you can always use the genex [`$<TARGET_FILE:Doxygen::doxygen>`](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#genex:TARGET_FILE) to access the path at generate time.

---

<div class="post-metadata">

### Author: ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)
#### Post date: [December 16, 2023, 12:22am UTC](https://discourse.cmake.org/t/set-environment-variables-for-doxygen-add-docs/9634/5 "2023-12-16T00:22:43Z")

</div>

Please consider the straight forward way, to create the desired configuration with `configure_file` and alike.

When using `cmake -E env`: Depending on the content of your variable, quoting for the shell is needed in a portable way. And Windows has a low limit for command line length.  
Writing a e.g. cmake script which sets the env var and then executes doxygen: does not make it easier than generating the full config directly.
