[cmake-developers] Generating files at generate-time

Stephen Kelly steveire at gmail.com
Tue Apr 23 15:07:28 EDT 2013


Hi,

as 2.8.11 will be out soon, I'm returning to some pending features I'd like 
to get in early in the next release.

I've pushed the genex-evaluate-file branch to my clone. It implements the 
file(EVALUATE) subcommand, which evaluates an input file containing 
generator expressions and writes the result to an output file:

 file(EVALUATE "${CMAKE_CURRENT_SOURCE_DIR}/input.txt"
               "${CMAKE_CURRENT_BINARY_DIR}/output.txt"
 )

or

 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/input.txt"
   "Some $<1:Content>"
 )
 file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/input.txt"
   "And $<1:More>"
 )
 file(EVALUATE "${CMAKE_CURRENT_BINARY_DIR}/input.txt"
               "${CMAKE_CURRENT_BINARY_DIR}/output.txt"
 )

This replaces the proposal for file(GENERATE) and file(GENERATE_APPEND) I 
made before: 

 http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/5835/focus=5841

Multi-config generators get in the way a little bit. It's a bit more complex 
to generate the file with 'the current config' because the behaviour would 
be so different between the different generators. In my branch I'm forcing 
the requirement of being explicit about the config.

The above signature evaluates the generator expression unconditionally with 
a null config. To generate the file only when generating for the Debug or 
Release configs:

 file(EVALUATE "${CMAKE_CURRENT_BINARY_DIR}/input.txt"
               "${CMAKE_CURRENT_BINARY_DIR}/output_$<CONFIGURATION>.txt"
     CONFIGURATIONS Debug Release
 )

Perhaps another signature like 

 file(EVALUATE "${CMAKE_CURRENT_BINARY_DIR}/input.txt"
               "${CMAKE_CURRENT_BINARY_DIR}/output_$<CONFIGURATION>.txt"
     ALL_CONFIGURATIONS
 )

is appropriate, which would generate the output file for the 
CMAKE_BUILD_TYPE or each of the CMAKE_CONFIGURATION_TYPES?

I guess the add_custom_command COMMAND has a similar issue. How is that 
solved?

Thanks,

Steve.





More information about the cmake-developers mailing list