# Difficulty with add\_executable() with generated files

**URL:** https://discourse.cmake.org/t/difficulty-with-add-executable-with-generated-files/4921
**Category:** Usage
**Tags:** tool:cmake
**Created:** [January 28, 2022, 6:26am UTC](https://discourse.cmake.org/t/difficulty-with-add-executable-with-generated-files/4921 "2022-01-28T06:26:40Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![erk](https://discourse.cmake.org/user_avatar/discourse.cmake.org/erk/32/114_2.png) [@erk](https://discourse.cmake.org/u/erk)
#### Post date: [January 29, 2022, 6:47pm UTC](https://discourse.cmake.org/t/difficulty-with-add-executable-with-generated-files/4921/6 "2022-01-29T18:47:54Z")

</div>

> [@Nicholas\_Yue](#):
>
> Question  
> (1) Should I spit out the file names of the generated files as full path or relative path ? One line for each file or concatenated in a single line (as a CMake list string?) ?  
> (2) How should I then pass that information to add\_executable ? Any pseudo code example ?
> 
> Cheers

(1) since the generator is yours you can make it generate a list file that can be included using  
[https://cmake.org/cmake/help/latest/command/include.html](https://cmake.org/cmake/help/latest/command/include.html), so the content of the generated file may defined a CMake variable, e.g. GENERATED\_FILES which contains the list of generated file.

You can  
include(generated\_file.cmake OPTIONAL)  
so that inclusion would not break if file is not there, but you’ll have to run cmake twice to get it right.

or you statically know the list of file (as @ben.boeckel said)

or you generate the list of file during _configuration_ using [https://cmake.org/cmake/help/latest/command/execute\_process.html](https://cmake.org/cmake/help/latest/command/execute_process.html) so that the to-be-include file is ensured to exists (provided `execute_process` happens before `include`).  
In that last case you may have to rerun cmake manually when nodes\_definition.json changes, unless  
you add [https://cmake.org/cmake/help/latest/prop\_dir/CMAKE\_CONFIGURE\_DEPENDS.html](https://cmake.org/cmake/help/latest/prop_dir/CMAKE_CONFIGURE_DEPENDS.html) property to nodes\_definition.json file so that cmake will be rerun as soon as nodes\_definition.json changes.

Now @ben.boeckel advised against this solution in the past: [CMAKE\_CONFIGURE\_DEPENDS with newly created file](https://discourse.cmake.org/t/cmake-configure-depends-with-newly-created-file/663) so may be he can explain why.

---

_[View the full topic](https://discourse.cmake.org/t/difficulty-with-add-executable-with-generated-files/4921)._
