In a CMakeLists.txt of a project of mine, I had a configure_file that converted MyHeader.h.in to MyHeader.h while doing transformations of CMake variables - and that worked great.
My problem now is that I ended up generating MyHeader.h.initself by an add_custom_command, so at build time - while configure_file runs at configure time. So, I need to convert the configure_file to something else that can transform CMake variables in the source file at build time.
I found this: Implementing build time configure_file functionality (#25534) · Issue · cmake/cmake :
In the
COMMANDfor theadd_custom_command()call, you can use one of the variouscmake -E copy...commands to do a simple file copy if you don’t need to do any variable substitution as part of the copying
Great - but what do I do, if I do need to do variable substitution as part of the copying? Can I use configure_file directly as an argument of the cmake command? Or maybe should I save the configure_file call to a separate .cmake script file, and then call cmake on this script from add_custom_command?