[CMake] Generating Source Files

Jeremy Cowgar jeremy at cowgar.com
Sat Apr 4 23:48:37 EDT 2009


Bill Hoffman wrote:
> Jeremy Cowgar wrote:
>> I am confused on how that would help me. The ADD_CUSTOM_COMMAND 
>> generates many source files, and it has dependencies, so it does not 
>> have to generate source files many times, but sometimes it does. When 
>> it does, I need the FILE( GLOB .. ) to execute after that custom 
>> command is run so that the rest of my script can continue.
>>
>
> Is there no way to compute or know the names of all the files that 
> will be generated at CMake time?

No. Not very easily. Here's the thing. Let's say the project has 
parser.e. It's going to take that and translate it to C code, now bear 
in mind that parser.e in real life is ~1400 lines and is just one part 
of my project. Anyway, it's the main file. parser.e will be translated 
to C and then compiled to be parser.exe. Let's say this is parser.e 
right now:

puts(1, "Starting my new project\n")

That will create parser.c for sure, that's easy. However, now on to my 
next step, I edit code and add things to parser.e:

include std/text.e

puts(1, trim("Starting my new project\n"))

Well, now when parser.e is translated this time around (the 
ADD_CUSTOM_COMMAND knows to watch parser.e as a dependency), it will 
generate both parser.c and text.c. Both are needed to compile and make 
parser.exe. Now, someone else does a bit more work on the parser and 
includes regular expressions:

include std/text.e
include std/regex.e

puts(1, "Hello")

Well, std/regex.e includes three files itself. So now, when generated, 
there is parser.c, text.c, regex.c, machine.c, cfunc.c, os.c

So, it's nearly impossible. Right now how we handle it is in the 
Makefile we do this:

EU_INTERPRETER_OBJECTS = $(patsubst %.c,%.o,$(wildcard 
$(BUILDDIR)/intobj/*.c))

But, that executes each time that we run make, therefore it works great. 
I am looking for that ability in CMake but am having a hard time. We 
currently have 3 make files going, one for Unix systems (gcc, make), 
another for OpenWatcom and another for MSVC. What is happening (and is 
hard not to happen) is a change is made, say a new file is added, and 
the dev who did it works in Windows and updated the Watcom makefile and 
forgets about the MSVC and Unix makefile because they have neither. Or 
maybe they do remember, but can't test, they make the change and it was 
a typo, etc...

Jeremy



More information about the CMake mailing list