[cmake-developers] Generating files at generate-time

Brad King brad.king at kitware.com
Wed Apr 24 15:53:03 EDT 2013

On 04/23/2013 03:07 PM, Stephen Kelly wrote:
>                "${CMAKE_CURRENT_BINARY_DIR}/output.txt"
>  )
>                "${CMAKE_CURRENT_BINARY_DIR}/output_$<CONFIGURATION>.txt"
>      CONFIGURATIONS Debug Release
>  )
>                "${CMAKE_CURRENT_BINARY_DIR}/output_$<CONFIGURATION>.txt"
>  )

Currently the file() command holds a bunch of utilities that execute
synchronously.  I do not think it should be used in a declarative
form that delays evaluation until generate time.  I can't think of
a better command to hold this though.  Perhaps having "GENERATE" in
the command mode will be sufficient as in your original proposal.

In order to select which configurations get the generation we could
just have an argument to specify a condition for generation.  That
condition could then be populated with a generator expression to
test $<CONFIG:...> or something.

I also liked your original proposal's keyword-based signature.

 file(GENERATE # create during generation
      OUTPUT <output-genex>  # genex computing output path
      [INPUT <input-genex>]  # genex computing input path
      [CONTENT <genex>]      # genex content
      CONDITION <bool-genex> # genex for whether to generate

where INPUT and CONTENT are mutually exclusive.

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

We don't have official support for per-config OUTPUT from
add_custom_command, though IIRC there is a feature request in the
issue tracker to support $<CONFIGURATION> there.


More information about the cmake-developers mailing list