[CMake] How to read and compile dynamically-generated list of cpp files

Matthew Woehlke mw_triad at users.sourceforge.net
Wed Feb 5 15:19:02 EST 2014


On 2014-02-03 11:44, gimmeamilk gimmeamilk wrote:
> I have a custom tool that processes a given list of IDL files and
> produces a number of .cpp and .h files as output. I want to add those
> files to the list of things to compile in my CMakeLists, and also
> model the dependencies those files have on the IDL. To keep things
> simple, I will state that any change to any of the IDL files should
> trigger a regeneration of all cpp/h.
>
> I have a custom command that takes care of running the generator tool
> and listing all the IDL files as dependencies.
>
> My issue is getting the subsequent list of cpp/h files into cmake at
> build-time. It is not possible to infer from the name of the IDL files
> what cpp files will be generated. My generator tool will, however,
> output the list of generated files to a text file.

My usual approach to problems like these is to figure out a way to 
compute the list of output files *without* actually generating them 
(ideally by the generation tool having a mode to do that), and to then 
arrange (1) for that to happen at configure time, and (2) for 
configuration to depend on the input file(s). (For example, generating 
Python bindings with Shiboken is a similar problem.)

Alternatively, you can create an external project that you configure and 
build as part of your build step. (This might work strangely on e.g. 
MSVC, however.)

-- 
Matthew



More information about the CMake mailing list