[CMake] cmp0026, file(GENERATE...), and configure_file

Alan W. Irwin irwin at beluga.phys.uvic.ca
Mon Apr 27 19:13:14 EDT 2015


On 2015-04-23 04:19-0700 Alan W. Irwin wrote:

> On 2015-04-23 06:47-0400 David Cole wrote:
>> In the meantime, while it is certainly clumsy to do the two separate
>> commands everywhere, you could write a CMake language
>> function(configure_file_generate ...) that takes the same args as
>> configure_file, but does the two step in its implementation.
>
> That is a good idea that should be straightforward for me to implement
> as part of the PLplot build system.

And here is that function (no guarantees except "it works for me") in
case someone who reads this thread later would like to try this
interim solution before the preferred GENERATE signature of
configure_file is implemented for CMake.

function(configure_file_generate)
   # Configure files that contain both normal items
   # to configure (referenced as ${VAR} or @VAR@) as well as
   # generator expressions (referenced as $<...>).
   # The arguments of this function have exactly the
   # same syntax and meaning as configure_file.

   set(intermediate_file_suffix "_cf_only")
   list(GET ARGV 0 input_file)
   list(GET ARGV 1 output_file)
   set(intermediate_file ${output_file}${intermediate_file_suffix})

   # Locally modify ARGV so that output file for configure file is
   # redirected to intermediate_file.
   list(REMOVE_AT ARGV 1)
   list(INSERT ARGV 1 ${intermediate_file})

   # Configure all but generator expressions.
   configure_file(${ARGV})

   # Configure generator expressions.
   # N.B. these ${output_file} results will only be available
   # at generate time.
   file(GENERATE
     OUTPUT ${output_file}
     INPUT ${intermediate_file}
     )
endfunction(configure_file_generate)

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list