# Is it possible to append to a file using generator expressions?

**URL:** https://discourse.cmake.org/t/is-it-possible-to-append-to-a-file-using-generator-expressions/11326
**Category:** Usage
**Created:** [July 25, 2024, 9:16pm UTC](https://discourse.cmake.org/t/is-it-possible-to-append-to-a-file-using-generator-expressions/11326 "2024-07-25T21:16:48Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![KStocky](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kstocky/32/4707_2.png) [@KStocky](https://discourse.cmake.org/u/KStocky)
#### Post date: [July 25, 2024, 9:16pm UTC](https://discourse.cmake.org/t/is-it-possible-to-append-to-a-file-using-generator-expressions/11326/1 "2024-07-25T21:16:48Z")

</div>

Hi all!

I have been searching for a way to append to a file using generator expressions and haven’t been able to find any information on this. At this point, I am wondering if it is even possible. My use case is that I want every target to be able to write its output directory to a single file, I can then use that information to clean stale content files in each target’s directory.

I could instead use a directory and a file per target and iterate through the files in the directory as a workaround, but I thought I might ask here to see if I am missing anything obvious here.

Cheers,  
Keith

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [July 18, 2025, 8:49pm UTC](https://discourse.cmake.org/t/is-it-possible-to-append-to-a-file-using-generator-expressions/11326/2 "2025-07-18T20:49:06Z")

</div>

I would `file(APPEND)` generator expressions to a single file (cleared at the start of configure) and then `file(GENERATE INPUT)` that to the desired destination. You could also append to a variable or property and then use `file(GENERATE CONTENT)` instead.
