Delay in operation of file(GENERATE ...

You could try using the new file(CONFIGURE) command (in 3.18+). It creates the file at configure time, instead of generation time, which is similar to configure_file() and file(WRITE).