[CMake] EXECUTE_PROCESS or ADD_CUSTOM_COMMAND?

Brad King brad.king at kitware.com
Tue Jul 25 16:06:04 EDT 2006


fuchsrich at se-core.net wrote:
> I need to compile a code generator, run the code generator, then compile the
> code that the code generator produces.  Do I need to complie the generator,
> then use the EXECUTE_PROCESS command to run it, then have the generated code
> compiled, or should I use the ADD_CUSTOM_COMMAND somehow?
> 
> The code generator is in a dir like such:
> common/code_generator/*.java
> and the output is put here:
> common/code_generator_output/*.cpp
> 
> The code that is generated is based on an .xsd file, so I don't know what the
> file names will be of the generated code until it is created.

Use ADD_EXECUTABLE to create the generator and then use
ADD_CUSTOM_COMMAND to drive its use.  See here for basic file generation:

http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_generate_a_source_file_during_the_build.3F

You could use FILE(GLOB) to get the list of input java files ahead of
time or better yet just list them manually so that when one is added
CMake will know to re-run and include it.  This list should be used as
the DEPENDS option of the ADD_CUSTOM_COMMAND call.  The OUTPUT option
should have one file that you know to be generated.  This output should
then be listed as a source file in some other target added with
ADD_LIBRARY, ADD_EXECUTABLE, or ADD_CUSTOM_TARGET.

To be fully safe you really need to know the set of output files
produced by a custom command and list them on the OUTPUT option and as
source files in the final target using the outputs.  Listing one will
work if no one deletes the other outputs by hand and then expects the
build to work.

-Brad


More information about the CMake mailing list