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

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

#generate myfile.txt


#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?

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?

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?

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:

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


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

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

DEPENDS timer_cx.c.obj

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?