# CMake Configuration uses a file which will only be generated during Build time

**URL:** <https://discourse.cmake.org/t/cmake-configuration-uses-a-file-which-will-only-be-generated-during-build-time/1965>\
**Category:** Code\
**Created:** [October 5, 2020, 3:19pm UTC](https://discourse.cmake.org/t/cmake-configuration-uses-a-file-which-will-only-be-generated-during-build-time/1965 "2020-10-05T15:19:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![swoo.quek](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@swoo.quek](https://discourse.cmake.org/u/swoo.quek)\
**Post date:** [October 5, 2020, 3:19pm UTC](https://discourse.cmake.org/t/cmake-configuration-uses-a-file-which-will-only-be-generated-during-build-time/1965/1 "2020-10-05T15:19:55Z")

</div>

I have a custom command which uses a file generated (during Build time) by another custom command:

add\_custom\_command(  
#Command\_A  
… #generate _myfile.txt_

…  
)

add\_custom\_command(  
#Command\_B  
… #uses _myfile.txt_  
…  
)

Is this workable, or even possible with CMake?

How can you **Configure** Command\_B, which uses a file which will only exist during **Build** time?

I can change Command\_A to be execute\_process(…#generate _myfile.txt_…) which will generate the file during CMake, but how do I use it in Command\_B?

---

<div class="post-metadata">

**Author:** ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)\
**Post date:** [October 5, 2020, 6:13pm UTC](https://discourse.cmake.org/t/cmake-configuration-uses-a-file-which-will-only-be-generated-during-build-time/1965/2 "2020-10-05T18:13:00Z")

</div>

As long as you use the `add_custom_command(OUTPUT ...)` and not the `add_custom_command(TARGET ...)`, what you want to do is possible.

What have you tried so far? Did you read the documentation of the `BYPRODUCTS` and `DEPENDS` keyword of `add_custom_command`?

---

<div class="post-metadata">

**Author:** ![swoo.quek](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@swoo.quek](https://discourse.cmake.org/u/swoo.quek)\
**Post date:** [October 7, 2020, 12:00pm UTC](https://discourse.cmake.org/t/cmake-configuration-uses-a-file-which-will-only-be-generated-during-build-time/1965/3 "2020-10-07T12:00:19Z")

</div>

Dear Alain,

> What have you tried so far? Did you read the documentation of the `BYPRODUCTS` and `DEPENDS` keyword of `add_custom_command` ?

The concept is just too complicated to even start trying

I mean, I have used `add_custom_command(OUTPUT ... ... DEPENDS)` in other context, but I do not know how to apply this to the dilemma of “using something (which has not been generated) in CMake Configuration”

Would you mind explaining the concept?

---

<div class="post-metadata">

**Author:** ![swoo.quek](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@swoo.quek](https://discourse.cmake.org/u/swoo.quek)\
**Post date:** [October 7, 2020, 2:04pm UTC](https://discourse.cmake.org/t/cmake-configuration-uses-a-file-which-will-only-be-generated-during-build-time/1965/4 "2020-10-07T14:04:08Z")

</div>

Dear Alain,

The following I describe what the situation is like:

#1. When I run “make all”, the file `timer_cx.d` will be generated:

> //timer\_cx.d  
> C:/Proj/\_builds/CMakeFiles/foo.dir/timer/timer\_cx.c.obj C:/Proj/\_builds/CMakeFiles/foo.dir/timer\_cx.d: C:/Proj/timer/timer\_cx.c
> 
> C:/Proj/\_builds/CMakeFiles/foo.dir/timer/timer\_cx.c.obj _ **C:/Proj/\_builds/CMakeFiles/foo.dir/timer\_cx.d: C:/Proj/timer/timer\_cx\_if.h** _
> 
> C:/Proj/timer/timer\_cx\_if.h:  
> …

#2. Some part of `timer_cx.d` would be extracted (in _ **italic bold** _), and put it here:

> add\_custom\_command(  
> OUTPUT … #timer\_cx.c.obj  
> COMMAND …#command to generate timer\_cx.c.obj  
> DEPENDS _ **C:/Proj/\_builds/CMakeFiles/foo.dir/timer\_cx.d: C:/Proj/timer/timer\_cx\_if.h** _  
> VERBATIM  
> )

> add\_custom\_target(  
> target2  
> DEPENDS timer\_cx.c.obj  
> VERBATIM  
> )

I think the above is not possible, because during CMake Configuration (#2), the file` timer_cx.d` has not been generated yet, thus the content of `timer_cx.d` cannot be known

Even if `timer_cx.d` can be generated during CMake generation ( **before** “make all”), is it still possible?
