# Recusively adding a directory and sub-directories to include path

**URL:** <https://ziggit.dev/t/recusively-adding-a-directory-and-sub-directories-to-include-path/17842>\
**Category:** Help\
**Tags:** build-system\
**Created:** [October 4, 2026, 11:10pm UTC](https://ziggit.dev/t/recusively-adding-a-directory-and-sub-directories-to-include-path/17842 "2026-10-04T23:10:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CWood-sdf](https://ziggit.dev/user_avatar/ziggit.dev/cwood-sdf/32/5914_2.png) [@CWood-sdf](https://ziggit.dev/u/CWood-sdf)\
**Post date:** [October 4, 2026, 11:10pm UTC](https://ziggit.dev/t/recusively-adding-a-directory-and-sub-directories-to-include-path/17842/1 "2026-10-04T23:10:29Z")

</div>

I don’t think this is currently possible, but I am trying to compile a C++ project with zig build and would like it to be able to re-build things when I add .cpp files or add new sub-directories with .cpp files. Ideally, this can all happen while under zig build --watch. I know I can manually list source files and sub-directories for include paths, but I would really rather not do that as I’m more used to the makefile-style glob syntax for compiling an entire directory and sub-directories of cpp files.

Is this at all feasible? In my understanding, I can just dir.iterate() in the build.zig script, but since that only runs once during configuration, it doesnt update under `--watch` mode.

---

<div class="post-metadata">

**Author:** ![alanza](https://ziggit.dev/user_avatar/ziggit.dev/alanza/32/6006_2.png) [@alanza](https://ziggit.dev/u/alanza)\
**Post date:** [October 5, 2026, 12:04am UTC](https://ziggit.dev/t/recusively-adding-a-directory-and-sub-directories-to-include-path/17842/2 "2026-10-05T00:04:53Z")

</div>

the word “include path” is i think a red herring here. include paths are for header files included by your source files. to me it sounds like what you is to gather all the cpp source files in a directory as source files. i believe you can do that by writing normal Zig code in your build.zig file. if the logic is sufficiently complicated you should consider writing an external script.

---

<div class="post-metadata">

**Author:** ![vincentd](https://ziggit.dev/user_avatar/ziggit.dev/vincentd/32/9870_2.png) [@vincentd](https://ziggit.dev/u/vincentd)\
**Post date:** [October 5, 2026, 3:59am UTC](https://ziggit.dev/t/recusively-adding-a-directory-and-sub-directories-to-include-path/17842/3 "2026-10-05T03:59:18Z")

</div>

I think zig 0.17.0 will let you do it with [Configure Cache Poisoning](https://ziglang.org/download/0.17.0/release-notes.html#Introduce-the-Concept-of-Configure-Cache-Poisoning), specifically `std.Build.dependOnDirectoryMetadata`. That tells the ‘maker’ to rerun the ‘configurer’ if the directory contents changes. NB: it is **not recursive.**

That said, I recommend listing individual files. Unlike zig, C & C++ don’t have a mechanism for the compiler to determine what code is and isn’t used, so by listing them individually:

1. It makes it easy for other people reading your project to see what it’s doing.
2. Your build won’t fail because of a compile error in code you don’t use.
