# How do I add depencies on header file to custom target

**URL:** <https://discourse.cmake.org/t/how-do-i-add-depencies-on-header-file-to-custom-target/218>\
**Category:** Code\
**Created:** [November 18, 2019, 8:43am UTC](https://discourse.cmake.org/t/how-do-i-add-depencies-on-header-file-to-custom-target/218 "2019-11-18T08:43:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickez](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nickez/32/166_2.png) [@nickez](https://discourse.cmake.org/u/nickez)\
**Post date:** [November 18, 2019, 8:43am UTC](https://discourse.cmake.org/t/how-do-i-add-depencies-on-header-file-to-custom-target/218/1 "2019-11-18T08:43:41Z")

</div>

Hey,

How do I add a dependency of a header file to a custom target? Basically I have a header file that contains a few header files. And I want to add all the transitive dependencies to a custom target.

It seems like if I only add the header file CMake won’t pick up all the transitive dependencies.

Thanks

---

<div class="post-metadata">

**Author:** ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)\
**Post date:** [November 18, 2019, 6:26pm UTC](https://discourse.cmake.org/t/how-do-i-add-depencies-on-header-file-to-custom-target/218/2 "2019-11-18T18:26:49Z")

</div>

These dependencies are implied by the content of a file, and so are called “implicit dependencies”. CMake models C and C++ preprocessor dependencies (header file inclusion) for rules associated with compiling sources into object files. CMake does not model implicit dependencies in general for arbitrary custom commands.

The [add\_custom\_command](https://cmake.org/cmake/help/v3.16/command/add_custom_command.html#generating-files) documentation does mention the `IMPLICIT_DEPENDS` option that can be used with Makefile generators. There is also a `DEPFILE` option for use with Ninja, but the custom command itself is responsible for generating the named file.

---

<div class="post-metadata">

**Author:** ![nickez](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nickez/32/166_2.png) [@nickez](https://discourse.cmake.org/u/nickez)\
**Post date:** [November 18, 2019, 8:11pm UTC](https://discourse.cmake.org/t/how-do-i-add-depencies-on-header-file-to-custom-target/218/3 "2019-11-18T20:11:39Z")

</div>

Thanks, I’ll take a look at those.
