# Getting a list of all source files for the running clang-format

**URL:** https://discourse.cmake.org/t/getting-a-list-of-all-source-files-for-the-running-clang-format/11217
**Category:** Code
**Created:** [July 10, 2024, 2:51pm UTC](https://discourse.cmake.org/t/getting-a-list-of-all-source-files-for-the-running-clang-format/11217 "2024-07-10T14:51:09Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![gracicot](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gracicot/32/4525_2.png) [@gracicot](https://discourse.cmake.org/u/gracicot)
#### Post date: [July 10, 2024, 2:51pm UTC](https://discourse.cmake.org/t/getting-a-list-of-all-source-files-for-the-running-clang-format/11217/1 "2024-07-10T14:51:10Z")

</div>

I’m creating a custom target to run clang-format on all the source file of a target.

Here’s what I got:

```auto
add_custom_target(format-fix
    COMMAND clang-format -style=file -i $<TARGET_PROPERTY:mylib,SOURCES>
    COMMAND_EXPAND_LISTS
    WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)

```

The problem is, even though I listed the header files in my sources, they don’t appear in that list.

```auto
target_sources(pixel-engine
PRIVATE
	src/source1.cpp
	src/source2.cpp

PUBLIC FILE_SET HEADERS
    BASE_DIRS src include/mylib
    FILES
        include/mylib/header1.hpp
        include/mylib/header2.hpp
)

```

Only `source1.cpp` and `source2.cpp` gets formatted.

Is there a way with generator expression to get the list of all source file and the list of all headers too? Thanks.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [July 10, 2024, 9:34pm UTC](https://discourse.cmake.org/t/getting-a-list-of-all-source-files-for-the-running-clang-format/11217/2 "2024-07-10T21:34:33Z")

</div>

> [@gracicot](#):
>
> `FILE_SET`

try [HEADER\_SET target property](https://cmake.org/cmake/help/latest/prop_tgt/HEADER_SET.html)
