Using the generator expression $<INSTALL_PREFIX> in install(CODE ) should work with CMake 3.27 and later. But the generator expression doesn’t work with the enviroment variable DESTDIR. I don’t know if this is the intended behavior.
Thank you, yes, that works. I think I understand the underlying difference in the CMake install script between file() and install but isn’t it still error-prone that you have to write \$ENV\\{DESTDIR\}$<INSTALL_PREFIX> for INSTALL(CODE …) but not for INSTALL(FILES …)?
If escaping is a worry, you can use install(SCRIPT) instead. CMake generates the appropriate code to use DESTDIR itself for install(FILES). CMake isn’t going to parse your CODE or SCRIPT to second guess your intent if you miss it yourself; the install prefix is something different from DESTDIR and knowing what the intent of any given $<INSTALL_PREFIX> usage is intended to be is beyond CMake’s scope.