# If I link a library, do I also get the header files it uses without having to declare it in target\_include\_directories or target\_sources

**URL:** https://discourse.cmake.org/t/if-i-link-a-library-do-i-also-get-the-header-files-it-uses-without-having-to-declare-it-in-target-include-directories-or-target-sources/15513
**Category:** Usage
**Created:** [February 18, 2026, 3:01pm UTC](https://discourse.cmake.org/t/if-i-link-a-library-do-i-also-get-the-header-files-it-uses-without-having-to-declare-it-in-target-include-directories-or-target-sources/15513 "2026-02-18T15:01:17Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Maaz\_Madha](https://discourse.cmake.org/user_avatar/discourse.cmake.org/maaz_madha/32/5927_2.png) [@Maaz\_Madha](https://discourse.cmake.org/u/Maaz_Madha)
#### Post date: [February 18, 2026, 3:01pm UTC](https://discourse.cmake.org/t/if-i-link-a-library-do-i-also-get-the-header-files-it-uses-without-having-to-declare-it-in-target-include-directories-or-target-sources/15513/1 "2026-02-18T15:01:17Z")

</div>

If I use `target_sources()` to add a couple of header files to a library target, and then link that library to another target using `target_link_libraries()`, do I automatically inherit the include paths for those headers?

In other words, if I include one of those headers inside a source file of the new library, will the compiler automatically know where to find it? Or do I still need to explicitly specify the include directories using `target_include_directories()`?

I’m trying to understand whether adding headers via `target_sources()` is enough to propagate their include paths to dependent targets, or whether include directories must always be exported separately.

Kind regards

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [February 18, 2026, 9:31pm UTC](https://discourse.cmake.org/t/if-i-link-a-library-do-i-also-get-the-header-files-it-uses-without-having-to-declare-it-in-target-include-directories-or-target-sources/15513/2 "2026-02-18T21:31:39Z")

</div>

Plain `target_sources()` adding a bare header won’t do it for you, but if you add the header to a file set (which is done using `target_sources()` with the FILE\_SET keyword), then header search paths _will_ be handled for you. Read up on [file sets in the `target_sources()` documentation](https://cmake.org/cmake/help/latest/command/target_sources.html#file-sets) to understand how it works. It requires you to think about your directory structure and what directories you want to be propagated to consumers of a target. It isn’t quite “CMake figures everything out for you” (because it can’t, you have to make some decisions).

---

<div class="post-metadata">

### Author: ![Maaz\_Madha](https://discourse.cmake.org/user_avatar/discourse.cmake.org/maaz_madha/32/5927_2.png) [@Maaz\_Madha](https://discourse.cmake.org/u/Maaz_Madha)
#### Post date: [March 31, 2026, 2:37pm UTC](https://discourse.cmake.org/t/if-i-link-a-library-do-i-also-get-the-header-files-it-uses-without-having-to-declare-it-in-target-include-directories-or-target-sources/15513/3 "2026-03-31T14:37:03Z")

</div>

So passing a target to another as PUBLIC, and the secondary target is linked to another, the header files from the first one will be naturally propagated through because of the target\_sources() FILE\_SET keyword

---

<div class="post-metadata">

### Author: ![Maaz\_Madha](https://discourse.cmake.org/user_avatar/discourse.cmake.org/maaz_madha/32/5927_2.png) [@Maaz\_Madha](https://discourse.cmake.org/u/Maaz_Madha)
#### Post date: [March 31, 2026, 2:40pm UTC](https://discourse.cmake.org/t/if-i-link-a-library-do-i-also-get-the-header-files-it-uses-without-having-to-declare-it-in-target-include-directories-or-target-sources/15513/4 "2026-03-31T14:40:58Z")

</div>

So I can do #include (in my main.c for example) I won’t need to add the header files and search directory path in my target\_sources in my main.c, because the target\_link\_libraries would handle it?
