[CMake] Generated CMakeLists.txt

Michael Hertling mhertling at online.de
Tue Nov 8 15:54:18 EST 2011


On 11/08/2011 03:30 PM, Łukasz Tasz wrote:
> Hi All,
> 
> I have one issue connected with generated code.
> 
> What is recommended way to proceed with generators which provides
> source which is dynamic?
> 
> The setup looks like: generator has some input, and depending on this
> input files are generated.
> From cmake point of view I need only this list of source files to
> create library.
> 
> Generator is providing simple command to generate such a list.
> 
> 
> During cmake phase, I'm calling generator to generate list.cmake with
> list of source file,
> then such a list is included, and configuration is generated. Source
> file are marked as generated, and appropriate
> ADD_CUSTOM_COMMAND(OUTPUT list) is registerd.
> 
> 
> In lifecycle cmake -> make -> edit-input_files -> make -> edit ... make
> 
> everything works smooth with one remark, If you will edit input files
> in a way that new source file will be introduced, then regeneration is
> not enough, I need to regenerate configuration,
> with current approach it looks like:
> edit-input-adding-new-file ->
>      make-step1-generate: will regenerate the code + regenerate
> cmakelist - since new file is there
>      make-step2-compile-sources:
>      make-step3-linking - will fail since new file is not added to
> configuration,
> 
> with next run of make, cmake --check-build-system will recognize
> changes in cmakelist and configuration will be regenerated, and build
> will be successfull (if code changes was smart enough:) )
> 
> The question is if there are some hooks to cmake --check-build-system
> that also additionaly my generate --cmake action will be called? (to
> regenerate cmakelist which holds list of files)
> 
> Or maybe my approach is wrong?
> 
> thanks in advance
> Lukasz

If I understand correctly, you need to establish a dependency of the
CMakeLists.txt file on the input for the code generator. You might
use a CONFIGURE_FILE() command for this purpose, e.g.

CONFIGURE_FILE(input.txt input.txt.bak COPYONLY)

with input.txt being the code generator's input file. In this way, a
change of input.txt outdates the CMakeLists.txt file, and the entire
project is reconfigured and rebuilt the next time Make is called. If
the machinery works by now when you reconfigure the project by hand,
this should do the trick. If not, please come up with a minimal but
complete example to show exactly what you are doing at the moment,
what does not work and what you'd like to see instead.

Regards,

Michael


More information about the CMake mailing list