[CMake] Generating Source Files

James Bigler jamesbigler at gmail.com
Wed Apr 8 11:44:55 EDT 2009


On Wed, Apr 8, 2009 at 9:05 AM, Jeremy Cowgar <jeremy at cowgar.com> wrote:
> Jeremy Cowgar wrote:
>>
>> 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?
>
> Ok, our parser now writes a <prgname>.mak file that contains two lines,
> SOURCES=abc.c def.c xyz. and OBJECTS=abc.obj def.obj xyz.obj
>
> However, it does so after translation. Is there a way to read this file in
> *after* the custom command runs? Maybe I can get the list of source files
> that way?
>
> Jeremy

I have some similar machinery that I borrowed from the swig stuff.
You want to test to see if the source file exists.  If it doesn't you
want to run configure_file(progname.mak ... IMMEDIATE) to create a
blank file, then include(progname.mak) it.  Then make your target
dependent on that file.  During your target generation you generate
your source list file, but only change the file if the contents
change.

add_custom_command(OUTPUTS ${EXTRA_SOURCE_FILES} progname.mak
  # Generate the EXTRA_SOURCE_FILES
  COMMAND ${MY_COMMAND}
  # Generate the progname.mak
  COMMAND ${MY_COMMAND} -M progname.mak.test
  COMMAND ${CMAKE_COMMAND} -E copy_if_different progname.mak.test progname.mak
  # I'm not sure you need this as it may cause you to recompile more than usual
  DEPENDS progname.mak
  MAIN_DEPENDENCY parser.e
  )

By including progname.mak during configure, you tell CMake to
reconfigure whenever that file changes.  If a user changes parser.e,
you will generate all your sources, plus the source list.  Running
cmake again will cause you to reconfigure.

I'm not sure this helps.

James


More information about the CMake mailing list