# Adding dependency to generated files to a single source file?

**URL:** <https://discourse.cmake.org/t/adding-dependency-to-generated-files-to-a-single-source-file/6372>\
**Category:** Code\
**Created:** [August 29, 2022, 8:50am UTC](https://discourse.cmake.org/t/adding-dependency-to-generated-files-to-a-single-source-file/6372 "2022-08-29T08:50:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Naville](https://discourse.cmake.org/user_avatar/discourse.cmake.org/naville/32/2724_2.png) [@Naville](https://discourse.cmake.org/u/Naville)\
**Post date:** [August 29, 2022, 8:50am UTC](https://discourse.cmake.org/t/adding-dependency-to-generated-files-to-a-single-source-file/6372/1 "2022-08-29T08:50:48Z")

</div>

Hi:  
In my use case, I have commands at configure time that generates `.cpp.inc` files from input files, something like :

```auto
configure_file(
        "${CMAKE_CURRENT_LIST_DIR}/Input.cpp.in"
        "${CMAKE_CURRENT_BINARY_DIR}/Input.cpp.inc")
# Copy to where Input.cpp lives
file(COPY ....)

```

And then in my `Input.cpp` file, I `#include "Input.cpp.inc"`

This raises a few questions:

- `Input.cpp.inc` is not automatically regenerated when `Input.cpp.in` changes
- `Input.cpp` is not recompiled when `Input.cpp.in` changes

---

<div class="post-metadata">

**Author:** ![Naville](https://discourse.cmake.org/user_avatar/discourse.cmake.org/naville/32/2724_2.png) [@Naville](https://discourse.cmake.org/u/Naville)\
**Post date:** [August 29, 2022, 8:52am UTC](https://discourse.cmake.org/t/adding-dependency-to-generated-files-to-a-single-source-file/6372/2 "2022-08-29T08:52:58Z")

</div>

P.S.:

- `libInput` which contains `Input.cpp` might not be created yet when this CMakeLists is being run. (Uncontrollable by me)
- `libInput` is not created in the same level as current CMakeLists.txt

---

<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:** [August 29, 2022, 11:01am UTC](https://discourse.cmake.org/t/adding-dependency-to-generated-files-to-a-single-source-file/6372/3 "2022-08-29T11:01:09Z")

</div>

> [@Naville](#):
>
> ```auto
> configure_file(
> "${CMAKE_CURRENT_LIST_DIR}/Input.cpp.in"
> "${CMAKE_CURRENT_BINARY_DIR}/Input.cpp.inc")
> # Copy to where Input.cpp lives
> file(COPY ....)
> 
> ```

Why not just configure directly into wherever `file(COPY)` puts the file? That might solve the issue.

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [August 29, 2022, 12:52pm UTC](https://discourse.cmake.org/t/adding-dependency-to-generated-files-to-a-single-source-file/6372/4 "2022-08-29T12:52:11Z")

</div>

This looks like that this will change the source directory. You should generally try to avoid that. Maybe adapt the include path instead…
