[CMake] Running custom executable

Alexander Neundorf a.neundorf-work at gmx.net
Tue Apr 7 16:37:27 EDT 2015


On Tuesday, April 07, 2015 13:22:30 you wrote:
> > > > I have a custom executable that does some codegen to produce an
> > > > 
> >> > > enumeration and a couple of tables.  I need this to be run against
> >> 
> >> each
> >> 
> >> > > source file before actual compilation.  It needs include directories
> >> 
> >> and
> >> 
> >> > > macro definitions from the build system.
> >> > > 
> >> > > Is there a way to do this with a CMake build system?
> >> 
> >> add_custom_command
> >> 
> >> > > seems like it might work, but I need all runs of the custom
> >> 
> >> executable to
> >> 
> >> > > run before compilation begins.
> >> > 
> >> > execute_process() might be what you want:
> >> > http://www.cmake.org/cmake/help/v3.2/command/execute_process.html
> >> 
> >> Hmmm, probably add_custom_command() or add_custom_target() is what he
> >> wants.
> >> Why does it have to run before the compilation begins ?
> 
> The program will run once per source file, scan them, and generate a header
> file that is necessary for compilation to succeed.

You could create a add_custom_target(foo); make your actual target depend on 
it, so it is finished before the actual compilation starts using 
add_dependencies().

Alex



More information about the CMake mailing list