# A install directory depends on custom command

**URL:** <https://discourse.cmake.org/t/a-install-directory-depends-on-custom-command/7171>\
**Category:** Code\
**Created:** [January 1, 2023, 2:45pm UTC](https://discourse.cmake.org/t/a-install-directory-depends-on-custom-command/7171 "2023-01-01T14:45:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bradbell](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/e95f7d/32.png) [@bradbell](https://discourse.cmake.org/u/bradbell)\
**Post date:** [January 1, 2023, 2:45pm UTC](https://discourse.cmake.org/t/a-install-directory-depends-on-custom-command/7171/1 "2023-01-01T14:45:34Z")

</div>

I am installing a directory that is created by a custom command. How do I make that step in the install depend on first executing the custom comamnd ?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [January 1, 2023, 11:46pm UTC](https://discourse.cmake.org/t/a-install-directory-depends-on-custom-command/7171/2 "2023-01-01T23:46:47Z")

</div>

There is no way to make the install script (or its build system target) depend on anything other than `all`. See [this issue](https://gitlab.kitware.com/cmake/cmake/-/issues/8438). You can make the `install()` command in your code have `OPTIONAL` to skip installing it if it doesn’t exist.

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [January 2, 2023, 6:07am UTC](https://discourse.cmake.org/t/a-install-directory-depends-on-custom-command/7171/3 "2023-01-02T06:07:03Z")

</div>

An output of the custom command must be part of a target that is not excluded from ALL.

---

<div class="post-metadata">

**Author:** ![bradbell](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/e95f7d/32.png) [@bradbell](https://discourse.cmake.org/u/bradbell)\
**Post date:** [January 2, 2023, 10:21am UTC](https://discourse.cmake.org/t/a-install-directory-depends-on-custom-command/7171/4 "2023-01-02T10:21:36Z")

</div>

1. I was not aware that the install command depended on the all target. I did not see mention of that in [https://cmake.org/cmake/help/latest/command/install.html](https://cmake.org/cmake/help/latest/command/install.html)

2. Using the ALL option in add\_custom\_target I was able the get the command to execute before the install.

3. How do I get the add\_custom\_target command to recognize that the directory has already been created so that the command is not re-run with each make all ?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [January 3, 2023, 10:07pm UTC](https://discourse.cmake.org/t/a-install-directory-depends-on-custom-command/7171/5 "2023-01-03T22:07:24Z")

</div>

> [@bradbell](#):
>
> How do I get the add\_custom\_target command to recognize that the directory has already been created so that the command is not re-run with each make all ?

`make` (and some other tools) do not handle dependencies on directories all that well. CMake can’t fix that.

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [January 4, 2023, 8:38am UTC](https://discourse.cmake.org/t/a-install-directory-depends-on-custom-command/7171/6 "2023-01-04T08:38:13Z")

</div>

I suggest setting the dependency to one file in that directory that is created for sure.
