[CMake] Generating files during building

Alan W. Irwin irwin at beluga.phys.uvic.ca
Thu May 31 15:16:33 EDT 2007


Hi Gustavo:

I am going to answer you on list because the cmake gurus there may have some
additional comments on the problem of generated source files.

Alan

On 2007-05-31 18:39+0100 Gustavo wrote:

> Hello.
>
> On Thursday 31 May 2007 15:55, you wrote:
>> On 2007-05-31 14:37+0100 Gustavo wrote:
>>>>> Finding .o files is a real PITA.  So, you're going to want to generate
>>>>> your .c files, figure out which .c files you actually have, then do
>>>>> CMake as usual.
>>>>
>>>> Yes, do the split at cmake-time time or earlier, then you know early
>>>> enough which c files you will have.
>>>
>>> The source file is generated after the first phase of the building
>>> process:
>>
>> Is this really necessary?  For example, could you run EXECUTE_PROCESS
>> (which runs at cmake time) to execute your splitter to generate all the
>> source files?
>
> This source file has dependencies.
> I need to process a tree of datafiles that are used to generate the source
> file. So I suppose that I should instead use an ADD_CUSTOM_COMMAND.

Yes, that is the standard way for generating source files with dependencies
at build time.  I have only used that method for headers, but from many
prior discussions here it also works for generated C source files that need
to be explicitly compiled at build time.  If I recall correctly from the
discussions, you need to set the GENERATED property to ON using
SET_SOURCE_FILES_PROPERTIES (see documentation of
SET_SOURCE_FILES_PROPERTIES for further discussion).

I am not sure the following is necessary if the source files are built in
the same directory where they are needed, but for the case where source
files are built in a different directory (the case for my generated header),
you must have your executable or library target depend on an empty custom
target which in turn depends on your custom command to insure the source
files get built before they need to be compiled.

In any case, I do not think multiple invocations of cmake will be necessary
in order to use generated source files.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list