[CMake] configure_file as a build step?

Eric Noulard eric.noulard at gmail.com
Wed May 9 16:30:36 EDT 2012


2012/5/9 Jensen, Erik A <Erik.Jensen at pnnl.gov>:
> That worked, although a little roundabout. Thank you.
>
> Would there be any interest in having an easier way to do this? It seems like it could be usefully in a fair number of situations.
>
> Maybe an additional -E command:
> cmake -E configure_file -D var1=value1 -D var2=value2 --at-only infile outfile

Not that much simpler than the following example.

> Or even a way to run arbitrary CMake commands without a script file:
> cmake -D var1=value1 -D var2=value2 -R "configure_file(infile outfile @ONLY)"
>
> This would make it possible to avoid having a whole other file just to execute one CMake command at build time.
>
> Thoughts?

Is it really simpler than writing your own simple (or complicated)
script once and launching:

cmake -DINFILE=blah.in  -DOUTFILE=blah.out -Dvar1=value1 -Dvar2=value2
-DCOPYONLY=1 -P GenericConfigureFile.cmake

this command may be launched in add_custom_command and you can spare the first
configure_file if you pass all the value you need with -D on the command line.

One option that could be nice would be a way to inherit CMake-time
defined values
at Build-time in order to spare much of "-Dvar1=value1" argument.

Something like a new CMake command that would dump in a file the definition
of the currently defined vars

variables_save(FILE ${CMAKE_CURRENT_BINARY_DIR}/myvarset.cmake)
then you would be able to do
variables_load(FILE /path/to/myvarset.cmake)
and get the previously saved vars defintions.

May be variables_save could take a list of vars as argument:
variables_save(VARS MyVar1 MyVar2 FILE ${CMAKE_CURRENT_BINARY_DIR}/myset.cmake)

I think this should even be doable as CMake macro.
variables_load may simply be
include(/path/to/myvarset.cmake)

-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GenericConfigureFile.cmake
Type: application/octet-stream
Size: 260 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120509/608238f1/attachment.obj>


More information about the CMake mailing list