# Difference between target\_link\_libraries and adding headers via target\_sources

**URL:** https://discourse.cmake.org/t/difference-between-target-link-libraries-and-adding-headers-via-target-sources/15730
**Category:** Code
**Tags:** os:windows
**Created:** [June 24, 2026, 2:37pm UTC](https://discourse.cmake.org/t/difference-between-target-link-libraries-and-adding-headers-via-target-sources/15730 "2026-06-24T14:37:13Z")
**Posts on this page:** 1
**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: [June 24, 2026, 2:37pm UTC](https://discourse.cmake.org/t/difference-between-target-link-libraries-and-adding-headers-via-target-sources/15730/1 "2026-06-24T14:37:13Z")

</div>

Hi all

Is target link libraries needed when wanted to add the .c files in a library, and then do target\_sources file sets to specify which header files to use from that(or what the file needs)? Also, if I strictly just wnat to add a header file(an interface library), do I do target link libraries INTERFACE said target and then in the target-sources add it in in the files section?

Something like so

> cmake\_path(GET CMAKE\_CURRENT\_SOURCE\_DIR PARENT\_PATH PARENT\_DIR)
> 
> add\_executable(app\_main main.c)
> 
> target\_sources(app\_main  
> PUBLIC  
> FILE\_SET HEADERS  
> BASE\_DIRS  
> ${PARENT\_DIR}/tusb\_src  
> ${PARENT\_DIR}/file\_processing  
> ${CMAKE\_CURRENT\_SOURCE\_DIR}  
> FILES  
> ${PARENT\_DIR}/file\_processing/file\_processing.h  
> ${PARENT\_DIR}/hardware\_processing/common\_header.h)
> 
> ## target\_include\_directories(${EXECUTABLE\_NAME} PUBLIC ${CMAKE\_CURRENT\_SOURCE\_DIR})
> 
> ##target\_compile\_definitions(app\_main PUBLIC CFG\_TUH\_ENABLED=1)
> 
> target\_link\_libraries(app\_main PRIVATE file\_processing host\_storage pico\_multicore hardware\_clocks file\_processing common\_header)

with common header being defined as

> set(common\_processing\_Headers ${CMAKE\_CURRENT\_SOURCE\_DIR}/common\_header.h)
> 
> add\_library(common\_headers INTERFACE ${common\_processing\_HEADERS})
> 
> target\_link\_libraries(hardware\_processing  
> PRIVATE hardware\_spi hardware\_sync  
> PUBLIC hardware\_pio hardware\_irq hardware\_gpio hardware\_dma fatfs\_lib  
> PUBLIC hardware\_uart  
> INTERFACE common\_headers)

Is this a correct way to do this? I’m just very unsure about this

Kind regards
