[CMake] Compiling a file during CMake creation

Alexander Neundorf a.neundorf-work at gmx.net
Mon Jun 9 17:40:51 EDT 2008


On Monday 09 June 2008, Steven Van Ingelgem wrote:
> I am building an executable which I need to pre-process some files (much
> like QT does).

You mean like moc, which is then used to generate source which will be built ?

You don't have to do that at cmake time, you can do this at build time.
With moc it would look like:

add_executable(moc ${mocSources})
get_target_property(MOC_EXECUTABLE moc LOCATION)

...


add_custom_command(OUTPUT file.moc 
                   COMMAND ${MOC_EXECUTABLE} ... args...
                   DEPENDS moc)

The last "DEPENDS" tells cmake that the target "moc" has to be built before 
the custom command is executed.

Alex


More information about the CMake mailing list