0

Good morning!

Do someone have example of usage the "file(GENERATE OUTPUT" cmake closure:

file(GENERATE OUTPUT output_file [CONDITION expression])

Could I use one to generate source code files by template?

I was unable to font out an answer in the official documentation: https://cmake.org/cmake/help/v3.0/command/file.html

and in the Internet

I have source files like

config.template :

config: param1: ${PARAM_1_VALUE}


and I wish to replace ${PARAM_1_VALUE} with some cmake variable value and get the corresponding output file with name config.cfg

Thanks in advance!

  • 1
    "Could I use one to generate source code files by template?" - Unlikely, you probably need to use [configure_file](https://cmake.org/cmake/help/v3.10/command/configure_file.html) instead. As for `file(GENERATE)` command flow, it is used for instantiate [generator expressions](https://cmake.org/cmake/help/v3.10/manual/cmake-generator-expressions.7.html) - things, which may depend on configuration in multi-configuration builders (like Visual Studio). The command has quite specific usage, so providing an example without knowing your needs would have a little sence. – Tsyvarev Feb 07 '19 at 15:37
  • Ok, I've add details – Boris Uskov Feb 07 '19 at 15:48
  • 1
    This work is exactly for `configure_file`. See an example in that answer: https://stackoverflow.com/a/22293945/3440745. – Tsyvarev Feb 07 '19 at 15:54

0 Answers0